ztxkui 3.8.6 → 3.8.8
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 +1 -1
- package/dist/components/EnhanceSelect/index.js +164 -46
- 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.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJtZW1iZXJfdHlwZSI6MSwiaGFuZGxlX2hyX3Bob25lIjpudWxsLCJyZXN1bWVfZGF0ZSI6bnVsbCwidXNlcl9uYW1lIjoi546L5aWVIiwiZW1wX25hbWUiOm51bGwsImVtcF9udW1iZXIiOm51bGwsImltdF9pZCI6bnVsbCwicmVhbF9uYW1lIjoi546L5aWVIiwiY2xpZW50X3R5cGUiOiJ3ZWIiLCJkYXRhX3JvbGVfaWQiOiIxMzQzNDkwNjg2MjYwMjI4MDk3IiwiY2xpZW50X2lkIjoic3dvcmQiLCJ1c2VyX3R5cGUiOiJ3ZWIiLCJyb2xlX2lkIjoiMTEyMzU5ODgxNjczODY3NTIwMSwxMzQzNDkwNDI1MDAxMjI2MjQyIiwicG9zdF9uYW1lIjpudWxsLCJzY29wZSI6WyJhbGwiXSwiaW50ZXJ2aWV3X2lkIjpudWxsLCJleHAiOjE2NjQ4NjgyODcsIm9yZ19uYW1lIjpudWxsLCJqdGkiOiJkMTU3MGYzNy0zY2JiLTQ0ODgtYTEwMy0wYTkyNDVmZjc5Y2IiLCJtZW1iZXJfaWQiOjEsImNvbXBhbnlfaWQiOm51bGwsInN5c3RlbV9pZCI6bnVsbCwiZGVwdF9uYW1lIjpudWxsLCJhdmF0YXIiOiIiLCJkYXRhX3JvbGVfbmFtZSI6Im51bGwiLCJhdXRob3JpdGllcyI6WyLlhoXli6QiLCJhZG1pbmlzdHJhdG9yIl0sInJvbGVfbmFtZSI6ImFkbWluaXN0cmF0b3Is5YaF5YukIiwicmVzdW1lX3RlbXBsYXRlIjpudWxsLCJsaWNlbnNlIjoicG93ZXJlZCBieSB6bWRtcyIsInBvc3RfaWQiOiIiLCJ1c2VyX2lkIjoiMTM0NDA5OTIwNjMyODM1Njg2NSIsIm9yZ19pZCI6bnVsbCwibmlja19uYW1lIjoi546L5aWVIiwiY29tcGFueV9uYW1lIjpudWxsLCJkZXB0X2lkIjoiIiwiaGFuZGxlX2hyX25hbWUiOm51bGwsImFjY291bnQiOiLnjovlpZUiLCJyZXN1bWVfaWQiOm51bGx9.frYQQIw5WQIJIc_Qf6NLmYV5hZ6OVd6TAfxXrjgWFhY',
|
|
10
10
|
},
|
|
11
11
|
method: options.method,
|
|
12
12
|
}).then(function (response) { return response.json(); });
|
|
@@ -30,7 +30,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
|
30
30
|
* @description 增强下拉框功能
|
|
31
31
|
*/
|
|
32
32
|
import React, { useCallback, useEffect, memo, useRef, useState, useMemo, } from 'react';
|
|
33
|
-
import { Select } from 'antd';
|
|
33
|
+
import { Divider, Select } from 'antd';
|
|
34
|
+
import Button from '../Button';
|
|
34
35
|
import { useFetchState } from 'ztxkutils/dist/hooks';
|
|
35
36
|
import debounce from 'lodash/debounce';
|
|
36
37
|
import { dangerouslySetXss } from 'ztxkutils/dist/tools';
|
|
@@ -43,6 +44,8 @@ import { dangerouslySetXss } from 'ztxkutils/dist/tools';
|
|
|
43
44
|
* }
|
|
44
45
|
*/
|
|
45
46
|
var enhanceSelectCatchObj = {};
|
|
47
|
+
var enhanceSelectCatchLruKeys = [];
|
|
48
|
+
var enhanceSelectCatchLruMaxSize = 800;
|
|
46
49
|
// 获取接口数据
|
|
47
50
|
function getData(request, options) {
|
|
48
51
|
var _a;
|
|
@@ -101,7 +104,9 @@ function textContent(children) {
|
|
|
101
104
|
*/
|
|
102
105
|
function EnhanceSelect(_a) {
|
|
103
106
|
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.timeout, timeout = _c === void 0 ? 60000 : _c, _d = _a.dataKey, dataKey = _d === void 0 ? 'id' : _d, componentKey = _a.componentKey, _e = _a.titleKey, titleKey = _e === void 0 ? 'name' : _e, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, onSearch = _a.onSearch, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _f = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _f === void 0 ? true : _f, transformData = _a.transformData, joinKey = _a.joinKey, _g = _a.joinStr, joinStr = _g === void 0 ? '-' : _g, lineFeedKey = _a.lineFeedKey, _h = _a.lineFeedStr, lineFeedStr = _h === void 0 ? '-' : _h, mustHasParams = _a.mustHasParams, disabledValues = _a.disabledValues, searchDeleteKeys = _a.searchDeleteKeys, isHandAddItem = _a.isHandAddItem, isPage = _a.isPage, _j = _a.currentSize, currentSize = _j === void 0 ? 30 : _j, isCopy = _a.isCopy, onBlur = _a.onBlur, onFocus = _a.onFocus, isClickRequest = _a.isClickRequest, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "timeout", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "onSearch", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr", "lineFeedKey", "lineFeedStr", "mustHasParams", "disabledValues", "searchDeleteKeys", "isHandAddItem", "isPage", "currentSize", "isCopy", "onBlur", "onFocus", "isClickRequest"]);
|
|
104
|
-
|
|
107
|
+
// TODO: 注释动态设置open逻辑 start
|
|
108
|
+
// const currentClick = useRef<boolean>(true);
|
|
109
|
+
// TODO: 注释动态设置open逻辑 end
|
|
105
110
|
// 下拉数据源
|
|
106
111
|
var _k = useFetchState([]), selectList = _k[0], setSelectList = _k[1];
|
|
107
112
|
// 手动添加的数据源
|
|
@@ -122,8 +127,10 @@ function EnhanceSelect(_a) {
|
|
|
122
127
|
var _t = useState(1), currentPage = _t[0], setCurrentPage = _t[1];
|
|
123
128
|
// 总条数
|
|
124
129
|
var _u = useState(0), count = _u[0], setCount = _u[1];
|
|
125
|
-
//
|
|
126
|
-
|
|
130
|
+
// TODO: 注释动态设置open逻辑 start
|
|
131
|
+
// // 手动清空数据
|
|
132
|
+
// const handleClearDataRef = useRef<boolean>(false);
|
|
133
|
+
// TODO: 注释动态设置open逻辑 end
|
|
127
134
|
// 是否自动请求
|
|
128
135
|
var isAutoRequest = useRef(false); // 请求过了
|
|
129
136
|
// 处理value
|
|
@@ -315,10 +322,12 @@ function EnhanceSelect(_a) {
|
|
|
315
322
|
// if (value) {
|
|
316
323
|
console.log(value);
|
|
317
324
|
// setIsOpen(true);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
325
|
+
// TODO: 注释动态设置open逻辑 start
|
|
326
|
+
// if (value || handleClearDataRef.current) {
|
|
327
|
+
// setIsOpen(true);
|
|
328
|
+
// }
|
|
329
|
+
// handleClearDataRef.current = false;
|
|
330
|
+
// TODO: 注释动态设置open逻辑 end
|
|
322
331
|
if (isHandAddItem) {
|
|
323
332
|
if (value) {
|
|
324
333
|
setHandleAddItems([
|
|
@@ -343,10 +352,12 @@ function EnhanceSelect(_a) {
|
|
|
343
352
|
var _a;
|
|
344
353
|
// console.log(value);
|
|
345
354
|
// setIsOpen(true);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
// TODO: 注释动态设置open逻辑 start
|
|
356
|
+
// if (value || handleClearDataRef.current) {
|
|
357
|
+
// setIsOpen(true);
|
|
358
|
+
// }
|
|
359
|
+
// handleClearDataRef.current = false;
|
|
360
|
+
// TODO: 注释动态设置open逻辑 end
|
|
350
361
|
if (isHandAddItem) {
|
|
351
362
|
if (value) {
|
|
352
363
|
setHandleAddItems([
|
|
@@ -381,6 +392,23 @@ function EnhanceSelect(_a) {
|
|
|
381
392
|
enhanceSelectCatchObj[url] = enhanceSelectCatchObj[url]
|
|
382
393
|
? enhanceSelectCatchObj[url]
|
|
383
394
|
: {};
|
|
395
|
+
var currentIndex = enhanceSelectCatchLruKeys.indexOf(url);
|
|
396
|
+
if (currentIndex !== -1) {
|
|
397
|
+
enhanceSelectCatchLruKeys.splice(currentIndex, 1);
|
|
398
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
402
|
+
}
|
|
403
|
+
if (enhanceSelectCatchLruKeys.length > enhanceSelectCatchLruMaxSize) {
|
|
404
|
+
var oldKey = enhanceSelectCatchLruKeys.shift();
|
|
405
|
+
try {
|
|
406
|
+
delete enhanceSelectCatchLruKeys[oldKey];
|
|
407
|
+
}
|
|
408
|
+
catch (err) {
|
|
409
|
+
//
|
|
410
|
+
}
|
|
411
|
+
}
|
|
384
412
|
var catchData = enhanceSelectCatchObj[url];
|
|
385
413
|
var catchDataKey = params ? JSON.stringify(params) : 'single';
|
|
386
414
|
if (!catchData[catchDataKey]) {
|
|
@@ -412,6 +440,52 @@ function EnhanceSelect(_a) {
|
|
|
412
440
|
url,
|
|
413
441
|
remoteSearch,
|
|
414
442
|
]);
|
|
443
|
+
var sendRequestNoCatch = function () {
|
|
444
|
+
if (!url || remoteSearch) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (isCatch) {
|
|
448
|
+
if (enhanceSelectCatchObj) {
|
|
449
|
+
enhanceSelectCatchObj[url] = enhanceSelectCatchObj[url]
|
|
450
|
+
? enhanceSelectCatchObj[url]
|
|
451
|
+
: {};
|
|
452
|
+
var currentIndex = enhanceSelectCatchLruKeys.indexOf(url);
|
|
453
|
+
if (currentIndex !== -1) {
|
|
454
|
+
enhanceSelectCatchLruKeys.splice(currentIndex, 1);
|
|
455
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
459
|
+
}
|
|
460
|
+
if (enhanceSelectCatchLruKeys.length > enhanceSelectCatchLruMaxSize) {
|
|
461
|
+
var oldKey = enhanceSelectCatchLruKeys.shift();
|
|
462
|
+
try {
|
|
463
|
+
delete enhanceSelectCatchLruKeys[oldKey];
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
//
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
var catchData = enhanceSelectCatchObj[url];
|
|
470
|
+
var catchDataKey = params ? JSON.stringify(params) : 'single';
|
|
471
|
+
// 发送接口请求,并设置缓存数据
|
|
472
|
+
getDataHandle(request, { url: url, params: params, method: method, timeout: timeout }, {
|
|
473
|
+
appointObj: {
|
|
474
|
+
obj: catchData,
|
|
475
|
+
key: catchDataKey,
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
getDataHandle(request, {
|
|
482
|
+
url: url,
|
|
483
|
+
params: params,
|
|
484
|
+
method: method,
|
|
485
|
+
timeout: timeout,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
415
489
|
useEffect(function () {
|
|
416
490
|
if (!url || remoteSearch) {
|
|
417
491
|
return;
|
|
@@ -423,6 +497,24 @@ function EnhanceSelect(_a) {
|
|
|
423
497
|
enhanceSelectCatchObj[url] = enhanceSelectCatchObj[url]
|
|
424
498
|
? enhanceSelectCatchObj[url]
|
|
425
499
|
: {};
|
|
500
|
+
var currentIndex = enhanceSelectCatchLruKeys.indexOf(url);
|
|
501
|
+
// 当前访问数据置为最新鲜
|
|
502
|
+
if (currentIndex !== -1) {
|
|
503
|
+
enhanceSelectCatchLruKeys.splice(currentIndex, 1);
|
|
504
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
enhanceSelectCatchLruKeys.push(url);
|
|
508
|
+
}
|
|
509
|
+
if (enhanceSelectCatchLruKeys.length > enhanceSelectCatchLruMaxSize) {
|
|
510
|
+
var oldKey = enhanceSelectCatchLruKeys.shift();
|
|
511
|
+
try {
|
|
512
|
+
delete enhanceSelectCatchLruKeys[oldKey];
|
|
513
|
+
}
|
|
514
|
+
catch (err) {
|
|
515
|
+
//
|
|
516
|
+
}
|
|
517
|
+
}
|
|
426
518
|
var catchData = enhanceSelectCatchObj[url];
|
|
427
519
|
var catchDataKey = params ? JSON.stringify(params) : 'single';
|
|
428
520
|
if (catchData[catchDataKey]) {
|
|
@@ -700,12 +792,13 @@ function EnhanceSelect(_a) {
|
|
|
700
792
|
};
|
|
701
793
|
// onChange 方法
|
|
702
794
|
var onChangeHandle = function (value, option) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
else {
|
|
707
|
-
|
|
708
|
-
}
|
|
795
|
+
// TODO: 注释动态设置open逻辑 start
|
|
796
|
+
// if ((Array.isArray(value) && value.length === 0) || !value) {
|
|
797
|
+
// currentClick.current = true;
|
|
798
|
+
// } else {
|
|
799
|
+
// currentClick.current = false;
|
|
800
|
+
// }
|
|
801
|
+
// TODO: 注释动态设置open逻辑 end
|
|
709
802
|
setFirstLoading(true);
|
|
710
803
|
if (((Array.isArray(value) && value.length === 0) || !value) &&
|
|
711
804
|
remoteSearch &&
|
|
@@ -787,20 +880,26 @@ function EnhanceSelect(_a) {
|
|
|
787
880
|
var onFocusHandle = function (e) {
|
|
788
881
|
console.log('焦点事件');
|
|
789
882
|
setIsOpen(true);
|
|
790
|
-
|
|
883
|
+
// TODO: 注释动态设置open逻辑 start
|
|
884
|
+
// currentClick.current = false;
|
|
885
|
+
// TODO: 注释动态设置open逻辑 end
|
|
791
886
|
onFocus && onFocus(e);
|
|
792
887
|
};
|
|
793
888
|
var onBlurHandle = function (e) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
889
|
+
// TODO: 注释动态设置open逻辑 start
|
|
890
|
+
// console.log('失去焦点事件');
|
|
891
|
+
// setIsOpen(false);
|
|
892
|
+
// currentClick.current = false;
|
|
893
|
+
// TODO: 注释动态设置open逻辑 end
|
|
797
894
|
onBlur && onBlur(e);
|
|
798
895
|
};
|
|
799
896
|
// 清空数据时
|
|
800
897
|
var onClearHandle = function () {
|
|
801
898
|
// console.log('清空数据事件');
|
|
802
|
-
|
|
803
|
-
|
|
899
|
+
// TODO: 注释动态设置open逻辑 start
|
|
900
|
+
// handleClearDataRef.current = true;
|
|
901
|
+
// setIsOpen(false);
|
|
902
|
+
// TODO: 注释动态设置open逻辑 end
|
|
804
903
|
};
|
|
805
904
|
// 选中时
|
|
806
905
|
var onSelectHandle = function (value, obj) {
|
|
@@ -815,9 +914,11 @@ function EnhanceSelect(_a) {
|
|
|
815
914
|
document === null || document === void 0 ? void 0 : document.execCommand('copy');
|
|
816
915
|
document.body.removeChild(textarea);
|
|
817
916
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
917
|
+
// TODO: 注释动态设置open逻辑 start
|
|
918
|
+
// if (!restProps.mode) {
|
|
919
|
+
// setIsOpen(false);
|
|
920
|
+
// }
|
|
921
|
+
// TODO: 注释动态设置open逻辑 end
|
|
821
922
|
};
|
|
822
923
|
// 点击时
|
|
823
924
|
var onClickHandle = function (e) {
|
|
@@ -828,24 +929,24 @@ function EnhanceSelect(_a) {
|
|
|
828
929
|
sendRemoteRequest();
|
|
829
930
|
sendRemoteRequest1();
|
|
830
931
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
932
|
+
// TODO: 注释动态设置open逻辑 start
|
|
933
|
+
// if (currentClick.current) {
|
|
934
|
+
// console.log(e.nativeEvent.target.getAttribute('class'));
|
|
935
|
+
// let className = '';
|
|
936
|
+
// try {
|
|
937
|
+
// className = e.nativeEvent.target.getAttribute('class');
|
|
938
|
+
// } catch (err) {
|
|
939
|
+
// console.log(err);
|
|
940
|
+
// }
|
|
941
|
+
// const bool = className.indexOf('rc-virtual-list') === -1;
|
|
942
|
+
// if (isOpen && bool) {
|
|
943
|
+
// setIsOpen(false);
|
|
944
|
+
// } else {
|
|
945
|
+
// setIsOpen(true);
|
|
946
|
+
// }
|
|
947
|
+
// }
|
|
948
|
+
// currentClick.current = true;
|
|
949
|
+
// TODO: 注释动态设置open逻辑 end
|
|
849
950
|
};
|
|
850
951
|
// 滚动加载
|
|
851
952
|
var onPopupScrollHandle = function (e) {
|
|
@@ -862,7 +963,24 @@ function EnhanceSelect(_a) {
|
|
|
862
963
|
};
|
|
863
964
|
return (React.createElement(Select, __assign({ defaultValue: showAll ? '' : undefined, allowClear: true, showSearch: true, filterOption: remoteSearch ? false : filterOptionHandle, onSearch: remoteSearch ? onSearchHandle : onSearchHandleInner, onChange: onChangeHandle, optionLabelProp: "title", loading: loading, onFocus: onFocusHandle, onBlur: onBlurHandle, onClear: onClearHandle, onSelect: onSelectHandle, onClick: onClickHandle,
|
|
864
965
|
// getPopupContainer={(trigger) => trigger || document.body}
|
|
865
|
-
open: isOpen,
|
|
966
|
+
open: isOpen, onDropdownVisibleChange: function (visible) { return setIsOpen(visible); }, onPopupScroll: onPopupScrollHandle, dropdownRender: url && !remoteSearch && isCatch
|
|
967
|
+
? function (menu) { return (React.createElement(React.Fragment, null,
|
|
968
|
+
menu,
|
|
969
|
+
React.createElement(Divider, { style: { marginTop: 0, marginBottom: '4px' } }),
|
|
970
|
+
React.createElement("div", { style: {
|
|
971
|
+
display: 'flex',
|
|
972
|
+
alignItems: 'center',
|
|
973
|
+
flexDirection: 'row',
|
|
974
|
+
justifyContent: 'space-between',
|
|
975
|
+
padding: '0 6px',
|
|
976
|
+
} },
|
|
977
|
+
React.createElement("span", null),
|
|
978
|
+
React.createElement(Button, { onClick: function (e) {
|
|
979
|
+
console.log(e);
|
|
980
|
+
e.preventDefault();
|
|
981
|
+
sendRequestNoCatch();
|
|
982
|
+
} }, "\u5237\u65B0\u6570\u636E")))); }
|
|
983
|
+
: undefined }, restProps, { value: newValue,
|
|
866
984
|
// 这里需要注释掉,因为修改了一部分逻辑
|
|
867
985
|
disabled: remoteSearch || isClickRequest
|
|
868
986
|
? restProps.disabled
|