ztxkui 2.0.0 → 2.0.4
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/Demo.js +5 -3
- package/dist/components/EnhanceSelect/index.js +21 -10
- package/package.json +1 -1
package/dist/Demo.js
CHANGED
|
@@ -6,7 +6,7 @@ var selectStyle = { width: '200px' };
|
|
|
6
6
|
function request(options) {
|
|
7
7
|
return fetch(options.url + "?" + stringify(options.params), {
|
|
8
8
|
headers: {
|
|
9
|
-
'Zmdms-Auth': 'bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
|
9
|
+
'Zmdms-Auth': 'bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJtZW1iZXJfdHlwZSI6MSwiaGFuZGxlX2hyX3Bob25lIjpudWxsLCJyZXN1bWVfZGF0ZSI6bnVsbCwidXNlcl9uYW1lIjoiY2hlbnl4IiwiaW10X2lkIjpudWxsLCJyZWFsX25hbWUiOiLpmYjkuprpm4QiLCJjbGllbnRfdHlwZSI6IndlYiIsImRhdGFfcm9sZV9pZCI6IjEzNDU5Nzg1MDUzMDIwNTY5NjIsMTQxMjYxNDExMDY0NzM4NjExNCwxNDEyNjE1Njc3MTE5MjY2ODE3LDE0NDgxMjEwODY1MDQzMDA1NDYsMTQ1MjgyMDI5MzgwMjcxMzA5MCwxNDUzOTI1MDAxNTMxNDc4MDE3LDE0NTg3MTIwODIwODIzNTcyNTAsMTQ1ODgyNjIzODE4NTg4OTc5NCwxNDU4ODI3NzAxMDEyMzI0MzUzLDE0NTg4MjgzNjA4MDE1MDkzNzcsMTQ2MDA4OTI2MjAxMjAzMDk3NywxNDYxMTM3Nzg4NjQ1MTI2MTQ2IiwiY2xpZW50X2lkIjoic3dvcmQiLCJ1c2VyX3R5cGUiOiJ3ZWIiLCJyb2xlX2lkIjoiMTQxMjYwODc0Mjk1MzI4NzY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MzI4NDI0NDQ5IiwiaGFuZGxlX2hyX25hbWUiOm51bGwsImFjY291bnQiOiJjaGVueXgiLCJyZXN1bWVfaWQiOm51bGx9.Moo8uYZzd7bNGw_jsydYQvyf5lVoJA8LLUNQdkPxXac',
|
|
10
10
|
},
|
|
11
11
|
method: options.method,
|
|
12
12
|
}).then(function (response) { return response.json(); });
|
|
@@ -47,7 +47,7 @@ function Demo() {
|
|
|
47
47
|
projectName: '项目12',
|
|
48
48
|
},
|
|
49
49
|
]);
|
|
50
|
-
setValue('1462433051208761603');
|
|
50
|
+
// setValue('1462433051208761603');
|
|
51
51
|
}, 2000);
|
|
52
52
|
return function () {
|
|
53
53
|
if (timeoutId) {
|
|
@@ -65,6 +65,8 @@ function Demo() {
|
|
|
65
65
|
React.createElement("h2", null, "\u5F02\u6B65\u83B7\u53D6\u6570\u636E"),
|
|
66
66
|
React.createElement("h2", null, "\u5F02\u6B65\u83B7\u53D6\u6570\u636E\uFF0C\u5E76\u7F13\u5B58\u6570\u636E"),
|
|
67
67
|
React.createElement("h2", null, "\u8FDC\u7A0B\u6A21\u7CCA\u641C\u7D22"),
|
|
68
|
-
React.createElement(EnhanceSelect, { style: selectStyle, placeholder: "\u53EF\u8FDC\u7A0B\u6A21\u7CCA\u641C\u7D22", url: "http://192.168.0.
|
|
68
|
+
React.createElement(EnhanceSelect, { style: selectStyle, placeholder: "\u53EF\u8FDC\u7A0B\u6A21\u7CCA\u641C\u7D22", url: "http://192.168.0.83:8000/api/zmdms-system/employee/page", request: request, remoteSearch: true, dataKey: "id", titleKey: "empName",
|
|
69
|
+
// value={value}
|
|
70
|
+
mode: "multiple" })));
|
|
69
71
|
}
|
|
70
72
|
export default Demo;
|
|
@@ -74,9 +74,11 @@ function EnhanceSelect(_a) {
|
|
|
74
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, transformData = _a.transformData, joinKey = _a.joinKey, _e = _a.joinStr, joinStr = _e === void 0 ? '-' : _e, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "transformData", "joinKey", "joinStr"]);
|
|
75
75
|
// 下拉数据源
|
|
76
76
|
var _f = useFetchState([]), selectList = _f[0], setSelectList = _f[1];
|
|
77
|
-
|
|
77
|
+
// 多选时,自己需要合并的数据
|
|
78
|
+
var _g = useFetchState([]), multipleList = _g[0], setMultipleList = _g[1];
|
|
79
|
+
var _h = useFetchState(false), loading = _h[0], setLoading = _h[1];
|
|
78
80
|
var fetchId = useRef(0); // 请求Id,每次请求都会加1
|
|
79
|
-
var
|
|
81
|
+
var _j = useFetchState(false), firstLoading = _j[0], setFirstLoading = _j[1];
|
|
80
82
|
// 如果selectList 发生改变,那么触发onCompleted事件
|
|
81
83
|
useEffect(function () {
|
|
82
84
|
if (Array.isArray(selectList) && onCompleted) {
|
|
@@ -134,7 +136,7 @@ function EnhanceSelect(_a) {
|
|
|
134
136
|
searchParams[searchKey] = value;
|
|
135
137
|
}
|
|
136
138
|
if (dataKeyValue) {
|
|
137
|
-
searchParams[searchDataKey] = dataKeyValue;
|
|
139
|
+
searchParams[searchDataKey] = dataKeyValue + '';
|
|
138
140
|
}
|
|
139
141
|
getData(request, {
|
|
140
142
|
url: url,
|
|
@@ -245,7 +247,8 @@ function EnhanceSelect(_a) {
|
|
|
245
247
|
getRemoteDataHandle('', '');
|
|
246
248
|
}
|
|
247
249
|
else {
|
|
248
|
-
if (typeof restProps.value === 'string'
|
|
250
|
+
if (typeof restProps.value === 'string' ||
|
|
251
|
+
Array.isArray(restProps.value)) {
|
|
249
252
|
setFirstLoading(true);
|
|
250
253
|
getRemoteDataHandle('', restProps.value);
|
|
251
254
|
}
|
|
@@ -269,8 +272,10 @@ function EnhanceSelect(_a) {
|
|
|
269
272
|
newData.forEach(function (item) {
|
|
270
273
|
// 如果源数组中找到了该条数据,那么不添加
|
|
271
274
|
// 否则添加
|
|
272
|
-
if (!resultData.find(function (resultItem) {
|
|
273
|
-
|
|
275
|
+
if (!resultData.find(function (resultItem) {
|
|
276
|
+
return resultItem && item && resultItem[dataKey] === item[dataKey];
|
|
277
|
+
})) {
|
|
278
|
+
resultData.push(item);
|
|
274
279
|
}
|
|
275
280
|
});
|
|
276
281
|
}
|
|
@@ -282,7 +287,7 @@ function EnhanceSelect(_a) {
|
|
|
282
287
|
return (React.createElement(React.Fragment, null,
|
|
283
288
|
showAll && (React.createElement(Select.Option, { title: "\u5168\u90E8", value: "" }, "\u5168\u90E8")),
|
|
284
289
|
Array.isArray(selectList) &&
|
|
285
|
-
concatData(selectList, _defaultList).map(function (item) {
|
|
290
|
+
concatData(concatData(selectList, _defaultList), multipleList).map(function (item) {
|
|
286
291
|
var key = componentKey ? item[componentKey] : item[dataKey];
|
|
287
292
|
var value = item[dataKey];
|
|
288
293
|
var title = item[titleKey];
|
|
@@ -310,17 +315,23 @@ function EnhanceSelect(_a) {
|
|
|
310
315
|
};
|
|
311
316
|
// onChange 方法
|
|
312
317
|
var onChangeHandle = function (value, option) {
|
|
313
|
-
|
|
318
|
+
var _defaultList = Array.isArray(defaultList) ? defaultList : [];
|
|
319
|
+
var currentList = concatData(concatData(selectList || [], _defaultList), multipleList || []);
|
|
320
|
+
if (currentList && Array.isArray(currentList)) {
|
|
314
321
|
var key_1 = dataKey;
|
|
315
322
|
// 支持多选模式
|
|
316
323
|
var currentData = void 0;
|
|
317
324
|
if (Array.isArray(value)) {
|
|
318
325
|
currentData = value.map(function (valueItem) {
|
|
319
|
-
return
|
|
326
|
+
return currentList.find(function (item) { return item[key_1] === valueItem; });
|
|
320
327
|
});
|
|
328
|
+
currentData = currentData === null || currentData === void 0 ? void 0 : currentData.filter(function (item) { return item; });
|
|
329
|
+
if (remoteSearch) {
|
|
330
|
+
setMultipleList(currentData);
|
|
331
|
+
}
|
|
321
332
|
}
|
|
322
333
|
else {
|
|
323
|
-
currentData =
|
|
334
|
+
currentData = currentList.find(function (item) { return item[key_1] === value; });
|
|
324
335
|
}
|
|
325
336
|
onChange && onChange(value, option, currentData);
|
|
326
337
|
}
|