ztxkui 1.9.8 → 2.0.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.
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.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJtZW1iZXJfdHlwZSI6MSwiaGFuZGxlX2hyX3Bob25lIjpudWxsLCJyZXN1bWVfZGF0ZSI6bnVsbCwidXNlcl9uYW1lIjoiY2hlbnl4IiwiaW10X2lkIjpudWxsLCJyZWFsX25hbWUiOiLpmYjkuprpm4QiLCJjbGllbnRfdHlwZSI6IndlYiIsImRhdGFfcm9sZV9pZCI6IjEzNDU5Nzg1MDUzMDIwNTY5NjIsMTQxMjYxNDExMDY0NzM4NjExNCwxNDEyNjE1Njc3MTE5MjY2ODE3LDE0NDgxMjEwODY1MDQzMDA1NDYsMTQ1MjgyMDI5MzgwMjcxMzA5MCwxNDUzOTI1MDAxNTMxNDc4MDE3LDE0NTg3MTIwODIwODIzNTcyNTAsMTQ1ODgyNjIzODE4NTg4OTc5NCwxNDU4ODI3NzAxMDEyMzI0MzUzLDE0NTg4MjgzNjA4MDE1MDkzNzcsMTQ2MDA4OTI2MjAxMjAzMDk3NywxNDYxMTM3Nzg4NjQ1MTI2MTQ2IiwiY2xpZW50X2lkIjoic3dvcmQiLCJ1c2VyX3R5cGUiOiJ3ZWIiLCJyb2xlX2lkIjoiMTQxMjYwODc0Mjk1MzI4NzY4MiwxNDM4MzIyNTQzMjk1OTI2Mjc0LDE0NDM0NzU0NzU5NzI3MzQ5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jaGVueXgiLCJyZXN1bWVfaWQiOm51bGx9.Moo8uYZzd7bNGw_jsydYQvyf5lVoJA8LLUNQdkPxXac',
|
|
10
10
|
},
|
|
11
11
|
method: options.method,
|
|
12
12
|
}).then(function (response) { return response.json(); });
|
|
@@ -15,6 +15,7 @@ function Demo() {
|
|
|
15
15
|
console.log('rerender');
|
|
16
16
|
var _a = useState([]), list = _a[0], setList = _a[1];
|
|
17
17
|
var _b = useState([]), defaultList = _b[0], setDefaultList = _b[1];
|
|
18
|
+
var _c = useState(''), value = _c[0], setValue = _c[1];
|
|
18
19
|
// 模拟接口请求
|
|
19
20
|
useEffect(function () {
|
|
20
21
|
var timeoutId = setTimeout(function () {
|
|
@@ -46,6 +47,7 @@ function Demo() {
|
|
|
46
47
|
projectName: '项目12',
|
|
47
48
|
},
|
|
48
49
|
]);
|
|
50
|
+
// setValue('1462433051208761603');
|
|
49
51
|
}, 2000);
|
|
50
52
|
return function () {
|
|
51
53
|
if (timeoutId) {
|
|
@@ -61,18 +63,10 @@ function Demo() {
|
|
|
61
63
|
console.log(value, option, fullData);
|
|
62
64
|
} }),
|
|
63
65
|
React.createElement("h2", null, "\u5F02\u6B65\u83B7\u53D6\u6570\u636E"),
|
|
64
|
-
React.createElement(EnhanceSelect, { style: selectStyle, url: "http://192.168.0.83:8000/api/zmdms-user/list", params: JSON.stringify({
|
|
65
|
-
status: 50,
|
|
66
|
-
companyId: '1397074605412696066',
|
|
67
|
-
}), request: request, joinKey: "depName" }),
|
|
68
66
|
React.createElement("h2", null, "\u5F02\u6B65\u83B7\u53D6\u6570\u636E\uFF0C\u5E76\u7F13\u5B58\u6570\u636E"),
|
|
69
|
-
React.createElement(EnhanceSelect, { style: selectStyle, url: "http://192.168.0.83:8000/api/zmdms-user/list", params: JSON.stringify({
|
|
70
|
-
status: 50,
|
|
71
|
-
companyId: '1397074605412696066',
|
|
72
|
-
}), request: request, isCatch: true }),
|
|
73
67
|
React.createElement("h2", null, "\u8FDC\u7A0B\u6A21\u7CCA\u641C\u7D22"),
|
|
74
|
-
React.createElement(EnhanceSelect, { style: selectStyle, placeholder: "\u53EF\u8FDC\u7A0B\u6A21\u7CCA\u641C\u7D22", url: "http://192.168.0.83:8000/api/zmdms-
|
|
75
|
-
|
|
76
|
-
|
|
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" })));
|
|
77
71
|
}
|
|
78
72
|
export default Demo;
|
|
@@ -75,6 +75,10 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
75
75
|
* 远程搜索Key值
|
|
76
76
|
*/
|
|
77
77
|
remoteSearchKey?: string;
|
|
78
|
+
/**
|
|
79
|
+
* 远程搜索主键Key值
|
|
80
|
+
*/
|
|
81
|
+
remoteSearchDataKey?: string;
|
|
78
82
|
/**
|
|
79
83
|
* 接口数据格式转换
|
|
80
84
|
*/
|
|
@@ -95,6 +99,6 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
95
99
|
* { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
|
|
96
100
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
97
101
|
*/
|
|
98
|
-
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, transformData, joinKey, joinStr, ...restProps }: IProps<VT>): JSX.Element;
|
|
102
|
+
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, transformData, joinKey, joinStr, ...restProps }: IProps<VT>): JSX.Element;
|
|
99
103
|
declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
|
|
100
104
|
export default _default;
|
|
@@ -71,11 +71,14 @@ function getData(request, options) {
|
|
|
71
71
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
72
72
|
*/
|
|
73
73
|
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, 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", "transformData", "joinKey", "joinStr"]);
|
|
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
|
|
81
|
+
var _j = useFetchState(false), firstLoading = _j[0], setFirstLoading = _j[1];
|
|
79
82
|
// 如果selectList 发生改变,那么触发onCompleted事件
|
|
80
83
|
useEffect(function () {
|
|
81
84
|
if (Array.isArray(selectList) && onCompleted) {
|
|
@@ -116,9 +119,9 @@ function EnhanceSelect(_a) {
|
|
|
116
119
|
});
|
|
117
120
|
}, [setSelectList, setLoading, transformData]);
|
|
118
121
|
// 远程搜索
|
|
119
|
-
var getRemoteDataHandle = useCallback(function (value) {
|
|
120
|
-
var _a;
|
|
122
|
+
var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
|
|
121
123
|
var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
|
|
124
|
+
var searchDataKey = remoteSearchDataKey ? remoteSearchDataKey : dataKey;
|
|
122
125
|
var outParams = params;
|
|
123
126
|
try {
|
|
124
127
|
outParams = JSON.parse(params);
|
|
@@ -128,10 +131,17 @@ function EnhanceSelect(_a) {
|
|
|
128
131
|
// 利用闭包,存到当前请求的id
|
|
129
132
|
fetchId.current++;
|
|
130
133
|
var fetchIdClosure = fetchId.current;
|
|
134
|
+
var searchParams = {};
|
|
135
|
+
if (value) {
|
|
136
|
+
searchParams[searchKey] = value;
|
|
137
|
+
}
|
|
138
|
+
if (dataKeyValue) {
|
|
139
|
+
searchParams[searchDataKey] = dataKeyValue + '';
|
|
140
|
+
}
|
|
131
141
|
getData(request, {
|
|
132
142
|
url: url,
|
|
133
143
|
method: method,
|
|
134
|
-
params: __assign(__assign({ size: 50, page: 1 }, outParams),
|
|
144
|
+
params: __assign(__assign({ size: 50, page: 1 }, outParams), searchParams),
|
|
135
145
|
})
|
|
136
146
|
.then(function (resData) {
|
|
137
147
|
var _a, _b, _c;
|
|
@@ -164,7 +174,9 @@ function EnhanceSelect(_a) {
|
|
|
164
174
|
method,
|
|
165
175
|
request,
|
|
166
176
|
remoteSearchKey,
|
|
177
|
+
remoteSearchDataKey,
|
|
167
178
|
titleKey,
|
|
179
|
+
dataKey,
|
|
168
180
|
setSelectList,
|
|
169
181
|
transformData,
|
|
170
182
|
setLoading,
|
|
@@ -172,7 +184,7 @@ function EnhanceSelect(_a) {
|
|
|
172
184
|
var searchHandle = function (value) {
|
|
173
185
|
// 当value有值时才进行搜索
|
|
174
186
|
if (value) {
|
|
175
|
-
getRemoteDataHandle(value);
|
|
187
|
+
getRemoteDataHandle(value, '');
|
|
176
188
|
}
|
|
177
189
|
};
|
|
178
190
|
var onSearchHandle = debounce(searchHandle, 300);
|
|
@@ -230,8 +242,25 @@ function EnhanceSelect(_a) {
|
|
|
230
242
|
return;
|
|
231
243
|
}
|
|
232
244
|
// console.log('TEST: 远程搜索');
|
|
233
|
-
|
|
234
|
-
|
|
245
|
+
if (!firstLoading) {
|
|
246
|
+
if (!restProps.value) {
|
|
247
|
+
getRemoteDataHandle('', '');
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
if (typeof restProps.value === 'string') {
|
|
251
|
+
setFirstLoading(true);
|
|
252
|
+
getRemoteDataHandle('', restProps.value);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, [
|
|
257
|
+
url,
|
|
258
|
+
remoteSearch,
|
|
259
|
+
getRemoteDataHandle,
|
|
260
|
+
restProps.value,
|
|
261
|
+
firstLoading,
|
|
262
|
+
setFirstLoading,
|
|
263
|
+
]);
|
|
235
264
|
// 数据合并
|
|
236
265
|
function concatData(originalData, newData) {
|
|
237
266
|
if (!newData) {
|
|
@@ -243,7 +272,7 @@ function EnhanceSelect(_a) {
|
|
|
243
272
|
// 如果源数组中找到了该条数据,那么不添加
|
|
244
273
|
// 否则添加
|
|
245
274
|
if (!resultData.find(function (resultItem) { return resultItem[dataKey] === item[dataKey]; })) {
|
|
246
|
-
resultData.
|
|
275
|
+
resultData.push(item);
|
|
247
276
|
}
|
|
248
277
|
});
|
|
249
278
|
}
|
|
@@ -255,7 +284,7 @@ function EnhanceSelect(_a) {
|
|
|
255
284
|
return (React.createElement(React.Fragment, null,
|
|
256
285
|
showAll && (React.createElement(Select.Option, { title: "\u5168\u90E8", value: "" }, "\u5168\u90E8")),
|
|
257
286
|
Array.isArray(selectList) &&
|
|
258
|
-
concatData(selectList, _defaultList).map(function (item) {
|
|
287
|
+
concatData(concatData(selectList, _defaultList), multipleList).map(function (item) {
|
|
259
288
|
var key = componentKey ? item[componentKey] : item[dataKey];
|
|
260
289
|
var value = item[dataKey];
|
|
261
290
|
var title = item[titleKey];
|
|
@@ -283,17 +312,20 @@ function EnhanceSelect(_a) {
|
|
|
283
312
|
};
|
|
284
313
|
// onChange 方法
|
|
285
314
|
var onChangeHandle = function (value, option) {
|
|
286
|
-
|
|
315
|
+
var _defaultList = Array.isArray(defaultList) ? defaultList : [];
|
|
316
|
+
var currentList = concatData(concatData(selectList || [], _defaultList), multipleList || []);
|
|
317
|
+
if (currentList && Array.isArray(currentList)) {
|
|
287
318
|
var key_1 = dataKey;
|
|
288
319
|
// 支持多选模式
|
|
289
320
|
var currentData = void 0;
|
|
290
321
|
if (Array.isArray(value)) {
|
|
291
322
|
currentData = value.map(function (valueItem) {
|
|
292
|
-
return
|
|
323
|
+
return currentList.find(function (item) { return item[key_1] === valueItem; });
|
|
293
324
|
});
|
|
325
|
+
setMultipleList(currentData);
|
|
294
326
|
}
|
|
295
327
|
else {
|
|
296
|
-
currentData =
|
|
328
|
+
currentData = currentList.find(function (item) { return item[key_1] === value; });
|
|
297
329
|
}
|
|
298
330
|
onChange && onChange(value, option, currentData);
|
|
299
331
|
}
|