ls-pro-common 3.0.79 → 3.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.js +1 -1
- package/dist/common.min.js +1 -1
- package/es/hooks/useBaseDict.d.ts +35 -0
- package/es/hooks/useBaseDict.js +104 -0
- package/es/hooks/useDtl/index.js +7 -5
- package/es/hooks/useFilterBack.d.ts +9 -10
- package/es/hooks/useFilterBack.js +6 -6
- package/es/hooks/useSelectOptions.d.ts +81 -0
- package/es/hooks/useSelectOptions.js +210 -0
- package/es/hooks/useShowConfirm.d.ts +9 -0
- package/es/hooks/useShowConfirm.js +23 -0
- package/es/hooks/useSingle/index.js +5 -3
- package/es/http/index.js +1 -1
- package/es/index.d.ts +6 -2
- package/es/index.js +6 -2
- package/es/utils/exportProcess.d.ts +8 -0
- package/es/utils/exportProcess.js +99 -0
- package/es/utils/index.d.ts +2 -0
- package/es/utils/index.js +18 -0
- package/lib/hooks/useBaseDict.d.ts +35 -0
- package/lib/hooks/useBaseDict.js +104 -0
- package/lib/hooks/useDtl/index.js +7 -5
- package/lib/hooks/useFilterBack.d.ts +9 -10
- package/lib/hooks/useFilterBack.js +6 -6
- package/lib/hooks/useSelectOptions.d.ts +81 -0
- package/lib/hooks/useSelectOptions.js +210 -0
- package/lib/hooks/useShowConfirm.d.ts +9 -0
- package/lib/hooks/useShowConfirm.js +23 -0
- package/lib/hooks/useSingle/index.js +5 -3
- package/lib/http/index.js +1 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +6 -2
- package/lib/utils/exportProcess.d.ts +8 -0
- package/lib/utils/exportProcess.js +99 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import "antd/es/message/style";
|
|
2
|
+
import _message from "antd/es/message";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
5
|
+
import { showSuccess, showError, sleep, downloadFile } from '.';
|
|
6
|
+
import { httpGet } from '../http';
|
|
7
|
+
/**
|
|
8
|
+
* 导出进度查看
|
|
9
|
+
*
|
|
10
|
+
* @param apiResult 导出接口返回数据,
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
var exportProcess = function exportProcess(apiResult) {
|
|
14
|
+
if (!apiResult.taskId) {
|
|
15
|
+
var _apiResult$flag;
|
|
16
|
+
showSuccess((apiResult === null || apiResult === void 0 ? void 0 : (_apiResult$flag = apiResult.flag) === null || _apiResult$flag === void 0 ? void 0 : _apiResult$flag.retMsg) || '导出成功');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var time = 0;
|
|
20
|
+
var exit = false;
|
|
21
|
+
var win = top || window;
|
|
22
|
+
var loading = _message.loading({
|
|
23
|
+
content: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", null, "\u6B63\u5728\u5BFC\u51FA\u4E2D,\u8BF7\u7A0D\u5019..."), /*#__PURE__*/React.createElement("a", {
|
|
24
|
+
onClick: function onClick() {
|
|
25
|
+
loading();
|
|
26
|
+
}
|
|
27
|
+
}, /*#__PURE__*/React.createElement(CloseOutlined, {
|
|
28
|
+
style: {
|
|
29
|
+
marginLeft: 20,
|
|
30
|
+
color: 'gray',
|
|
31
|
+
width: 13
|
|
32
|
+
}
|
|
33
|
+
}))),
|
|
34
|
+
duration: 0,
|
|
35
|
+
style: {
|
|
36
|
+
textAlign: 'right'
|
|
37
|
+
},
|
|
38
|
+
onClose: function onClose() {
|
|
39
|
+
exit = true;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var getResult = function getResult() {
|
|
43
|
+
if (exit) return;
|
|
44
|
+
httpGet('/petrel-poi-center-api/sysPoiExportManage/page', {
|
|
45
|
+
'page.pn': 1,
|
|
46
|
+
'page.size': 1,
|
|
47
|
+
'search.id': apiResult.taskId
|
|
48
|
+
}).then(function (result) {
|
|
49
|
+
var _result$rows = result.rows,
|
|
50
|
+
rows = _result$rows === void 0 ? [] : _result$rows;
|
|
51
|
+
var row = rows === null || rows === void 0 ? void 0 : rows[0];
|
|
52
|
+
if (!row) {
|
|
53
|
+
if (time < 3) {
|
|
54
|
+
time++;
|
|
55
|
+
sleep(5).then(function () {
|
|
56
|
+
return getResult();
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
showError('获取导出进度失败,请在消息中心查看导出结果');
|
|
60
|
+
win.postMessage({
|
|
61
|
+
type: 'exportError'
|
|
62
|
+
});
|
|
63
|
+
loading();
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
var status = row.status,
|
|
67
|
+
downloadUrl = row.downloadUrl;
|
|
68
|
+
//导出中
|
|
69
|
+
if (status < 30) {
|
|
70
|
+
sleep(5).then(function () {
|
|
71
|
+
return getResult();
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
//导出成功
|
|
75
|
+
if (status === 30 && downloadUrl) {
|
|
76
|
+
downloadFile(downloadUrl);
|
|
77
|
+
} else {
|
|
78
|
+
//导出失败
|
|
79
|
+
showError('导出异常,请在消息中心查看失败原因');
|
|
80
|
+
win.postMessage({
|
|
81
|
+
type: 'exportError'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
loading();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}).catch(function () {
|
|
88
|
+
showError('获取导出进度失败,请在消息中心查看导出结果');
|
|
89
|
+
loading();
|
|
90
|
+
win.postMessage({
|
|
91
|
+
type: 'exportError'
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
sleep(1).then(function () {
|
|
96
|
+
return getResult();
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
export default exportProcess;
|
package/es/utils/index.d.ts
CHANGED
|
@@ -314,3 +314,5 @@ export declare const openPageInMain: (option: {
|
|
|
314
314
|
export declare const showLoading: (text?: string) => void;
|
|
315
315
|
export declare const exitLoading: () => void;
|
|
316
316
|
export declare const handleTheme: () => void;
|
|
317
|
+
export declare const sleep: (secord: number) => Promise<unknown>;
|
|
318
|
+
export declare const downloadFile: (url: string, fileName?: string | undefined) => void;
|
package/es/utils/index.js
CHANGED
|
@@ -889,4 +889,22 @@ export var handleTheme = function handleTheme() {
|
|
|
889
889
|
if (theme) {
|
|
890
890
|
document.body.classList.add('theme-' + theme);
|
|
891
891
|
}
|
|
892
|
+
};
|
|
893
|
+
export var sleep = function sleep(secord) {
|
|
894
|
+
return new Promise(function (resolve) {
|
|
895
|
+
setTimeout(function () {
|
|
896
|
+
resolve(true);
|
|
897
|
+
}, secord * 1000);
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
export var downloadFile = function downloadFile(url, fileName) {
|
|
901
|
+
var a = document.createElement('a');
|
|
902
|
+
a.href = url;
|
|
903
|
+
// a.target = '_blank'; // 新开屏有闪烁
|
|
904
|
+
if (fileName) {
|
|
905
|
+
a.setAttribute('download', fileName);
|
|
906
|
+
}
|
|
907
|
+
document.body.appendChild(a);
|
|
908
|
+
a.click();
|
|
909
|
+
document.body.removeChild(a);
|
|
892
910
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @name 请求字典 */
|
|
2
|
+
interface useSelectOptionsType {
|
|
3
|
+
/** @name 字典item的value */
|
|
4
|
+
dictValue?: string;
|
|
5
|
+
/** @name 字典item的label */
|
|
6
|
+
dictLabel?: string;
|
|
7
|
+
/**
|
|
8
|
+
* @default GET
|
|
9
|
+
* @name 请求方式
|
|
10
|
+
*/
|
|
11
|
+
method?: 'GET' | 'POST';
|
|
12
|
+
/** @name 请求的url */
|
|
13
|
+
url?: string;
|
|
14
|
+
/**
|
|
15
|
+
* @default true
|
|
16
|
+
* @name 是否需要网关
|
|
17
|
+
*/
|
|
18
|
+
needGateWay?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @default true
|
|
21
|
+
* @name 是否是JSON post中会使用
|
|
22
|
+
*/
|
|
23
|
+
isJson?: boolean;
|
|
24
|
+
/** @name 请求参数 */
|
|
25
|
+
params?: any;
|
|
26
|
+
/** @name 1label返回中文带箭头 2label返回中文不带箭头 */
|
|
27
|
+
type?: '1' | '2';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param props
|
|
31
|
+
* @name 动态请求select的options
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare const useBaseDict: (props: useSelectOptionsType) => [any[], (options: any[]) => void];
|
|
35
|
+
export default useBaseDict;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
/** @name 请求字典 */
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
import { httpGet, httpPost } from '../http';
|
|
8
|
+
import { showWarn } from '../utils';
|
|
9
|
+
/**
|
|
10
|
+
* @param props
|
|
11
|
+
* @name 动态请求select的options
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export var useBaseDict = function useBaseDict(props) {
|
|
15
|
+
var _props$url = props.url,
|
|
16
|
+
url = _props$url === void 0 ? '/lesoon-integration/sysDictDtl?lesoon-tenant=1' : _props$url,
|
|
17
|
+
_props$method = props.method,
|
|
18
|
+
method = _props$method === void 0 ? 'GET' : _props$method,
|
|
19
|
+
_props$dictValue = props.dictValue,
|
|
20
|
+
dictValue = _props$dictValue === void 0 ? 'dictValue' : _props$dictValue,
|
|
21
|
+
_props$dictLabel = props.dictLabel,
|
|
22
|
+
dictLabel = _props$dictLabel === void 0 ? 'displayName' : _props$dictLabel,
|
|
23
|
+
_props$needGateWay = props.needGateWay,
|
|
24
|
+
needGateWay = _props$needGateWay === void 0 ? true : _props$needGateWay,
|
|
25
|
+
_props$isJson = props.isJson,
|
|
26
|
+
isJson = _props$isJson === void 0 ? true : _props$isJson,
|
|
27
|
+
_props$params = props.params,
|
|
28
|
+
params = _props$params === void 0 ? {} : _props$params,
|
|
29
|
+
_props$type = props.type,
|
|
30
|
+
type = _props$type === void 0 ? '1' : _props$type;
|
|
31
|
+
var _useState = useState([]),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
options = _useState2[0],
|
|
34
|
+
setOptions = _useState2[1];
|
|
35
|
+
/** @name 下拉框请求数据 */
|
|
36
|
+
var requestOptions = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
38
|
+
var _res;
|
|
39
|
+
var val,
|
|
40
|
+
res,
|
|
41
|
+
baseParams,
|
|
42
|
+
data,
|
|
43
|
+
_args = arguments;
|
|
44
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
45
|
+
while (1) switch (_context.prev = _context.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
val = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
|
|
48
|
+
if (url) {
|
|
49
|
+
_context.next = 4;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
showWarn('请配置url');
|
|
53
|
+
return _context.abrupt("return");
|
|
54
|
+
case 4:
|
|
55
|
+
baseParams = _objectSpread({
|
|
56
|
+
page: 1,
|
|
57
|
+
pageSize: 999
|
|
58
|
+
}, params);
|
|
59
|
+
if (!(method === 'GET')) {
|
|
60
|
+
_context.next = 11;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
_context.next = 8;
|
|
64
|
+
return httpGet(url, baseParams, needGateWay);
|
|
65
|
+
case 8:
|
|
66
|
+
res = _context.sent;
|
|
67
|
+
_context.next = 15;
|
|
68
|
+
break;
|
|
69
|
+
case 11:
|
|
70
|
+
if (!(method === 'POST')) {
|
|
71
|
+
_context.next = 15;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
_context.next = 14;
|
|
75
|
+
return httpPost(url, baseParams, isJson, needGateWay);
|
|
76
|
+
case 14:
|
|
77
|
+
res = _context.sent;
|
|
78
|
+
case 15:
|
|
79
|
+
data = (((_res = res) === null || _res === void 0 ? void 0 : _res.rows) || []).map(function (item) {
|
|
80
|
+
return {
|
|
81
|
+
value: item === null || item === void 0 ? void 0 : item[dictValue],
|
|
82
|
+
text: item === null || item === void 0 ? void 0 : item[dictLabel],
|
|
83
|
+
label: type === '1' ? (item === null || item === void 0 ? void 0 : item[dictValue]) + '→' + (item === null || item === void 0 ? void 0 : item[dictLabel]) : item === null || item === void 0 ? void 0 : item[dictLabel],
|
|
84
|
+
children: item === null || item === void 0 ? void 0 : item.children,
|
|
85
|
+
items: item
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
setOptions(data);
|
|
89
|
+
case 17:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}, _callee);
|
|
94
|
+
}));
|
|
95
|
+
return function requestOptions() {
|
|
96
|
+
return _ref.apply(this, arguments);
|
|
97
|
+
};
|
|
98
|
+
}();
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
requestOptions();
|
|
101
|
+
}, []);
|
|
102
|
+
return [options, setOptions];
|
|
103
|
+
};
|
|
104
|
+
export default useBaseDict;
|
|
@@ -12,6 +12,7 @@ import { PlusCircleOutlined, EditOutlined, DeleteOutlined, ImportOutlined, Expor
|
|
|
12
12
|
import { showConfirm, showWarn, showError, showSuccess } from '../../utils';
|
|
13
13
|
import { httpPost } from '../../http';
|
|
14
14
|
import usePermission from '../usePermission';
|
|
15
|
+
import exportProcess from '../../utils/exportProcess';
|
|
15
16
|
function useDtl(dtlParam) {
|
|
16
17
|
var mstService = dtlParam.service,
|
|
17
18
|
masterObject = dtlParam.initItem,
|
|
@@ -729,7 +730,7 @@ function useDtl(dtlParam) {
|
|
|
729
730
|
var onExportDtl = /*#__PURE__*/function () {
|
|
730
731
|
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url, param) {
|
|
731
732
|
var _param$exportColumns;
|
|
732
|
-
var searchArr, arr, otherArr, whereArr, where, _result$flag6, result, _result$flag7
|
|
733
|
+
var searchArr, arr, otherArr, whereArr, where, _result$flag6, result, _result$flag7;
|
|
733
734
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
734
735
|
while (1) switch (_context9.prev = _context9.next) {
|
|
735
736
|
case 0:
|
|
@@ -802,10 +803,11 @@ function useDtl(dtlParam) {
|
|
|
802
803
|
_context9.next = 19;
|
|
803
804
|
break;
|
|
804
805
|
}
|
|
805
|
-
|
|
806
|
+
exportProcess(result);
|
|
807
|
+
// showSuccess(result.flag?.retMsg || '导出成功');
|
|
806
808
|
return _context9.abrupt("return", true);
|
|
807
809
|
case 19:
|
|
808
|
-
showError(((_result$
|
|
810
|
+
showError(((_result$flag7 = result.flag) === null || _result$flag7 === void 0 ? void 0 : _result$flag7.retMsg) || '导出失败,请联系系统管理员');
|
|
809
811
|
return _context9.abrupt("return", false);
|
|
810
812
|
case 21:
|
|
811
813
|
_context9.next = 27;
|
|
@@ -828,7 +830,7 @@ function useDtl(dtlParam) {
|
|
|
828
830
|
/** 审核按钮事件 */
|
|
829
831
|
var onAudit = /*#__PURE__*/function () {
|
|
830
832
|
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
831
|
-
var obj, _result$
|
|
833
|
+
var obj, _result$flag8, result;
|
|
832
834
|
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
833
835
|
while (1) switch (_context10.prev = _context10.next) {
|
|
834
836
|
case 0:
|
|
@@ -898,7 +900,7 @@ function useDtl(dtlParam) {
|
|
|
898
900
|
}
|
|
899
901
|
return _context10.abrupt("return");
|
|
900
902
|
case 36:
|
|
901
|
-
if ((result === null || result === void 0 ? void 0 : (_result$
|
|
903
|
+
if ((result === null || result === void 0 ? void 0 : (_result$flag8 = result.flag) === null || _result$flag8 === void 0 ? void 0 : _result$flag8.retCode) === '0') {
|
|
902
904
|
showSuccess(result.flag.retMsg || '审核成功');
|
|
903
905
|
Object.assign(masterObject, result.data);
|
|
904
906
|
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name 本地查询字段清空
|
|
3
|
-
*/
|
|
1
|
+
/** @name 本地查询字段清空 */
|
|
4
2
|
interface useFilterLocalType {
|
|
5
|
-
|
|
3
|
+
/** @name 表格的actionRef */
|
|
6
4
|
tableRef: any;
|
|
7
5
|
}
|
|
8
6
|
interface useFilterBack {
|
|
9
|
-
|
|
7
|
+
/** @name 已存在过滤字段数量 */
|
|
10
8
|
filterLocal: number;
|
|
11
|
-
|
|
9
|
+
/** @name 设置已存在过滤数量 */
|
|
12
10
|
setFilterLocal: any;
|
|
13
|
-
|
|
11
|
+
/** @name 根据filter中的值设置filterLocal */
|
|
14
12
|
changeFilterFun: (val: any) => void;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* 结合table中的onChange第二个参数filter使用, 可直接使用changeFilterFun(filter)
|
|
16
|
+
*
|
|
19
17
|
* @param props
|
|
18
|
+
* @name 本地过滤条件清空图标
|
|
20
19
|
* @returns
|
|
21
20
|
*/
|
|
22
21
|
export declare const useFilterLocal: (props: useFilterLocalType) => useFilterBack;
|
|
23
|
-
export
|
|
22
|
+
export default useFilterLocal;
|
|
@@ -3,17 +3,16 @@ import _Tooltip from "antd/es/tooltip";
|
|
|
3
3
|
import "antd/es/badge/style";
|
|
4
4
|
import _Badge from "antd/es/badge";
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
-
/**
|
|
7
|
-
* @name 本地查询字段清空
|
|
8
|
-
*/
|
|
6
|
+
/** @name 本地查询字段清空 */
|
|
9
7
|
import { useEffect, useState } from 'react';
|
|
10
8
|
import { ClearOutlined } from '@ant-design/icons';
|
|
11
9
|
import React from 'react';
|
|
12
10
|
import ReactDOM from 'react-dom';
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* 结合table中的onChange第二个参数filter使用, 可直接使用changeFilterFun(filter)
|
|
13
|
+
*
|
|
16
14
|
* @param props
|
|
15
|
+
* @name 本地过滤条件清空图标
|
|
17
16
|
* @returns
|
|
18
17
|
*/
|
|
19
18
|
export var useFilterLocal = function useFilterLocal(props) {
|
|
@@ -75,4 +74,5 @@ export var useFilterLocal = function useFilterLocal(props) {
|
|
|
75
74
|
filterLocal: filterLocal,
|
|
76
75
|
changeFilterFun: changeFilterFun
|
|
77
76
|
};
|
|
78
|
-
};
|
|
77
|
+
};
|
|
78
|
+
export default useFilterLocal;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** @name 请求select的options */
|
|
2
|
+
interface useSelectOptionsType {
|
|
3
|
+
/** @name 请求前操作,可直接返回false */
|
|
4
|
+
beforeLoad?: (val: Record<string, any>, setOptions: (options: any[]) => any) => Promise<boolean>;
|
|
5
|
+
/** @name 请求后操作,针对返回的res操作 */
|
|
6
|
+
afterLoad?: (val?: any) => Promise<any[]>;
|
|
7
|
+
/** @name 字段名 */
|
|
8
|
+
name?: any;
|
|
9
|
+
/** @name 请求配置 */
|
|
10
|
+
requestProps?: {
|
|
11
|
+
/** @name 字典item的value */
|
|
12
|
+
dictValue?: string;
|
|
13
|
+
/** @name 字典item的label */
|
|
14
|
+
dictLabel?: string;
|
|
15
|
+
/**
|
|
16
|
+
* @default GET
|
|
17
|
+
* @name 请求方式
|
|
18
|
+
*/
|
|
19
|
+
method?: 'GET' | 'POST';
|
|
20
|
+
/**
|
|
21
|
+
* @param val 搜索的值
|
|
22
|
+
* @name 更改params
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
changeParams?: (val?: string) => any;
|
|
26
|
+
/** @name 请求的url */
|
|
27
|
+
url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @default true
|
|
30
|
+
* @name 是否需要网关
|
|
31
|
+
*/
|
|
32
|
+
needGateWay?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @default true
|
|
35
|
+
* @name 是否是JSON post中会使用
|
|
36
|
+
*/
|
|
37
|
+
isJson?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @default 500
|
|
41
|
+
* @name 防抖时间
|
|
42
|
+
*/
|
|
43
|
+
debounceTime?: number;
|
|
44
|
+
/**
|
|
45
|
+
* @default true
|
|
46
|
+
* @name 自动第一次请求
|
|
47
|
+
*/
|
|
48
|
+
autoLoad?: boolean;
|
|
49
|
+
/** @name 1label返回中文带箭头 2label返回中文不带箭头 */
|
|
50
|
+
type?: '1' | '2';
|
|
51
|
+
}
|
|
52
|
+
interface useSelectOptionsBack {
|
|
53
|
+
/** @name 请求到的枚举字典 */
|
|
54
|
+
options: any[];
|
|
55
|
+
/** @name 设置请求到的枚举字典 */
|
|
56
|
+
setOptions: (options: any[]) => any;
|
|
57
|
+
/** @name 防抖请求 */
|
|
58
|
+
nameSearchFun: (val?: string) => void;
|
|
59
|
+
/** @name 直接请求 */
|
|
60
|
+
requestOptions: (val?: string) => void;
|
|
61
|
+
/** @name 设置本地搜索的枚举字典 */
|
|
62
|
+
setLocalSearch: (options: any[]) => any;
|
|
63
|
+
/** @name 本地搜索的枚举字典 */
|
|
64
|
+
localSearch: any[];
|
|
65
|
+
/** @name 请求到的枚举字典+本地搜索的枚举字典组合后的值 */
|
|
66
|
+
totalDataAll: any[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param fn
|
|
70
|
+
* @param delay
|
|
71
|
+
* @name 防抖
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
export declare const debounce: (fn: any, delay?: number) => (...rest: any) => void;
|
|
75
|
+
/**
|
|
76
|
+
* @param props
|
|
77
|
+
* @name 动态请求select的options
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
export declare const useSelectOptions: (props: useSelectOptionsType) => useSelectOptionsBack;
|
|
81
|
+
export default useSelectOptions;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
+
var _this = this;
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
/** @name 请求select的options */
|
|
8
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { httpGet, httpPost } from '../http';
|
|
10
|
+
import { showWarn } from '../utils';
|
|
11
|
+
/**
|
|
12
|
+
* @param fn
|
|
13
|
+
* @param delay
|
|
14
|
+
* @name 防抖
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export var debounce = function debounce(fn) {
|
|
18
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
|
19
|
+
var timer = null;
|
|
20
|
+
return function () {
|
|
21
|
+
for (var _len = arguments.length, rest = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
|
+
rest[_key] = arguments[_key];
|
|
23
|
+
}
|
|
24
|
+
var args = rest;
|
|
25
|
+
if (timer) clearTimeout(timer);
|
|
26
|
+
timer = setTimeout(function () {
|
|
27
|
+
fn.apply(_this, args);
|
|
28
|
+
timer = null;
|
|
29
|
+
}, delay);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @param props
|
|
34
|
+
* @name 动态请求select的options
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export var useSelectOptions = function useSelectOptions(props) {
|
|
38
|
+
var beforeLoad = props.beforeLoad,
|
|
39
|
+
afterLoad = props.afterLoad,
|
|
40
|
+
name = props.name,
|
|
41
|
+
_props$debounceTime = props.debounceTime,
|
|
42
|
+
debounceTime = _props$debounceTime === void 0 ? 500 : _props$debounceTime,
|
|
43
|
+
_props$requestProps = props.requestProps,
|
|
44
|
+
requestProps = _props$requestProps === void 0 ? {} : _props$requestProps,
|
|
45
|
+
_props$autoLoad = props.autoLoad,
|
|
46
|
+
autoLoad = _props$autoLoad === void 0 ? true : _props$autoLoad;
|
|
47
|
+
var url = requestProps.url,
|
|
48
|
+
_requestProps$method = requestProps.method,
|
|
49
|
+
method = _requestProps$method === void 0 ? 'GET' : _requestProps$method,
|
|
50
|
+
dictValue = requestProps.dictValue,
|
|
51
|
+
dictLabel = requestProps.dictLabel,
|
|
52
|
+
changeParams = requestProps.changeParams,
|
|
53
|
+
_requestProps$needGat = requestProps.needGateWay,
|
|
54
|
+
needGateWay = _requestProps$needGat === void 0 ? true : _requestProps$needGat,
|
|
55
|
+
_requestProps$isJson = requestProps.isJson,
|
|
56
|
+
isJson = _requestProps$isJson === void 0 ? true : _requestProps$isJson;
|
|
57
|
+
var _useState = useState([]),
|
|
58
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
59
|
+
options = _useState2[0],
|
|
60
|
+
setOptions = _useState2[1];
|
|
61
|
+
var _useState3 = useState([]),
|
|
62
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
63
|
+
localSearch = _useState4[0],
|
|
64
|
+
setLocalSearch = _useState4[1];
|
|
65
|
+
/** @name 下拉框请求数据 */
|
|
66
|
+
var requestOptions = /*#__PURE__*/function () {
|
|
67
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
68
|
+
var val,
|
|
69
|
+
res,
|
|
70
|
+
params,
|
|
71
|
+
data,
|
|
72
|
+
_res,
|
|
73
|
+
_args = arguments;
|
|
74
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
75
|
+
while (1) switch (_context.prev = _context.next) {
|
|
76
|
+
case 0:
|
|
77
|
+
val = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
|
|
78
|
+
_context.t0 = beforeLoad;
|
|
79
|
+
if (!_context.t0) {
|
|
80
|
+
_context.next = 7;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
_context.next = 5;
|
|
84
|
+
return beforeLoad(val, setOptions);
|
|
85
|
+
case 5:
|
|
86
|
+
_context.t1 = _context.sent;
|
|
87
|
+
_context.t0 = _context.t1 === false;
|
|
88
|
+
case 7:
|
|
89
|
+
if (!_context.t0) {
|
|
90
|
+
_context.next = 9;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
return _context.abrupt("return");
|
|
94
|
+
case 9:
|
|
95
|
+
if (url) {
|
|
96
|
+
_context.next = 12;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
showWarn('请配置url');
|
|
100
|
+
return _context.abrupt("return");
|
|
101
|
+
case 12:
|
|
102
|
+
params = {
|
|
103
|
+
page: 1,
|
|
104
|
+
pageSize: 20,
|
|
105
|
+
where: _defineProperty({}, name, val)
|
|
106
|
+
};
|
|
107
|
+
if (changeParams) {
|
|
108
|
+
params = changeParams(val);
|
|
109
|
+
}
|
|
110
|
+
if (!(method === 'GET')) {
|
|
111
|
+
_context.next = 20;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
_context.next = 17;
|
|
115
|
+
return httpGet(url, params, needGateWay);
|
|
116
|
+
case 17:
|
|
117
|
+
res = _context.sent;
|
|
118
|
+
_context.next = 24;
|
|
119
|
+
break;
|
|
120
|
+
case 20:
|
|
121
|
+
if (!(method === 'POST')) {
|
|
122
|
+
_context.next = 24;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
_context.next = 23;
|
|
126
|
+
return httpPost(url, params, isJson, needGateWay);
|
|
127
|
+
case 23:
|
|
128
|
+
res = _context.sent;
|
|
129
|
+
case 24:
|
|
130
|
+
data = [];
|
|
131
|
+
if (!afterLoad) {
|
|
132
|
+
_context.next = 31;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
_context.next = 28;
|
|
136
|
+
return afterLoad(res);
|
|
137
|
+
case 28:
|
|
138
|
+
data = _context.sent;
|
|
139
|
+
_context.next = 32;
|
|
140
|
+
break;
|
|
141
|
+
case 31:
|
|
142
|
+
if (dictValue && dictLabel) {
|
|
143
|
+
data = (((_res = res) === null || _res === void 0 ? void 0 : _res.rows) || []).map(function (item) {
|
|
144
|
+
return {
|
|
145
|
+
value: item === null || item === void 0 ? void 0 : item[dictValue],
|
|
146
|
+
text: item === null || item === void 0 ? void 0 : item[dictLabel],
|
|
147
|
+
label: (item === null || item === void 0 ? void 0 : item[dictValue]) + '→' + (item === null || item === void 0 ? void 0 : item[dictLabel]),
|
|
148
|
+
children: item === null || item === void 0 ? void 0 : item.children,
|
|
149
|
+
items: item
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
showWarn('请配置afterLoad或设置dictValue和dictLabel');
|
|
154
|
+
}
|
|
155
|
+
case 32:
|
|
156
|
+
setOptions(data);
|
|
157
|
+
case 33:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context.stop();
|
|
160
|
+
}
|
|
161
|
+
}, _callee);
|
|
162
|
+
}));
|
|
163
|
+
return function requestOptions() {
|
|
164
|
+
return _ref.apply(this, arguments);
|
|
165
|
+
};
|
|
166
|
+
}();
|
|
167
|
+
/** @name 防抖函数 使用useCallback来缓存函数 */
|
|
168
|
+
var nameSearchFun = useCallback(debounce( /*#__PURE__*/function () {
|
|
169
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
|
|
170
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
171
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
172
|
+
case 0:
|
|
173
|
+
return _context2.abrupt("return", requestOptions(params));
|
|
174
|
+
case 1:
|
|
175
|
+
case "end":
|
|
176
|
+
return _context2.stop();
|
|
177
|
+
}
|
|
178
|
+
}, _callee2);
|
|
179
|
+
}));
|
|
180
|
+
return function (_x) {
|
|
181
|
+
return _ref2.apply(this, arguments);
|
|
182
|
+
};
|
|
183
|
+
}(), debounceTime), []);
|
|
184
|
+
useEffect(function () {
|
|
185
|
+
if (autoLoad) {
|
|
186
|
+
requestOptions();
|
|
187
|
+
}
|
|
188
|
+
}, [autoLoad]);
|
|
189
|
+
var totalDataAll = useMemo(function () {
|
|
190
|
+
var res = [].concat(_toConsumableArray(localSearch), _toConsumableArray(options)).reduce(function (acc, current) {
|
|
191
|
+
if (!acc.find(function (item) {
|
|
192
|
+
return item.value === current.value;
|
|
193
|
+
})) {
|
|
194
|
+
acc.push(current);
|
|
195
|
+
}
|
|
196
|
+
return acc;
|
|
197
|
+
}, []);
|
|
198
|
+
return res;
|
|
199
|
+
}, [localSearch, options]);
|
|
200
|
+
return {
|
|
201
|
+
options: options,
|
|
202
|
+
setOptions: setOptions,
|
|
203
|
+
nameSearchFun: nameSearchFun,
|
|
204
|
+
requestOptions: requestOptions,
|
|
205
|
+
localSearch: localSearch,
|
|
206
|
+
setLocalSearch: setLocalSearch,
|
|
207
|
+
totalDataAll: totalDataAll
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
export default useSelectOptions;
|