@kne/super-select 0.1.49 → 0.1.50
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/README.md +68 -16
- package/dist/index.js +155 -60
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +253 -158
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
React 复杂信息选择组件库,提供列表、表格、树形等多种选择模式,支持单选/多选、搜索、全选等功能
|
|
6
6
|
|
|
7
|
+
### 关键词
|
|
8
|
+
|
|
9
|
+
react, select, picker, multiselect, tree-select, table-select, antd, form, dropdown, searchable, i18n
|
|
10
|
+
|
|
7
11
|
### 安装
|
|
8
12
|
|
|
9
13
|
```shell
|
|
@@ -739,34 +743,40 @@ const SearchableTableExample = ({ isPopup }) => {
|
|
|
739
743
|
|
|
740
744
|
const remoteSearchListFilter = { language: 'zh-CN' };
|
|
741
745
|
|
|
742
|
-
//
|
|
746
|
+
// 模拟分页 loader:根据 currentPage/perPage 切片,保留 filter
|
|
747
|
+
const makePaginatedLoader = (allData, setLastRequest) => request => {
|
|
748
|
+
const params = request?.params || {};
|
|
749
|
+
const snapshot = { params, data: request?.data || {} };
|
|
750
|
+
setTimeout(() => setLastRequest(snapshot), 0);
|
|
751
|
+
const keyword = (params.filter?.keyword || '').toLowerCase();
|
|
752
|
+
const filtered = allData.filter(item => {
|
|
753
|
+
if (!keyword) return true;
|
|
754
|
+
return item.name.toLowerCase().includes(keyword) || item.email.toLowerCase().includes(keyword) || item.department.toLowerCase().includes(keyword);
|
|
755
|
+
});
|
|
756
|
+
const currentPage = params.currentPage || 1;
|
|
757
|
+
const perPage = params.perPage || 5;
|
|
758
|
+
const start = (currentPage - 1) * perPage;
|
|
759
|
+
const pageData = filtered.slice(start, start + perPage);
|
|
760
|
+
return { pageData, totalCount: filtered.length };
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
// 远程搜索 + 分页器(默认 pagination.open=true)
|
|
743
764
|
const RemoteSearchTableExample = ({ isPopup }) => {
|
|
744
765
|
const [value, setValue] = useState([]);
|
|
745
766
|
const [lastRequest, setLastRequest] = useState(null);
|
|
746
767
|
const api = React.useMemo(
|
|
747
768
|
() => ({
|
|
748
|
-
params: { filter: remoteSearchListFilter },
|
|
749
|
-
loader:
|
|
750
|
-
const snapshot = { params: request?.params || {}, data: request?.data || {} };
|
|
751
|
-
setTimeout(() => setLastRequest(snapshot), 0);
|
|
752
|
-
const keyword = (snapshot.params.filter?.keyword || '').toLowerCase();
|
|
753
|
-
const pageData = employeeOptions.filter(item => {
|
|
754
|
-
if (!keyword) {
|
|
755
|
-
return true;
|
|
756
|
-
}
|
|
757
|
-
return item.name.toLowerCase().includes(keyword) || item.email.toLowerCase().includes(keyword) || item.department.toLowerCase().includes(keyword);
|
|
758
|
-
});
|
|
759
|
-
return { pageData, totalCount: pageData.length };
|
|
760
|
-
}
|
|
769
|
+
params: { filter: remoteSearchListFilter, perPage: 5, currentPage: 1 },
|
|
770
|
+
loader: makePaginatedLoader(employeeOptions, setLastRequest)
|
|
761
771
|
}),
|
|
762
772
|
[]
|
|
763
773
|
);
|
|
764
774
|
|
|
765
775
|
return (
|
|
766
776
|
<Flex vertical gap={8}>
|
|
767
|
-
<span
|
|
777
|
+
<span>远程搜索 + 分页器(验证翻页 filter 不丢):</span>
|
|
768
778
|
<div style={{ color: '#666', fontSize: 12, lineHeight: 1.6 }}>
|
|
769
|
-
|
|
779
|
+
每页 5 条,共 25 条。翻页后观察下方请求参数:params.filter.language 应始终为 zh-CN;搜索后翻页 keyword 也不丢。
|
|
770
780
|
</div>
|
|
771
781
|
<SelectTableList
|
|
772
782
|
api={api}
|
|
@@ -790,6 +800,46 @@ const RemoteSearchTableExample = ({ isPopup }) => {
|
|
|
790
800
|
);
|
|
791
801
|
};
|
|
792
802
|
|
|
803
|
+
// 远程搜索 + 下拉加载(pagination.open=false)
|
|
804
|
+
const RemoteSearchLoadMoreExample = ({ isPopup }) => {
|
|
805
|
+
const [value, setValue] = useState([]);
|
|
806
|
+
const [lastRequest, setLastRequest] = useState(null);
|
|
807
|
+
const api = React.useMemo(
|
|
808
|
+
() => ({
|
|
809
|
+
params: { filter: remoteSearchListFilter, perPage: 5, currentPage: 1 },
|
|
810
|
+
loader: makePaginatedLoader(employeeOptions, setLastRequest)
|
|
811
|
+
}),
|
|
812
|
+
[]
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
return (
|
|
816
|
+
<Flex vertical gap={8}>
|
|
817
|
+
<span>远程搜索 + 下拉加载(验证 open=false 自动 loadMore):</span>
|
|
818
|
+
<div style={{ color: '#666', fontSize: 12, lineHeight: 1.6 }}>
|
|
819
|
+
每页 5 条,无分页器。滚动到底部自动加载下一页,数据追加显示。翻页时 filter.language 不丢。
|
|
820
|
+
</div>
|
|
821
|
+
<SelectTableList
|
|
822
|
+
api={api}
|
|
823
|
+
columns={employeeColumns}
|
|
824
|
+
valueKey="id"
|
|
825
|
+
labelKey="name"
|
|
826
|
+
value={value}
|
|
827
|
+
onChange={setValue}
|
|
828
|
+
isPopup={isPopup}
|
|
829
|
+
placeholder="搜索姓名、邮箱或部门"
|
|
830
|
+
getSearchProps={({ searchText }) => ({
|
|
831
|
+
filter: Object.assign({}, remoteSearchListFilter, searchText ? { keyword: searchText } : {})
|
|
832
|
+
})}
|
|
833
|
+
pagination={{ open: false, paramsType: 'params' }}
|
|
834
|
+
style={{ width: 600 }}
|
|
835
|
+
/>
|
|
836
|
+
{lastRequest ? (
|
|
837
|
+
<pre style={{ margin: 0, fontSize: 12, background: '#f5f5f5', padding: 8, borderRadius: 4, overflow: 'auto' }}>{JSON.stringify(lastRequest, null, 2)}</pre>
|
|
838
|
+
) : null}
|
|
839
|
+
</Flex>
|
|
840
|
+
);
|
|
841
|
+
};
|
|
842
|
+
|
|
793
843
|
// 全选功能
|
|
794
844
|
const SelectAllTableExample = ({ isPopup }) => {
|
|
795
845
|
const [value, setValue] = useState([]);
|
|
@@ -1322,6 +1372,8 @@ const BaseExample = () => {
|
|
|
1322
1372
|
<Divider />
|
|
1323
1373
|
<RemoteSearchTableExample isPopup={isPopup} />
|
|
1324
1374
|
<Divider />
|
|
1375
|
+
<RemoteSearchLoadMoreExample isPopup={isPopup} />
|
|
1376
|
+
<Divider />
|
|
1325
1377
|
<SelectAllTableExample isPopup={isPopup} />
|
|
1326
1378
|
<Divider />
|
|
1327
1379
|
<WideTableExample isPopup={isPopup} />
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var React
|
|
1
|
+
var React = require('react');
|
|
2
2
|
var reactDom = require('react-dom');
|
|
3
3
|
var globalContext = require('@kne/global-context');
|
|
4
4
|
var useResize = require('@kne/use-resize');
|
|
@@ -29,7 +29,7 @@ var isNil = require('lodash/isNil');
|
|
|
29
29
|
|
|
30
30
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
31
31
|
|
|
32
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React
|
|
32
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
33
33
|
var useResize__default = /*#__PURE__*/_interopDefaultLegacy(useResize);
|
|
34
34
|
var useControlValue__default = /*#__PURE__*/_interopDefaultLegacy(useControlValue);
|
|
35
35
|
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
@@ -103,7 +103,7 @@ const TagOverflowInner = ({
|
|
|
103
103
|
const list = Array.isArray(value) ? value : [];
|
|
104
104
|
const availableWidth = Math.max((innerWidth || 0) - iconSpace, 0);
|
|
105
105
|
const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
|
|
106
|
-
const shareItems = React
|
|
106
|
+
const shareItems = React.useMemo(() => list.map(item => ({
|
|
107
107
|
key: item?.[valueKey],
|
|
108
108
|
label: item?.[labelKey]
|
|
109
109
|
})), [list, labelKey, valueKey]);
|
|
@@ -238,7 +238,7 @@ const lockParentScroll = getScrollElements => {
|
|
|
238
238
|
};
|
|
239
239
|
};
|
|
240
240
|
const useLockParentScroll = (enabled, getScrollElements) => {
|
|
241
|
-
React
|
|
241
|
+
React.useEffect(() => {
|
|
242
242
|
if (!enabled) {
|
|
243
243
|
return undefined;
|
|
244
244
|
}
|
|
@@ -270,8 +270,8 @@ const ModalContent = _ref2 => {
|
|
|
270
270
|
open,
|
|
271
271
|
value: propsValue
|
|
272
272
|
} = others;
|
|
273
|
-
const [value, setValue] = React
|
|
274
|
-
React
|
|
273
|
+
const [value, setValue] = React.useState(propsValue);
|
|
274
|
+
React.useEffect(() => {
|
|
275
275
|
if (open && !isEqual__default["default"](value, propsValue)) {
|
|
276
276
|
setValue(propsValue);
|
|
277
277
|
}
|
|
@@ -302,9 +302,9 @@ const MobileSheetMask = _ref3 => {
|
|
|
302
302
|
fixedModeClass,
|
|
303
303
|
onClose
|
|
304
304
|
} = _ref3;
|
|
305
|
-
const [renderMask, setRenderMask] = React
|
|
306
|
-
const [maskClosing, setMaskClosing] = React
|
|
307
|
-
React
|
|
305
|
+
const [renderMask, setRenderMask] = React.useState(false);
|
|
306
|
+
const [maskClosing, setMaskClosing] = React.useState(false);
|
|
307
|
+
React.useEffect(() => {
|
|
308
308
|
if (open) {
|
|
309
309
|
setRenderMask(true);
|
|
310
310
|
setMaskClosing(false);
|
|
@@ -407,7 +407,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
407
407
|
'zh-CN': locale$1,
|
|
408
408
|
'en-US': locale
|
|
409
409
|
}
|
|
410
|
-
})(React
|
|
410
|
+
})(React.forwardRef((p, ref) => {
|
|
411
411
|
const intl = reactIntl.useIntl();
|
|
412
412
|
const {
|
|
413
413
|
formatMessage
|
|
@@ -541,7 +541,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
541
541
|
} = props;
|
|
542
542
|
const getPopupContainerDefault = responsiveUtils.usePopupContainer();
|
|
543
543
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
544
|
-
const wrapCustomGetPopupContainer = React
|
|
544
|
+
const wrapCustomGetPopupContainer = React.useMemo(() => {
|
|
545
545
|
if (typeof getPopupContainerProp === 'function') {
|
|
546
546
|
return triggerNode => getPopupContainerProp(triggerNode) || null;
|
|
547
547
|
}
|
|
@@ -577,16 +577,16 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
577
577
|
} : {
|
|
578
578
|
defaultValue: transformValue(props.defaultValue)
|
|
579
579
|
}));
|
|
580
|
-
const [searchProps, setSearchProps] = React
|
|
580
|
+
const [searchProps, setSearchProps] = React.useState({});
|
|
581
581
|
const [open, setOpen] = useControlValue__default["default"](props, {
|
|
582
582
|
defaultValue: 'defaultOpen',
|
|
583
583
|
value: 'open',
|
|
584
584
|
onChange: 'onOpenChange'
|
|
585
585
|
});
|
|
586
|
-
const [hover, setHover] = React
|
|
587
|
-
const [innerWidth, setInnerWidth] = React
|
|
588
|
-
const [containerWidth, setContainerWidth] = React
|
|
589
|
-
const [popupMountNode, setPopupMountNode] = React
|
|
586
|
+
const [hover, setHover] = React.useState(false);
|
|
587
|
+
const [innerWidth, setInnerWidth] = React.useState(0);
|
|
588
|
+
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
589
|
+
const [popupMountNode, setPopupMountNode] = React.useState(null);
|
|
590
590
|
const containerWidthChange = el => {
|
|
591
591
|
if (!el) {
|
|
592
592
|
return;
|
|
@@ -596,13 +596,13 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
596
596
|
const innerEl = el.querySelector('.select-input-inner');
|
|
597
597
|
setInnerWidth(innerEl.clientWidth);
|
|
598
598
|
};
|
|
599
|
-
const popupOverlayWidth = React
|
|
599
|
+
const popupOverlayWidth = React.useMemo(() => {
|
|
600
600
|
const configured = overlayWidth != null && overlayWidth !== '' ? pxToNumber(overlayWidth) : DEFAULT_OVERLAY_MIN_WIDTH;
|
|
601
601
|
return numberToPx$1(Math.max(containerWidth || 0, configured));
|
|
602
602
|
}, [containerWidth, overlayWidth]);
|
|
603
603
|
|
|
604
604
|
// 同步给 Dropdown 外层 minWidth,避免 antd 按窄触发器裁剪面板
|
|
605
|
-
const mergedOverlayStyle = React
|
|
605
|
+
const mergedOverlayStyle = React.useMemo(() => {
|
|
606
606
|
return Object.assign({}, overlayStyle, zIndex != null ? {
|
|
607
607
|
zIndex
|
|
608
608
|
} : null, {
|
|
@@ -611,11 +611,11 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
611
611
|
});
|
|
612
612
|
}, [overlayStyle, zIndex, popupOverlayWidth]);
|
|
613
613
|
const resizeRef = useResize__default["default"](containerWidthChange);
|
|
614
|
-
const setContainerRef = React
|
|
614
|
+
const setContainerRef = React.useCallback(node => {
|
|
615
615
|
resizeRef.current = node;
|
|
616
616
|
anchorRef(node);
|
|
617
617
|
}, [anchorRef, resizeRef]);
|
|
618
|
-
const resolveGetPopupContainer = React
|
|
618
|
+
const resolveGetPopupContainer = React.useCallback(triggerNode => {
|
|
619
619
|
if (typeof getPopupContainerProp === 'function') {
|
|
620
620
|
const customContainer = getPopupContainerProp(triggerNode);
|
|
621
621
|
if (customContainer) {
|
|
@@ -631,14 +631,14 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
631
631
|
}, [getPopupContainerDefault, getPopupContainerProp, getSheetPopupContainer, useMobileSheet]);
|
|
632
632
|
|
|
633
633
|
// 打开时再取挂载节点,避免落到错误容器
|
|
634
|
-
React
|
|
634
|
+
React.useLayoutEffect(() => {
|
|
635
635
|
if (!useMobileSheet) {
|
|
636
636
|
setPopupMountNode(null);
|
|
637
637
|
return;
|
|
638
638
|
}
|
|
639
639
|
setPopupMountNode(resolveGetPopupContainer(resizeRef.current) || (typeof document !== 'undefined' ? document.body : null));
|
|
640
640
|
}, [useMobileSheet, resolveGetPopupContainer, open, resizeRef]);
|
|
641
|
-
const getLockScrollTargets = React
|
|
641
|
+
const getLockScrollTargets = React.useCallback(() => {
|
|
642
642
|
const targets = [];
|
|
643
643
|
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
644
644
|
if (scrollEl) {
|
|
@@ -704,12 +704,12 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
704
704
|
return newValue;
|
|
705
705
|
});
|
|
706
706
|
};
|
|
707
|
-
const handleOpenChange = React
|
|
707
|
+
const handleOpenChange = React.useCallback(nextOpen => {
|
|
708
708
|
setOpen(nextOpen);
|
|
709
709
|
}, [setOpen]);
|
|
710
710
|
|
|
711
711
|
// 关闭时清空搜索,保证下次展开重新请求且从初始搜索态开始
|
|
712
|
-
React
|
|
712
|
+
React.useEffect(() => {
|
|
713
713
|
if (!open) {
|
|
714
714
|
setSearchProps({});
|
|
715
715
|
}
|
|
@@ -795,7 +795,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
795
795
|
}, current);
|
|
796
796
|
})());
|
|
797
797
|
};
|
|
798
|
-
React
|
|
798
|
+
React.useImperativeHandle(ref, () => {
|
|
799
799
|
return contextProps;
|
|
800
800
|
});
|
|
801
801
|
|
|
@@ -980,12 +980,12 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
980
980
|
|
|
981
981
|
var style$3 = {"kne-responsive-boundary":"kne-super-select_Nc-y4","kne-responsive-scroll":"kne-super-select_RlrDm","list":"kne-super-select_IsXdU","empty":"kne-super-select_SQZ8k","default-list":"kne-super-select_QD1Mz","is-selected-all":"kne-super-select_M-mOy","default-list-item":"kne-super-select_KtOsz","is-selected":"kne-super-select_TQhBB","single-checked":"kne-super-select_2rUrh","is-disabled":"kne-super-select_NbwX5","selected-all":"kne-super-select_vN2Fx","selected-tag":"kne-super-select_6oITk","select-search":"kne-super-select_iAH9D","select-list-item-description":"kne-super-select_TCkeJ","footer":"kne-super-select_v3f23","is-mobile":"kne-super-select_w-WB8"};
|
|
982
982
|
|
|
983
|
-
const SelectList = React
|
|
983
|
+
const SelectList = React.forwardRef((_ref, ref) => {
|
|
984
984
|
let {
|
|
985
985
|
children,
|
|
986
986
|
...p
|
|
987
987
|
} = _ref;
|
|
988
|
-
const fetchListRef = React
|
|
988
|
+
const fetchListRef = React.useRef(null);
|
|
989
989
|
const props = Object.assign({}, {
|
|
990
990
|
renderItemContent: _ref2 => {
|
|
991
991
|
let {
|
|
@@ -1214,7 +1214,7 @@ const FetchTableContent = ({
|
|
|
1214
1214
|
...tableProps
|
|
1215
1215
|
}) => {
|
|
1216
1216
|
const paginationMerged = Object.assign({
|
|
1217
|
-
open:
|
|
1217
|
+
open: true,
|
|
1218
1218
|
paramsType: 'data',
|
|
1219
1219
|
requestType: 'reload',
|
|
1220
1220
|
currentName: 'currentPage',
|
|
@@ -1230,16 +1230,101 @@ const FetchTableContent = ({
|
|
|
1230
1230
|
requestParams,
|
|
1231
1231
|
fetchProps
|
|
1232
1232
|
});
|
|
1233
|
-
const showPagination = paginationMerged.open && formatData.total > 0;
|
|
1234
1233
|
const currentPage = get__default["default"](requestParams, [paginationMerged.paramsType, paginationMerged.currentName], 1);
|
|
1235
1234
|
const currentPageSize = Number(get__default["default"](requestParams, [paginationMerged.paramsType, paginationMerged.pageSizeName], paginationMerged.pageSize)) || paginationMerged.pageSize || 20;
|
|
1236
|
-
|
|
1237
|
-
|
|
1235
|
+
const hasMore = formatData.total > currentPage * currentPageSize;
|
|
1236
|
+
const showPagination = paginationMerged.open && formatData.total > 0;
|
|
1237
|
+
const isLoadMoreMode = !paginationMerged.open;
|
|
1238
|
+
const [accumulatedList, setAccumulatedList] = React.useState([]);
|
|
1239
|
+
const [isLoadingMore, setIsLoadingMore] = React.useState(false);
|
|
1240
|
+
const isLoadingMoreRef = React.useRef(false);
|
|
1241
|
+
const prevDataRef = React.useRef(null);
|
|
1242
|
+
const containerRef = React.useRef(null);
|
|
1243
|
+
React.useEffect(() => {
|
|
1244
|
+
if (!isLoadMoreMode) return;
|
|
1245
|
+
if (data === prevDataRef.current) return;
|
|
1246
|
+
prevDataRef.current = data;
|
|
1247
|
+
const newList = formatData.list || [];
|
|
1248
|
+
if (currentPage <= 1) {
|
|
1249
|
+
setAccumulatedList(newList);
|
|
1250
|
+
} else {
|
|
1251
|
+
setAccumulatedList(prev => prev.concat(newList));
|
|
1252
|
+
}
|
|
1253
|
+
setIsLoadingMore(false);
|
|
1254
|
+
isLoadingMoreRef.current = false;
|
|
1255
|
+
}, [data, isLoadMoreMode, currentPage, formatData.list]);
|
|
1256
|
+
const doLoadNextPage = React.useCallback(() => {
|
|
1257
|
+
if (isLoadingMoreRef.current || !hasMore || !isLoadMoreMode) return;
|
|
1258
|
+
isLoadingMoreRef.current = true;
|
|
1259
|
+
setIsLoadingMore(true);
|
|
1260
|
+
const nextPage = currentPage + 1;
|
|
1261
|
+
const currentParams = get__default["default"](requestParams, paginationMerged.paramsType, {});
|
|
1262
|
+
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1263
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1264
|
+
[paginationMerged.currentName]: nextPage,
|
|
1265
|
+
[paginationMerged.pageSizeName]: currentPageSize
|
|
1266
|
+
})
|
|
1267
|
+
});
|
|
1268
|
+
}, [hasMore, isLoadMoreMode, currentPage, requestParams, paginationMerged, refresh, reload, currentPageSize]);
|
|
1269
|
+
React.useEffect(() => {
|
|
1270
|
+
if (!isLoadMoreMode) return;
|
|
1271
|
+
const container = containerRef.current;
|
|
1272
|
+
if (!container) return;
|
|
1273
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1274
|
+
if (!scrollEl) return;
|
|
1275
|
+
const onScroll = () => {
|
|
1276
|
+
const {
|
|
1277
|
+
scrollTop,
|
|
1278
|
+
scrollHeight,
|
|
1279
|
+
clientHeight
|
|
1280
|
+
} = scrollEl;
|
|
1281
|
+
if (scrollHeight - scrollTop - clientHeight < 50) {
|
|
1282
|
+
doLoadNextPage();
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
scrollEl.addEventListener('scroll', onScroll, {
|
|
1286
|
+
passive: true
|
|
1287
|
+
});
|
|
1288
|
+
return () => scrollEl.removeEventListener('scroll', onScroll);
|
|
1289
|
+
}, [isLoadMoreMode, doLoadNextPage]);
|
|
1290
|
+
|
|
1291
|
+
// 如果当前列表高度没有超过容器(弹窗模式可能不出现滚动条),
|
|
1292
|
+
// 仅靠 scroll 事件无法触发 loadMore:自动补页直到出现溢出或没有更多。
|
|
1293
|
+
const autoLoadCountRef = React.useRef(0);
|
|
1294
|
+
React.useEffect(() => {
|
|
1295
|
+
if (!isLoadMoreMode) return;
|
|
1296
|
+
if (isLoadingMoreRef.current) return;
|
|
1297
|
+
if (!hasMore) return;
|
|
1298
|
+
const container = containerRef.current;
|
|
1299
|
+
if (!container) return;
|
|
1300
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1301
|
+
if (!scrollEl) return;
|
|
1302
|
+
const isOverflowing = scrollEl.scrollHeight > scrollEl.clientHeight + 1;
|
|
1303
|
+
if (isOverflowing) {
|
|
1304
|
+
autoLoadCountRef.current = 0;
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (autoLoadCountRef.current >= 5) return;
|
|
1308
|
+
autoLoadCountRef.current += 1;
|
|
1309
|
+
setTimeout(() => doLoadNextPage(), 0);
|
|
1310
|
+
}, [isLoadMoreMode, hasMore, data, currentPage, currentPageSize, doLoadNextPage]);
|
|
1311
|
+
const displayList = isLoadMoreMode ? accumulatedList : formatData.list || [];
|
|
1312
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1313
|
+
ref: containerRef
|
|
1314
|
+
}, /*#__PURE__*/React__default["default"].createElement(tableView.Table, _extends({}, tableProps, {
|
|
1315
|
+
dataSource: displayList,
|
|
1238
1316
|
pagination: false,
|
|
1239
1317
|
columns: columns,
|
|
1240
1318
|
context: tableContext,
|
|
1241
1319
|
columnRenderProps: tableContext
|
|
1242
|
-
})), showPagination ? /*#__PURE__*/
|
|
1320
|
+
})), showPagination ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1321
|
+
style: {
|
|
1322
|
+
padding: '8px 12px',
|
|
1323
|
+
display: 'flex',
|
|
1324
|
+
justifyContent: 'flex-end'
|
|
1325
|
+
}
|
|
1326
|
+
}, /*#__PURE__*/React__default["default"].createElement(antd.Pagination, {
|
|
1327
|
+
size: "small",
|
|
1243
1328
|
total: formatData.total,
|
|
1244
1329
|
current: currentPage,
|
|
1245
1330
|
pageSize: currentPageSize,
|
|
@@ -1247,14 +1332,24 @@ const FetchTableContent = ({
|
|
|
1247
1332
|
showQuickJumper: paginationMerged.showQuickJumper,
|
|
1248
1333
|
hideOnSinglePage: paginationMerged.hideOnSinglePage,
|
|
1249
1334
|
onChange: (page, size) => {
|
|
1335
|
+
const currentParams = get__default["default"](requestParams, paginationMerged.paramsType, {});
|
|
1250
1336
|
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1251
|
-
[paginationMerged.paramsType]: Object.assign({},
|
|
1337
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1252
1338
|
[paginationMerged.currentName]: page,
|
|
1253
1339
|
[paginationMerged.pageSizeName]: size
|
|
1254
1340
|
})
|
|
1255
1341
|
});
|
|
1256
1342
|
}
|
|
1257
|
-
}) : null
|
|
1343
|
+
})) : null, isLoadMoreMode ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1344
|
+
style: {
|
|
1345
|
+
textAlign: 'center',
|
|
1346
|
+
padding: '8px 0',
|
|
1347
|
+
color: '#999',
|
|
1348
|
+
fontSize: 12,
|
|
1349
|
+
height: 32,
|
|
1350
|
+
visibility: isLoadingMore ? 'visible' : 'hidden'
|
|
1351
|
+
}
|
|
1352
|
+
}, "\u52A0\u8F7D\u4E2D...") : null);
|
|
1258
1353
|
};
|
|
1259
1354
|
const FetchTable = Fetch.withFetch(FetchTableContent);
|
|
1260
1355
|
|
|
@@ -1340,13 +1435,13 @@ const getListFromPageData = data => {
|
|
|
1340
1435
|
const TABLE_LIST_MAX_HEIGHT_POPUP = 300;
|
|
1341
1436
|
const TABLE_LIST_MAX_HEIGHT_EMBED = 400;
|
|
1342
1437
|
const TABLE_HEADER_HEIGHT = 48;
|
|
1343
|
-
const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React
|
|
1438
|
+
const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React.forwardRef((p, ref) => {
|
|
1344
1439
|
const {
|
|
1345
1440
|
formatMessage
|
|
1346
1441
|
} = reactIntl.useIntl();
|
|
1347
|
-
const [tagSearchText, setTagSearchText] = React
|
|
1348
|
-
const tablePageRef = React
|
|
1349
|
-
const listScrollRef = React
|
|
1442
|
+
const [tagSearchText, setTagSearchText] = React.useState('');
|
|
1443
|
+
const tablePageRef = React.useRef();
|
|
1444
|
+
const listScrollRef = React.useRef();
|
|
1350
1445
|
const props = Object.assign({}, {
|
|
1351
1446
|
overlayWidth: '600px',
|
|
1352
1447
|
dataType: 'list',
|
|
@@ -1398,7 +1493,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
1398
1493
|
return item[labelKey].indexOf(tagSearchText) > -1;
|
|
1399
1494
|
}
|
|
1400
1495
|
}, p);
|
|
1401
|
-
const bodyRef = React
|
|
1496
|
+
const bodyRef = React.useRef(null);
|
|
1402
1497
|
return /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({}, props, {
|
|
1403
1498
|
ref: ref
|
|
1404
1499
|
}), targetProps => {
|
|
@@ -1604,7 +1699,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
1604
1699
|
dataFormat
|
|
1605
1700
|
} : null, {
|
|
1606
1701
|
pagination: Object.assign({
|
|
1607
|
-
open:
|
|
1702
|
+
open: true,
|
|
1608
1703
|
showSizeChanger: false,
|
|
1609
1704
|
showQuickJumper: false,
|
|
1610
1705
|
hideOnSinglePage: true
|
|
@@ -1709,13 +1804,13 @@ const parseTreeData = memoize__default["default"](function (data, _ref) {
|
|
|
1709
1804
|
ids: data.map(item => item.id)
|
|
1710
1805
|
};
|
|
1711
1806
|
});
|
|
1712
|
-
const SelectTree = React
|
|
1807
|
+
const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
1713
1808
|
let {
|
|
1714
1809
|
children,
|
|
1715
1810
|
...p
|
|
1716
1811
|
} = _ref2;
|
|
1717
|
-
const fetchListRef = React
|
|
1718
|
-
const [expandedKeys, setExpandedKeys] = React
|
|
1812
|
+
const fetchListRef = React.useRef(null);
|
|
1813
|
+
const [expandedKeys, setExpandedKeys] = React.useState([]);
|
|
1719
1814
|
const props = Object.assign({}, {
|
|
1720
1815
|
parentKey: 'parentId',
|
|
1721
1816
|
childrenKey: 'children',
|
|
@@ -2190,13 +2285,13 @@ const CascaderInner = _ref => {
|
|
|
2190
2285
|
const {
|
|
2191
2286
|
message
|
|
2192
2287
|
} = antd.App.useApp();
|
|
2193
|
-
const [searchText, setSearchText] = React
|
|
2194
|
-
const [loading, setLoading] = React
|
|
2288
|
+
const [searchText, setSearchText] = React.useState('');
|
|
2289
|
+
const [loading, setLoading] = React.useState(false);
|
|
2195
2290
|
// 移动端弹窗内不用 SimpleBar,改原生滚动
|
|
2196
2291
|
const ScrollBox = isMobile ? 'div' : SimpleBar__default["default"];
|
|
2197
2292
|
|
|
2198
2293
|
// 构建 mapping
|
|
2199
|
-
const mapping = React
|
|
2294
|
+
const mapping = React.useMemo(() => {
|
|
2200
2295
|
const map = new Map();
|
|
2201
2296
|
const processData = function (items, parentId) {
|
|
2202
2297
|
if (parentId === void 0) {
|
|
@@ -2226,12 +2321,12 @@ const CascaderInner = _ref => {
|
|
|
2226
2321
|
}, [options, valueKey, labelKey]);
|
|
2227
2322
|
|
|
2228
2323
|
// 创建树工具
|
|
2229
|
-
const treeUtils = React
|
|
2324
|
+
const treeUtils = React.useMemo(() => {
|
|
2230
2325
|
return createTreeUtils(mapping);
|
|
2231
2326
|
}, [mapping]);
|
|
2232
2327
|
|
|
2233
2328
|
// 当前选中的列
|
|
2234
|
-
const [selectedIds, setSelectedIds] = React
|
|
2329
|
+
const [selectedIds, setSelectedIds] = React.useState(() => {
|
|
2235
2330
|
const initValue = value.find(item => {
|
|
2236
2331
|
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
2237
2332
|
return !!mapping.get(id);
|
|
@@ -2250,8 +2345,8 @@ const CascaderInner = _ref => {
|
|
|
2250
2345
|
});
|
|
2251
2346
|
|
|
2252
2347
|
// 当 Modal 打开时,根据 value 重新初始化 selectedIds
|
|
2253
|
-
const prevOpenRef = React
|
|
2254
|
-
React
|
|
2348
|
+
const prevOpenRef = React.useRef(open);
|
|
2349
|
+
React.useEffect(() => {
|
|
2255
2350
|
// 只在非 popup 模式下且 Modal 从关闭变为打开时处理
|
|
2256
2351
|
if (!isPopup && open && !prevOpenRef.current) {
|
|
2257
2352
|
const initValue = value.find(item => {
|
|
@@ -2273,14 +2368,14 @@ const CascaderInner = _ref => {
|
|
|
2273
2368
|
}, [open, value, mapping, treeUtils, valueKey, isPopup]);
|
|
2274
2369
|
|
|
2275
2370
|
// 懒加载支持
|
|
2276
|
-
const loadMorePropsRef = React
|
|
2371
|
+
const loadMorePropsRef = React.useRef({});
|
|
2277
2372
|
loadMorePropsRef.current = {
|
|
2278
2373
|
openLoadData,
|
|
2279
2374
|
onLoadMore,
|
|
2280
2375
|
parentIdKey,
|
|
2281
2376
|
treeUtils
|
|
2282
2377
|
};
|
|
2283
|
-
React
|
|
2378
|
+
React.useEffect(() => {
|
|
2284
2379
|
if (!open || !openLoadData || !onLoadMore) {
|
|
2285
2380
|
return;
|
|
2286
2381
|
}
|
|
@@ -2304,7 +2399,7 @@ const CascaderInner = _ref => {
|
|
|
2304
2399
|
}, [open, selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
|
|
2305
2400
|
|
|
2306
2401
|
// 检查是否为非叶子节点
|
|
2307
|
-
const isNotLastNode = React
|
|
2402
|
+
const isNotLastNode = React.useCallback(id => {
|
|
2308
2403
|
const node = mapping.get(id);
|
|
2309
2404
|
if (!node) return false;
|
|
2310
2405
|
if (openLoadData && !node.hasOwnProperty('children')) {
|
|
@@ -2314,7 +2409,7 @@ const CascaderInner = _ref => {
|
|
|
2314
2409
|
}, [mapping, openLoadData]);
|
|
2315
2410
|
|
|
2316
2411
|
// 选择处理
|
|
2317
|
-
const onCheckedChange = React
|
|
2412
|
+
const onCheckedChange = React.useCallback((checked, id) => {
|
|
2318
2413
|
const newValue = (() => {
|
|
2319
2414
|
if (onlyAllowLastLevel && checked) {
|
|
2320
2415
|
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
@@ -2353,7 +2448,7 @@ const CascaderInner = _ref => {
|
|
|
2353
2448
|
}, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
|
|
2354
2449
|
|
|
2355
2450
|
// 搜索结果
|
|
2356
|
-
const searchResults = React
|
|
2451
|
+
const searchResults = React.useMemo(() => {
|
|
2357
2452
|
if (!searchText || !onSearch) return null;
|
|
2358
2453
|
const keyword = searchText.toLowerCase();
|
|
2359
2454
|
return Array.from(mapping.values()).filter(item => {
|
|
@@ -2604,17 +2699,17 @@ const SelectCascader = _ref4 => {
|
|
|
2604
2699
|
} = _ref4;
|
|
2605
2700
|
// 内部始终使用数组格式处理
|
|
2606
2701
|
// SelectInput 会处理 single 模式的 value 和 onChange 转换
|
|
2607
|
-
const [innerValue, setInnerValue] = React
|
|
2702
|
+
const [innerValue, setInnerValue] = React.useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
|
|
2608
2703
|
|
|
2609
2704
|
// currentValue 用于内部处理,始终是数组
|
|
2610
|
-
const currentValue = React
|
|
2705
|
+
const currentValue = React.useMemo(() => {
|
|
2611
2706
|
if (value !== undefined) {
|
|
2612
2707
|
// 外部传入的 value 可能是对象(single)或数组(多选)
|
|
2613
2708
|
return Array.isArray(value) ? value : value ? [value] : [];
|
|
2614
2709
|
}
|
|
2615
2710
|
return innerValue;
|
|
2616
2711
|
}, [value, innerValue]);
|
|
2617
|
-
const setValue = React
|
|
2712
|
+
const setValue = React.useCallback(newValue => {
|
|
2618
2713
|
// SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
|
|
2619
2714
|
const normalizedValue = (() => {
|
|
2620
2715
|
if (single) {
|
|
@@ -2642,7 +2737,7 @@ const SelectCascader = _ref4 => {
|
|
|
2642
2737
|
}, [value, onChange, single]);
|
|
2643
2738
|
|
|
2644
2739
|
// 传递给 SelectInput 的值:根据 single 参数决定格式
|
|
2645
|
-
const selectInputValue = React
|
|
2740
|
+
const selectInputValue = React.useMemo(() => {
|
|
2646
2741
|
if (single) {
|
|
2647
2742
|
// single 模式:传单个对象或 undefined
|
|
2648
2743
|
return currentValue.length > 0 ? currentValue[0] : undefined;
|
|
@@ -2652,7 +2747,7 @@ const SelectCascader = _ref4 => {
|
|
|
2652
2747
|
}, [currentValue, single]);
|
|
2653
2748
|
|
|
2654
2749
|
// 计算 label 显示
|
|
2655
|
-
React
|
|
2750
|
+
React.useMemo(() => {
|
|
2656
2751
|
// currentValue 已经是数组格式了
|
|
2657
2752
|
return currentValue.map(item => {
|
|
2658
2753
|
// 如果已经是对象,确保有标准化的字段
|