ztxkui 2.2.8 → 2.3.2
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.
|
@@ -87,6 +87,10 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
87
87
|
* 接口数据格式转换
|
|
88
88
|
*/
|
|
89
89
|
transformData?: (res: any) => any;
|
|
90
|
+
/**
|
|
91
|
+
* 增加必传参数组
|
|
92
|
+
*/
|
|
93
|
+
mustHasParams?: string | string[];
|
|
90
94
|
}
|
|
91
95
|
/**
|
|
92
96
|
* 增强下拉框功能组件
|
|
@@ -103,6 +107,6 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
103
107
|
* { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
|
|
104
108
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
105
109
|
*/
|
|
106
|
-
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, joinKey, joinStr, ...restProps }: IProps<VT>): JSX.Element;
|
|
110
|
+
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, joinKey, joinStr, mustHasParams, ...restProps }: IProps<VT>): JSX.Element;
|
|
107
111
|
declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
|
|
108
112
|
export default _default;
|
|
@@ -39,6 +39,7 @@ import debounce from 'lodash/debounce';
|
|
|
39
39
|
var enhanceSelectCatchObj = {};
|
|
40
40
|
// 获取接口数据
|
|
41
41
|
function getData(request, options) {
|
|
42
|
+
var _a;
|
|
42
43
|
if (typeof request === 'function') {
|
|
43
44
|
if (typeof options.params === 'string') {
|
|
44
45
|
try {
|
|
@@ -48,6 +49,10 @@ function getData(request, options) {
|
|
|
48
49
|
console.log(err);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
if (((_a = options === null || options === void 0 ? void 0 : options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'POST') {
|
|
53
|
+
options.data = options.params;
|
|
54
|
+
Reflect.deleteProperty(options, 'params');
|
|
55
|
+
}
|
|
51
56
|
return request(options);
|
|
52
57
|
}
|
|
53
58
|
return Promise.resolve({
|
|
@@ -71,7 +76,7 @@ function getData(request, options) {
|
|
|
71
76
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
72
77
|
*/
|
|
73
78
|
function EnhanceSelect(_a) {
|
|
74
|
-
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _e = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _e === void 0 ? true : _e, transformData = _a.transformData, joinKey = _a.joinKey, _f = _a.joinStr, joinStr = _f === void 0 ? '-' : _f, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr"]);
|
|
79
|
+
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _e = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _e === void 0 ? true : _e, transformData = _a.transformData, joinKey = _a.joinKey, _f = _a.joinStr, joinStr = _f === void 0 ? '-' : _f, mustHasParams = _a.mustHasParams, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr", "mustHasParams"]);
|
|
75
80
|
// 下拉数据源
|
|
76
81
|
var _g = useFetchState([]), selectList = _g[0], setSelectList = _g[1];
|
|
77
82
|
// 多选时,自己需要合并的数据
|
|
@@ -91,6 +96,30 @@ function EnhanceSelect(_a) {
|
|
|
91
96
|
}, [selectList]);
|
|
92
97
|
// 获取数据,并设置数据
|
|
93
98
|
var getDataHandle = useCallback(function (request, options, appointObj) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (mustHasParams) {
|
|
101
|
+
var _params_1;
|
|
102
|
+
if (typeof options.params === 'string') {
|
|
103
|
+
try {
|
|
104
|
+
_params_1 = JSON.parse(options.params);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.log(err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (((_a = options === null || options === void 0 ? void 0 : options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'POST') {
|
|
111
|
+
_params_1 = options.params;
|
|
112
|
+
}
|
|
113
|
+
// 如果必传参数不存在
|
|
114
|
+
if (typeof mustHasParams === 'string' &&
|
|
115
|
+
_params_1[mustHasParams] == null) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(mustHasParams) &&
|
|
119
|
+
mustHasParams.find(function (key) { return _params_1[key] == null; })) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
94
123
|
setLoading(true);
|
|
95
124
|
// 利用闭包,存到当前请求的id
|
|
96
125
|
fetchId.current++;
|
|
@@ -120,7 +149,7 @@ function EnhanceSelect(_a) {
|
|
|
120
149
|
setLoading(false);
|
|
121
150
|
console.log(err);
|
|
122
151
|
});
|
|
123
|
-
}, [setSelectList, setLoading, transformData]);
|
|
152
|
+
}, [setSelectList, setLoading, transformData, mustHasParams]);
|
|
124
153
|
// 远程搜索
|
|
125
154
|
var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
|
|
126
155
|
var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
|
|
@@ -264,9 +293,9 @@ function EnhanceSelect(_a) {
|
|
|
264
293
|
// console.log('已经通过id访问了');
|
|
265
294
|
return;
|
|
266
295
|
}
|
|
296
|
+
// TODO:注释这里的内容
|
|
267
297
|
// 这种情况不需要启用远程搜索key值
|
|
268
298
|
if (!isRemoteSearchDataKey) {
|
|
269
|
-
getRemoteDataHandle('', '');
|
|
270
299
|
setFirstLoading(true);
|
|
271
300
|
return;
|
|
272
301
|
}
|
|
@@ -291,6 +320,24 @@ function EnhanceSelect(_a) {
|
|
|
291
320
|
isRemoteSearchDataKey,
|
|
292
321
|
setFirstLoading,
|
|
293
322
|
]);
|
|
323
|
+
useEffect(function () {
|
|
324
|
+
if (!url || !remoteSearch) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// console.log('TEST: 远程搜索');
|
|
328
|
+
// 这种情况不需要启用远程搜索key值
|
|
329
|
+
if (!isRemoteSearchDataKey) {
|
|
330
|
+
getRemoteDataHandle('', '');
|
|
331
|
+
setFirstLoading(true);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
}, [
|
|
335
|
+
url,
|
|
336
|
+
remoteSearch,
|
|
337
|
+
setFirstLoading,
|
|
338
|
+
getRemoteDataHandle,
|
|
339
|
+
isRemoteSearchDataKey,
|
|
340
|
+
]);
|
|
294
341
|
// 数据合并
|
|
295
342
|
function concatData(originalData, newData) {
|
|
296
343
|
if (!newData) {
|