ztxkui 3.8.7 → 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.
|
@@ -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';
|
|
@@ -103,7 +104,9 @@ function textContent(children) {
|
|
|
103
104
|
*/
|
|
104
105
|
function EnhanceSelect(_a) {
|
|
105
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"]);
|
|
106
|
-
|
|
107
|
+
// TODO: 注释动态设置open逻辑 start
|
|
108
|
+
// const currentClick = useRef<boolean>(true);
|
|
109
|
+
// TODO: 注释动态设置open逻辑 end
|
|
107
110
|
// 下拉数据源
|
|
108
111
|
var _k = useFetchState([]), selectList = _k[0], setSelectList = _k[1];
|
|
109
112
|
// 手动添加的数据源
|
|
@@ -124,8 +127,10 @@ function EnhanceSelect(_a) {
|
|
|
124
127
|
var _t = useState(1), currentPage = _t[0], setCurrentPage = _t[1];
|
|
125
128
|
// 总条数
|
|
126
129
|
var _u = useState(0), count = _u[0], setCount = _u[1];
|
|
127
|
-
//
|
|
128
|
-
|
|
130
|
+
// TODO: 注释动态设置open逻辑 start
|
|
131
|
+
// // 手动清空数据
|
|
132
|
+
// const handleClearDataRef = useRef<boolean>(false);
|
|
133
|
+
// TODO: 注释动态设置open逻辑 end
|
|
129
134
|
// 是否自动请求
|
|
130
135
|
var isAutoRequest = useRef(false); // 请求过了
|
|
131
136
|
// 处理value
|
|
@@ -317,10 +322,12 @@ function EnhanceSelect(_a) {
|
|
|
317
322
|
// if (value) {
|
|
318
323
|
console.log(value);
|
|
319
324
|
// setIsOpen(true);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
325
|
+
// TODO: 注释动态设置open逻辑 start
|
|
326
|
+
// if (value || handleClearDataRef.current) {
|
|
327
|
+
// setIsOpen(true);
|
|
328
|
+
// }
|
|
329
|
+
// handleClearDataRef.current = false;
|
|
330
|
+
// TODO: 注释动态设置open逻辑 end
|
|
324
331
|
if (isHandAddItem) {
|
|
325
332
|
if (value) {
|
|
326
333
|
setHandleAddItems([
|
|
@@ -345,10 +352,12 @@ function EnhanceSelect(_a) {
|
|
|
345
352
|
var _a;
|
|
346
353
|
// console.log(value);
|
|
347
354
|
// setIsOpen(true);
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
355
|
+
// TODO: 注释动态设置open逻辑 start
|
|
356
|
+
// if (value || handleClearDataRef.current) {
|
|
357
|
+
// setIsOpen(true);
|
|
358
|
+
// }
|
|
359
|
+
// handleClearDataRef.current = false;
|
|
360
|
+
// TODO: 注释动态设置open逻辑 end
|
|
352
361
|
if (isHandAddItem) {
|
|
353
362
|
if (value) {
|
|
354
363
|
setHandleAddItems([
|
|
@@ -431,6 +440,52 @@ function EnhanceSelect(_a) {
|
|
|
431
440
|
url,
|
|
432
441
|
remoteSearch,
|
|
433
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
|
+
};
|
|
434
489
|
useEffect(function () {
|
|
435
490
|
if (!url || remoteSearch) {
|
|
436
491
|
return;
|
|
@@ -737,12 +792,13 @@ function EnhanceSelect(_a) {
|
|
|
737
792
|
};
|
|
738
793
|
// onChange 方法
|
|
739
794
|
var onChangeHandle = function (value, option) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
else {
|
|
744
|
-
|
|
745
|
-
}
|
|
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
|
|
746
802
|
setFirstLoading(true);
|
|
747
803
|
if (((Array.isArray(value) && value.length === 0) || !value) &&
|
|
748
804
|
remoteSearch &&
|
|
@@ -824,20 +880,26 @@ function EnhanceSelect(_a) {
|
|
|
824
880
|
var onFocusHandle = function (e) {
|
|
825
881
|
console.log('焦点事件');
|
|
826
882
|
setIsOpen(true);
|
|
827
|
-
|
|
883
|
+
// TODO: 注释动态设置open逻辑 start
|
|
884
|
+
// currentClick.current = false;
|
|
885
|
+
// TODO: 注释动态设置open逻辑 end
|
|
828
886
|
onFocus && onFocus(e);
|
|
829
887
|
};
|
|
830
888
|
var onBlurHandle = function (e) {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
889
|
+
// TODO: 注释动态设置open逻辑 start
|
|
890
|
+
// console.log('失去焦点事件');
|
|
891
|
+
// setIsOpen(false);
|
|
892
|
+
// currentClick.current = false;
|
|
893
|
+
// TODO: 注释动态设置open逻辑 end
|
|
834
894
|
onBlur && onBlur(e);
|
|
835
895
|
};
|
|
836
896
|
// 清空数据时
|
|
837
897
|
var onClearHandle = function () {
|
|
838
898
|
// console.log('清空数据事件');
|
|
839
|
-
|
|
840
|
-
|
|
899
|
+
// TODO: 注释动态设置open逻辑 start
|
|
900
|
+
// handleClearDataRef.current = true;
|
|
901
|
+
// setIsOpen(false);
|
|
902
|
+
// TODO: 注释动态设置open逻辑 end
|
|
841
903
|
};
|
|
842
904
|
// 选中时
|
|
843
905
|
var onSelectHandle = function (value, obj) {
|
|
@@ -852,9 +914,11 @@ function EnhanceSelect(_a) {
|
|
|
852
914
|
document === null || document === void 0 ? void 0 : document.execCommand('copy');
|
|
853
915
|
document.body.removeChild(textarea);
|
|
854
916
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
917
|
+
// TODO: 注释动态设置open逻辑 start
|
|
918
|
+
// if (!restProps.mode) {
|
|
919
|
+
// setIsOpen(false);
|
|
920
|
+
// }
|
|
921
|
+
// TODO: 注释动态设置open逻辑 end
|
|
858
922
|
};
|
|
859
923
|
// 点击时
|
|
860
924
|
var onClickHandle = function (e) {
|
|
@@ -865,24 +929,24 @@ function EnhanceSelect(_a) {
|
|
|
865
929
|
sendRemoteRequest();
|
|
866
930
|
sendRemoteRequest1();
|
|
867
931
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
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
|
|
886
950
|
};
|
|
887
951
|
// 滚动加载
|
|
888
952
|
var onPopupScrollHandle = function (e) {
|
|
@@ -899,7 +963,24 @@ function EnhanceSelect(_a) {
|
|
|
899
963
|
};
|
|
900
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,
|
|
901
965
|
// getPopupContainer={(trigger) => trigger || document.body}
|
|
902
|
-
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,
|
|
903
984
|
// 这里需要注释掉,因为修改了一部分逻辑
|
|
904
985
|
disabled: remoteSearch || isClickRequest
|
|
905
986
|
? restProps.disabled
|