ztxkui 1.9.9 → 2.0.3
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(); });
|
|
@@ -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;
|
|
@@ -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,12 +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
|
|
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) {
|
|
@@ -119,7 +121,7 @@ function EnhanceSelect(_a) {
|
|
|
119
121
|
// 远程搜索
|
|
120
122
|
var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
|
|
121
123
|
var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
|
|
122
|
-
var searchDataKey = dataKey;
|
|
124
|
+
var searchDataKey = remoteSearchDataKey ? remoteSearchDataKey : dataKey;
|
|
123
125
|
var outParams = params;
|
|
124
126
|
try {
|
|
125
127
|
outParams = JSON.parse(params);
|
|
@@ -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,
|
|
@@ -172,6 +174,7 @@ function EnhanceSelect(_a) {
|
|
|
172
174
|
method,
|
|
173
175
|
request,
|
|
174
176
|
remoteSearchKey,
|
|
177
|
+
remoteSearchDataKey,
|
|
175
178
|
titleKey,
|
|
176
179
|
dataKey,
|
|
177
180
|
setSelectList,
|
|
@@ -268,8 +271,10 @@ function EnhanceSelect(_a) {
|
|
|
268
271
|
newData.forEach(function (item) {
|
|
269
272
|
// 如果源数组中找到了该条数据,那么不添加
|
|
270
273
|
// 否则添加
|
|
271
|
-
if (!resultData.find(function (resultItem) {
|
|
272
|
-
|
|
274
|
+
if (!resultData.find(function (resultItem) {
|
|
275
|
+
return resultItem && item && resultItem[dataKey] === item[dataKey];
|
|
276
|
+
})) {
|
|
277
|
+
resultData.push(item);
|
|
273
278
|
}
|
|
274
279
|
});
|
|
275
280
|
}
|
|
@@ -281,7 +286,7 @@ function EnhanceSelect(_a) {
|
|
|
281
286
|
return (React.createElement(React.Fragment, null,
|
|
282
287
|
showAll && (React.createElement(Select.Option, { title: "\u5168\u90E8", value: "" }, "\u5168\u90E8")),
|
|
283
288
|
Array.isArray(selectList) &&
|
|
284
|
-
concatData(selectList, _defaultList).map(function (item) {
|
|
289
|
+
concatData(concatData(selectList, _defaultList), multipleList).map(function (item) {
|
|
285
290
|
var key = componentKey ? item[componentKey] : item[dataKey];
|
|
286
291
|
var value = item[dataKey];
|
|
287
292
|
var title = item[titleKey];
|
|
@@ -309,17 +314,23 @@ function EnhanceSelect(_a) {
|
|
|
309
314
|
};
|
|
310
315
|
// onChange 方法
|
|
311
316
|
var onChangeHandle = function (value, option) {
|
|
312
|
-
|
|
317
|
+
var _defaultList = Array.isArray(defaultList) ? defaultList : [];
|
|
318
|
+
var currentList = concatData(concatData(selectList || [], _defaultList), multipleList || []);
|
|
319
|
+
if (currentList && Array.isArray(currentList)) {
|
|
313
320
|
var key_1 = dataKey;
|
|
314
321
|
// 支持多选模式
|
|
315
322
|
var currentData = void 0;
|
|
316
323
|
if (Array.isArray(value)) {
|
|
317
324
|
currentData = value.map(function (valueItem) {
|
|
318
|
-
return
|
|
325
|
+
return currentList.find(function (item) { return item[key_1] === valueItem; });
|
|
319
326
|
});
|
|
327
|
+
currentData = currentData === null || currentData === void 0 ? void 0 : currentData.filter(function (item) { return item; });
|
|
328
|
+
if (remoteSearch) {
|
|
329
|
+
setMultipleList(currentData);
|
|
330
|
+
}
|
|
320
331
|
}
|
|
321
332
|
else {
|
|
322
|
-
currentData =
|
|
333
|
+
currentData = currentList.find(function (item) { return item[key_1] === value; });
|
|
323
334
|
}
|
|
324
335
|
onChange && onChange(value, option, currentData);
|
|
325
336
|
}
|