@kne/super-select 0.1.47 → 0.1.48

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 CHANGED
@@ -737,6 +737,59 @@ const SearchableTableExample = ({ isPopup }) => {
737
737
  );
738
738
  };
739
739
 
740
+ const remoteSearchListFilter = { language: 'zh-CN' };
741
+
742
+ // 远程搜索:getSearchProps 必须写入 params(paramsType=params),不能写进 data
743
+ const RemoteSearchTableExample = ({ isPopup }) => {
744
+ const [value, setValue] = useState([]);
745
+ const [lastRequest, setLastRequest] = useState(null);
746
+ const api = React.useMemo(
747
+ () => ({
748
+ params: { filter: remoteSearchListFilter },
749
+ loader: request => {
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
+ }
761
+ }),
762
+ []
763
+ );
764
+
765
+ return (
766
+ <Flex vertical gap={8}>
767
+ <span>远程搜索(paramsType=params):</span>
768
+ <div style={{ color: '#666', fontSize: 12, lineHeight: 1.6 }}>
769
+ 模拟 GET 列表,loader 只读 params.filter.keyword。修好后搜「员工1」或「技术」列表会过滤,且下方 params.filter 含 keyword、data 为空对象;未修好时关键词进 data,列表不变。建议切到「弹窗」模式再搜。
770
+ </div>
771
+ <SelectTableList
772
+ api={api}
773
+ columns={employeeColumns}
774
+ valueKey="id"
775
+ labelKey="name"
776
+ value={value}
777
+ onChange={setValue}
778
+ isPopup={isPopup}
779
+ placeholder="搜索姓名、邮箱或部门"
780
+ getSearchProps={({ searchText }) => ({
781
+ filter: Object.assign({}, remoteSearchListFilter, searchText ? { keyword: searchText } : {})
782
+ })}
783
+ pagination={{ paramsType: 'params' }}
784
+ style={{ width: 600 }}
785
+ />
786
+ {lastRequest ? (
787
+ <pre style={{ margin: 0, fontSize: 12, background: '#f5f5f5', padding: 8, borderRadius: 4, overflow: 'auto' }}>{JSON.stringify(lastRequest, null, 2)}</pre>
788
+ ) : null}
789
+ </Flex>
790
+ );
791
+ };
792
+
740
793
  // 全选功能
741
794
  const SelectAllTableExample = ({ isPopup }) => {
742
795
  const [value, setValue] = useState([]);
@@ -1267,6 +1320,8 @@ const BaseExample = () => {
1267
1320
  <Divider />
1268
1321
  <SearchableTableExample isPopup={isPopup} />
1269
1322
  <Divider />
1323
+ <RemoteSearchTableExample isPopup={isPopup} />
1324
+ <Divider />
1270
1325
  <SelectAllTableExample isPopup={isPopup} />
1271
1326
  <Divider />
1272
1327
  <WideTableExample isPopup={isPopup} />
package/dist/index.js CHANGED
@@ -1395,6 +1395,10 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
1395
1395
  onOpenChange(false);
1396
1396
  }
1397
1397
  }) : footer);
1398
+ const paginationParamsType = paginationProp?.paramsType || 'data';
1399
+ const searchRequestProps = typeof getSearchProps === 'function' && isEmpty.isNotEmpty(searchProps) ? {
1400
+ [paginationParamsType]: getSearchProps(searchProps) || {}
1401
+ } : {};
1398
1402
  const tablePageFetchConfig = options ? {
1399
1403
  data: {
1400
1404
  options,
@@ -1419,9 +1423,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
1419
1423
  totalCount: pageData.length
1420
1424
  };
1421
1425
  }
1422
- } : merge__default["default"]({}, api, typeof getSearchProps === 'function' && isEmpty.isNotEmpty(searchProps) ? {
1423
- data: getSearchProps(searchProps) || {}
1424
- } : {});
1426
+ } : merge__default["default"]({}, api, searchRequestProps);
1425
1427
  const allColumnsHaveWidth = Array.isArray(columns) && columns.length > 0 && columns.every(TablePage.hasColumnWidth);
1426
1428
  const tableSelection = {
1427
1429
  allowSelectedAll,