@zat-design/sisyphus-react 3.14.0 → 3.14.3-beta.1

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.
@@ -18,4 +18,12 @@ declare function useEnum(codes: string[]): Record<string, DataOption[]>;
18
18
  * @param compose 展示 value-label
19
19
  */
20
20
  declare function useEnum(code: string, value?: string, compose?: boolean): [string, DataOption];
21
+ /**
22
+ * input code、values array output [labels array, options array]
23
+ * @param code
24
+ * @param values 值数组
25
+ * @param compose 展示 value-label
26
+ * @returns [标签数组, 选项数组]
27
+ */
28
+ declare function useEnum(code: string, values: (string | number)[], compose?: boolean): [string[], DataOption[]];
21
29
  export default useEnum;
@@ -1,3 +1,5 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
1
3
  var _ref;
2
4
  /* eslint-disable no-redeclare */
3
5
  import { useProConfig } from "../../ProConfigProvider";
@@ -23,6 +25,14 @@ var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-compon
23
25
  * @param compose 展示 value-label
24
26
  */
25
27
 
28
+ /**
29
+ * input code、values array output [labels array, options array]
30
+ * @param code
31
+ * @param values 值数组
32
+ * @param compose 展示 value-label
33
+ * @returns [标签数组, 选项数组]
34
+ */
35
+
26
36
  /**
27
37
  * 根据 code 从枚举缓存取出对应的 options 、以及回显
28
38
  * @param codes
@@ -62,16 +72,76 @@ function useEnum(codes, value, compose) {
62
72
  if (typeof codes === 'string') {
63
73
  var _catchData$data;
64
74
  var options = (catchData === null || catchData === void 0 || (_catchData$data = catchData.data) === null || _catchData$data === void 0 ? void 0 : _catchData$data[codes]) || [];
75
+
76
+ // 获取 children 字段名
77
+ var fieldChildren = 'children';
78
+ if (fieldNames && Object.keys(fieldNames).length && fieldNames.children) {
79
+ fieldChildren = fieldNames.children;
80
+ }
81
+ if (clear) {
82
+ fieldChildren = 'children';
83
+ }
84
+
85
+ // 递归查找函数:在嵌套结构中查找选项
86
+ var findOptionInNested = (opts, targetValue, fValue, fChildren) => {
87
+ // 当前层级查找
88
+ var foundInCurrentLevel = opts.find(option => String(option[fValue]) === String(targetValue));
89
+ if (foundInCurrentLevel) {
90
+ return foundInCurrentLevel;
91
+ }
92
+ // 递归查找子级
93
+ var foundInChildren = opts.reduce((found, option) => {
94
+ if (found) return found;
95
+ if (option[fChildren] && Array.isArray(option[fChildren])) {
96
+ return findOptionInNested(option[fChildren], targetValue, fValue, fChildren);
97
+ }
98
+ return undefined;
99
+ }, undefined);
100
+ return foundInChildren;
101
+ };
102
+
103
+ // 清理选项:移除 children,保留数据源中的其他所有字段(包括 parentCode 等业务字段)
104
+ var cleanOption = option => {
105
+ var _ = option[fieldChildren],
106
+ restOption = _objectWithoutProperties(option, [fieldChildren].map(_toPropertyKey));
107
+ return restOption;
108
+ };
65
109
  var getEnumLabel = (v, composezTow) => {
66
- var option = options.find(item => item[fieldValue] === v);
110
+ var option = findOptionInNested(options, v, fieldValue, fieldChildren);
67
111
  if (option) {
68
112
  return composezTow ? `${v}-${option[fieldLabel]}` : option[fieldLabel];
69
113
  }
114
+ return undefined;
70
115
  };
71
- if (value && Array.isArray(options)) {
72
- var option = options.find(item => item[fieldValue] === value);
116
+
117
+ // 处理数组值的情况
118
+ if (value && Array.isArray(value)) {
119
+ var labels = [];
120
+ var foundOptions = [];
121
+ value.forEach(v => {
122
+ var option = findOptionInNested(options, v, fieldValue, fieldChildren);
123
+ if (option) {
124
+ var cleanedOption = cleanOption(option);
125
+ foundOptions.push(cleanedOption);
126
+ labels.push(compose ? `${v}-${option[fieldLabel]}` : option[fieldLabel]);
127
+ } else {
128
+ var emptyOption = {
129
+ label: '',
130
+ value: ''
131
+ };
132
+ foundOptions.push(emptyOption);
133
+ labels.push('');
134
+ }
135
+ });
136
+ return [labels, foundOptions];
137
+ }
138
+
139
+ // 处理单个值的情况(保持向后兼容)
140
+ if (value && !Array.isArray(value) && Array.isArray(options)) {
141
+ var option = findOptionInNested(options, value, fieldValue, fieldChildren);
73
142
  if (option) {
74
- return [compose ? `${value}-${option[fieldLabel]}` : option[fieldLabel], option];
143
+ var cleanedOption = cleanOption(option);
144
+ return [compose ? `${value}-${option[fieldLabel]}` : option[fieldLabel], cleanedOption];
75
145
  }
76
146
  return [options];
77
147
  }
@@ -448,7 +448,7 @@ function useAntdTable(service, options, useRequestOptions) {
448
448
  });
449
449
  }
450
450
  return false;
451
- }, [rowSelections]);
451
+ }, [rowSelections, data.length, total]);
452
452
  var _rowSelection = {
453
453
  fixed: true,
454
454
  type: rowSelectType,
@@ -464,7 +464,7 @@ function useAntdTable(service, options, useRequestOptions) {
464
464
  return acc;
465
465
  }, {});
466
466
  setState({
467
- selectedRecords: newSelectedKeys === null || newSelectedKeys === void 0 ? void 0 : newSelectedKeys.map(item => selectedRecordObj === null || selectedRecordObj === void 0 ? void 0 : selectedRecordObj[item]),
467
+ selectedRecords: newSelectedKeys === null || newSelectedKeys === void 0 ? void 0 : newSelectedKeys.map(item => selectedRecordObj === null || selectedRecordObj === void 0 ? void 0 : selectedRecordObj[String(item)]),
468
468
  selectedRowKeys: newSelectedKeys
469
469
  });
470
470
  } else {
@@ -6,19 +6,19 @@ import "antd/es/input/style";
6
6
  import _Input from "antd/es/input";
7
7
  import "antd/es/message/style";
8
8
  import _message from "antd/es/message";
9
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
10
9
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
10
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
11
11
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
12
12
  import "antd/es/tree-select/style";
13
13
  import _TreeSelect from "antd/es/tree-select";
14
- var _excluded = ["disabled", "code", "dataSource", "defaultDisableValue", "onChange", "useRequest", "transformResponse", "fieldNames", "placeholder", "tooltip", "showSearch", "filterTreeNode", "treeNodeFilterProp", "defaultExpandAll", "expandedKeys", "treeCheckable", "onSearch", "otherProps", "width", "dropdownStyle", "popupClassName", "style", "allowClear", "listHeight", "showCodeName", "className", "checkStrictly", "checkable"],
15
- _excluded2 = ["children"];
14
+ var _excluded = ["disabled", "code", "dataSource", "defaultDisableValue", "onChange", "useRequest", "transformResponse", "fieldNames", "placeholder", "tooltip", "showSearch", "filterTreeNode", "treeNodeFilterProp", "defaultExpandAll", "expandedKeys", "treeCheckable", "onSearch", "otherProps", "width", "dropdownStyle", "popupClassName", "style", "allowClear", "listHeight", "showCodeName", "className", "checkStrictly", "checkable"];
16
15
  /* eslint-disable react/no-danger */
17
16
  /* eslint-disable react/jsx-closing-tag-location */
18
17
  import { useDeepCompareEffect, useRequest as useRequestFunc, useSetState } from 'ahooks';
19
18
  import classnames from 'classnames';
20
19
  import React, { useImperativeHandle, forwardRef, useCallback } from 'react';
21
20
  import { cloneDeep, debounce } from 'lodash';
21
+ import { tools } from '@zat-design/utils';
22
22
  import locale from "../../../locale";
23
23
  import { useProConfig } from "../../../ProConfigProvider";
24
24
  import Container from "../../../ProForm/components/Container";
@@ -35,14 +35,7 @@ export var ProTreeSelect = (props, ref) => {
35
35
  var _useProConfig = useProConfig('ProEnum'),
36
36
  _useProConfig$dics = _useProConfig.dics,
37
37
  dics = _useProConfig$dics === void 0 ? {} : _useProConfig$dics;
38
- var label = 'label';
39
- var code = 'value';
40
- var uuidKey = 'value';
41
- if (proSelectFieldNames && Object.keys(proSelectFieldNames).length) {
42
- code = proSelectFieldNames.value;
43
- label = proSelectFieldNames.label;
44
- uuidKey = proSelectFieldNames.key || proSelectFieldNames.value;
45
- }
38
+
46
39
  // 配置属性
47
40
  var disabled = props.disabled,
48
41
  enumCode = props.code,
@@ -88,11 +81,32 @@ export var ProTreeSelect = (props, ref) => {
88
81
  var _ref3 = otherProps || {},
89
82
  isView = _ref3.isView,
90
83
  viewEmpty = _ref3.viewEmpty;
91
- if (fieldNames && Object.keys(fieldNames).length) {
92
- code = fieldNames.value || 'value';
93
- label = fieldNames.label || 'label';
94
- uuidKey = fieldNames.key || code;
95
- }
84
+
85
+ // 合并全局和组件级别的 fieldNames,优先级:组件级 > 全局
86
+ var finalFieldNames = _objectSpread(_objectSpread({
87
+ label: 'label',
88
+ value: 'value',
89
+ children: 'children'
90
+ }, proSelectFieldNames), fieldNames);
91
+
92
+ /**
93
+ * 使用 tools.transformDataName 统一转换字段名
94
+ * 将原始数据转换为标准格式(label, value, children)
95
+ * tools.transformDataName 会自动检查数据是否已经是标准格式,如果是则直接返回
96
+ */
97
+ var transformFieldNames = useCallback(data => {
98
+ if (!data || !Array.isArray(data) || !data.length) {
99
+ return data || [];
100
+ }
101
+
102
+ // 使用 tools.transformDataName 转换字段名
103
+ // 它会自动检查数据是否已经是标准格式(label, value, children),如果是则直接返回
104
+ return tools.transformDataName(data, {
105
+ label: finalFieldNames.label,
106
+ value: finalFieldNames.value,
107
+ children: finalFieldNames.children
108
+ });
109
+ }, [finalFieldNames]);
96
110
  // 经过处理后的枚举数据,可能来自用户配置的处理函数后返回的结果
97
111
  var _useSetState = useSetState({}),
98
112
  _useSetState2 = _slicedToArray(_useSetState, 2),
@@ -105,6 +119,7 @@ export var ProTreeSelect = (props, ref) => {
105
119
 
106
120
  /**
107
121
  * 如果数据少于10条那么将数据平铺返回
122
+ * 注意:当 treeCheckable 为 false 时(单选模式),应保持树形结构,不进行平铺
108
123
  * @param dictsEnum 原始数据
109
124
  * @returns 平铺或者原始数据
110
125
  */
@@ -112,50 +127,33 @@ export var ProTreeSelect = (props, ref) => {
112
127
  if (treeCheckable) {
113
128
  return dictsEnum;
114
129
  }
115
- var count = 0;
116
- var result = [];
117
- var loopCount = data => {
118
- data.map(item => {
119
- count += 1;
120
- var children = item.children,
121
- other = _objectWithoutProperties(item, _excluded2);
122
- result.push(_objectSpread({}, other));
123
- if (item.children) {
124
- loopCount(item.children);
125
- }
126
- return item;
127
- });
128
- };
129
- if ((dictsEnum === null || dictsEnum === void 0 ? void 0 : dictsEnum.length) > 10) {
130
- return dictsEnum;
131
- }
132
- loopCount(dictsEnum);
133
- if (count <= 10) {
134
- return result;
135
- }
130
+ // 单选模式(treeCheckable=false)时,保持树形结构,不进行平铺
131
+ // 因为 TreeSelect 在单选模式下也需要树形结构来正确展示层级关系
136
132
  return dictsEnum;
137
133
  };
138
134
 
139
135
  /**
140
136
  * 如果要展示code-name,那么将源数据的label转为code-name
141
- * @param dataArr 源数据
137
+ * 注意:此时数据已经是标准格式(label, value, children)
138
+ * @param dataArr 源数据(标准格式)
142
139
  * @param showCodeAndName 是否展示code-name
143
140
  * @returns 转换结果
144
141
  */
145
142
  var transferDataSource = (dataArr, showCodeAndName) => {
143
+ if (!showCodeAndName) {
144
+ return dataArr;
145
+ }
146
146
  var copyData = cloneDeep(dataArr);
147
147
  var loop = arr => {
148
148
  arr.map(item => {
149
- item[label] = `${item[code]}-${item[label]}`;
149
+ item.label = `${item.value}-${item.label}`;
150
150
  if (item.children) {
151
151
  loop(item.children);
152
152
  }
153
153
  return item;
154
154
  });
155
155
  };
156
- if (showCodeAndName) {
157
- loop(copyData);
158
- }
156
+ loop(copyData);
159
157
  return copyData;
160
158
  };
161
159
  var defaultOnSuccessFun = res => {
@@ -167,7 +165,9 @@ export var ProTreeSelect = (props, ref) => {
167
165
  _message.error(msg);
168
166
  return;
169
167
  }
170
- var resultData = transferDataSource(data, showCodeName);
168
+ // 先转换字段名,再处理 code-name 展示
169
+ var transformedData = transformFieldNames(data || []);
170
+ var resultData = transferDataSource(transformedData, showCodeName);
171
171
  setState({
172
172
  selectList: resultData || [],
173
173
  origDataSource: resultData || []
@@ -196,7 +196,9 @@ export var ProTreeSelect = (props, ref) => {
196
196
  onSuccess: data => {
197
197
  if (transformResponse && typeof transformResponse === 'function') {
198
198
  var responseData = transformResponse(data);
199
- var resultData = transferDataSource(responseData, showCodeName);
199
+ // 先转换字段名,再处理 code-name 展示
200
+ var transformedData = transformFieldNames(responseData);
201
+ var resultData = transferDataSource(transformedData, showCodeName);
200
202
  setState({
201
203
  selectList: countChild(resultData),
202
204
  origDataSource: resultData
@@ -217,7 +219,9 @@ export var ProTreeSelect = (props, ref) => {
217
219
  if (fetchFunction !== null && fetchFunction !== void 0 && fetchFunction.data, useRequest !== null && useRequest !== void 0 && (_useRequest$options2 = useRequest.options) !== null && _useRequest$options2 !== void 0 && _useRequest$options2.cacheKey) {
218
220
  if (transformResponse && typeof transformResponse === 'function') {
219
221
  var responseData = transformResponse(fetchFunction.data);
220
- var resultData = transferDataSource(responseData, showCodeName);
222
+ // 先转换字段名,再处理 code-name 展示
223
+ var transformedData = transformFieldNames(responseData);
224
+ var resultData = transferDataSource(transformedData, showCodeName);
221
225
  setState({
222
226
  selectList: countChild(resultData),
223
227
  origDataSource: resultData
@@ -226,23 +230,29 @@ export var ProTreeSelect = (props, ref) => {
226
230
  defaultOnSuccessFun(fetchFunction.data);
227
231
  }
228
232
  }
229
- }, [fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data]);
233
+ }, [fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data, transformFieldNames]);
230
234
  useDeepCompareEffect(() => {
231
235
  if (enumCode) {
232
236
  var dictEnum = dics[enumCode] || [];
233
- var resultData = transferDataSource(dictEnum, showCodeName);
237
+ // 先转换字段名,再处理 code-name 展示
238
+ var transformedData = transformFieldNames(dictEnum);
239
+ var resultData = transferDataSource(transformedData, showCodeName);
240
+ var processedList = countChild(resultData);
234
241
  setState({
235
- selectList: countChild(resultData),
242
+ selectList: processedList,
236
243
  origDataSource: resultData
237
244
  });
238
245
  } else if (dataSource) {
239
- var _resultData = transferDataSource(dataSource, showCodeName);
246
+ // 先转换字段名,再处理 code-name 展示
247
+ var _transformedData = transformFieldNames(dataSource);
248
+ var _resultData = transferDataSource(_transformedData, showCodeName);
249
+ var _processedList = countChild(_resultData);
240
250
  setState({
241
- selectList: countChild(_resultData),
251
+ selectList: _processedList,
242
252
  origDataSource: _resultData
243
253
  });
244
254
  }
245
- }, [enumCode, dataSource]);
255
+ }, [enumCode, dataSource, transformFieldNames]);
246
256
  useDeepCompareEffect(() => {
247
257
  // code存在huo dataSource存在,不执行接口请求
248
258
  if (enumCode || dataSource) {
@@ -278,6 +288,7 @@ export var ProTreeSelect = (props, ref) => {
278
288
 
279
289
  /**
280
290
  * 根据值进行回显
291
+ * 注意:此时数据已经是标准格式(label, value, children)
281
292
  * @param value 输入值
282
293
  * @returns 对应枚举label
283
294
  */
@@ -287,8 +298,8 @@ export var ProTreeSelect = (props, ref) => {
287
298
  }
288
299
  var labelResult = [];
289
300
  var queryLabel = dicts => dicts.map(item => {
290
- if (value.includes(item[code])) {
291
- var labelText = item[label];
301
+ if (value.includes(item.value)) {
302
+ var labelText = item.label;
292
303
  labelResult.push(labelText);
293
304
  }
294
305
  if (item.children) {
@@ -333,15 +344,22 @@ export var ProTreeSelect = (props, ref) => {
333
344
 
334
345
  /**
335
346
  * 自定义渲染子树
336
- * @param node 每个节点数据对象
347
+ * 注意:此时数据已经是标准格式(label, value, children)
348
+ * @param node 每个节点数据对象(标准格式)
337
349
  * @returns 整个react节点树
338
350
  */
339
351
  var renderTreeNode = (node, grade) => {
340
352
  var children = node.children,
341
- icon = node.icon;
342
- var labelText = node[label];
343
- var value = node[code];
344
- var key = node[uuidKey];
353
+ icon = node.icon,
354
+ label = node.label,
355
+ nodeValue = node.value,
356
+ nodeKey = node.key;
357
+ var labelText = label;
358
+ var value = nodeValue;
359
+ var key = nodeValue; // 使用 value 作为 key,如果有 key 字段则使用 key
360
+ if (nodeKey !== undefined) {
361
+ key = nodeKey;
362
+ }
345
363
  // 三无走默认
346
364
  if (['undefined-undefined', 'undefined'].includes(labelText) && !value && !key) {
347
365
  if (showCodeName) {
@@ -409,7 +427,8 @@ export var ProTreeSelect = (props, ref) => {
409
427
 
410
428
  /**
411
429
  * 从树形数据中找出用户搜索得数据,并且将搜索字符串高亮标识
412
- * @param data 全量树
430
+ * 注意:此时数据已经是标准格式(label, value, children)
431
+ * @param data 全量树(标准格式)
413
432
  * @param searchStr 搜索字符串
414
433
  * @returns 处理后得树
415
434
  */
@@ -426,11 +445,11 @@ export var ProTreeSelect = (props, ref) => {
426
445
  }
427
446
  // 迭代完子节点向上回溯,如果有匹配到得子节点,那么加入当前节点得孩子对象上,否则加入得是空数组
428
447
  item.children = currentNodeChild;
429
- // 判断节点title是否包含关键字 如果有,那么直接进行下一循环
448
+ // 判断节点label是否包含关键字 如果有,那么直接进行下一循环
430
449
  // @ts-ignore
431
- if (item[label].indexOf(keyWord) > -1 && (selectProps === null || selectProps === void 0 ? void 0 : selectProps.mode) !== 'treeSelect') {
450
+ if (item.label && item.label.indexOf(keyWord) > -1 && (selectProps === null || selectProps === void 0 ? void 0 : selectProps.mode) !== 'treeSelect') {
432
451
  var regExp = new RegExp(keyWord);
433
- item[label] = item[label].replace(regExp, `<span class="highlight-search-text">${keyWord}</span>`);
452
+ item.label = item.label.replace(regExp, `<span class="highlight-search-text">${keyWord}</span>`);
434
453
  }
435
454
  currentAllNodeChild.push(item);
436
455
  }
@@ -468,16 +487,23 @@ export var ProTreeSelect = (props, ref) => {
468
487
  return _ref6.apply(this, arguments);
469
488
  };
470
489
  }(), 500);
490
+
491
+ /**
492
+ * 从树形数据中查找节点
493
+ * 注意:此时数据已经是标准格式(label, value, children)
494
+ * @param treeList 树形数据(标准格式)
495
+ * @param nodeValue 节点值
496
+ * @returns 找到的节点
497
+ */
471
498
  function findTreeNode(treeList, nodeValue) {
472
499
  var result = {};
473
500
  var filterData = function filterData(data) {
474
501
  for (var i = 0; i < data.length; i++) {
475
502
  var item = data[i];
476
- if (item[code] === nodeValue || Array.isArray(nodeValue) && nodeValue.includes(item[code])) {
503
+ if (item.value === nodeValue || Array.isArray(nodeValue) && nodeValue.includes(item.value)) {
477
504
  result = _objectSpread({}, item);
478
- result.value = item[code];
479
- result.label = item[label];
480
- delete result[(fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || 'children'];
505
+ // 删除 children 字段,避免循环引用
506
+ delete result.children;
481
507
  return null;
482
508
  }
483
509
  // 一直递归到最后一层子节点
@@ -489,6 +515,13 @@ export var ProTreeSelect = (props, ref) => {
489
515
  filterData(treeList);
490
516
  return result;
491
517
  }
518
+ /**
519
+ * 根据值获取标签
520
+ * 注意:此时数据已经是标准格式(label, value, children)
521
+ * @param treeList 树形数据(标准格式)
522
+ * @param nodeValue 节点值
523
+ * @returns 标签对象或数组
524
+ */
492
525
  function getLabelByValue(treeList, nodeValue) {
493
526
  var result = nodeValue;
494
527
  if (nodeValue) {
@@ -500,19 +533,19 @@ export var ProTreeSelect = (props, ref) => {
500
533
  return item;
501
534
  });
502
535
  } else {
503
- result = findTreeNode(treeList, nodeValue[code]);
536
+ result = findTreeNode(treeList, nodeValue.value);
504
537
  }
505
538
  }
506
539
  return result;
507
540
  }
508
541
  var handleChange = (newVal, label, extra) => {
509
542
  // newVal回来得一定是label、value
543
+ // 注意:此时数据已经是标准格式(label, value, children)
510
544
  var _selectList = selectList.map(item => {
511
- var label = item.label;
512
- var _label = label;
513
- if (label) {
545
+ var _label = item.label;
546
+ if (_label) {
514
547
  var regex = /<span class="highlight-search-text">(.*?)<\/span>/g;
515
- _label = item[label] = label === null || label === void 0 ? void 0 : label.replace(regex, '$1');
548
+ _label = item.label = _label.replace(regex, '$1');
516
549
  }
517
550
  return _objectSpread(_objectSpread({}, item), {}, {
518
551
  label: _label
@@ -1,6 +1,12 @@
1
1
  @root-entry-name: 'default';
2
2
  @import (reference) '~antd/es/style/themes/index.less';
3
3
 
4
+ .pro-tree-select-drop-down-container{
5
+ .@{ant-prefix}-select-tree-checkbox{
6
+ margin-top: 0;
7
+ }
8
+ }
9
+
4
10
  .pro-tree-modal-container .@{ant-prefix}-modal-content .@{ant-prefix}-modal-body {
5
11
  max-height: 498px;
6
12
  }
@@ -18,4 +18,12 @@ declare function useEnum(codes: string[]): Record<string, DataOption[]>;
18
18
  * @param compose 展示 value-label
19
19
  */
20
20
  declare function useEnum(code: string, value?: string, compose?: boolean): [string, DataOption];
21
+ /**
22
+ * input code、values array output [labels array, options array]
23
+ * @param code
24
+ * @param values 值数组
25
+ * @param compose 展示 value-label
26
+ * @returns [标签数组, 选项数组]
27
+ */
28
+ declare function useEnum(code: string, values: (string | number)[], compose?: boolean): [string[], DataOption[]];
21
29
  export default useEnum;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
+ var _toPropertyKey2 = _interopRequireDefault(require("@babel/runtime/helpers/toPropertyKey"));
7
10
  var _ProConfigProvider = require("../../ProConfigProvider");
8
11
  var _utils = require("../utils");
9
12
  var _ref;
@@ -29,6 +32,14 @@ var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-compon
29
32
  * @param compose 展示 value-label
30
33
  */
31
34
 
35
+ /**
36
+ * input code、values array output [labels array, options array]
37
+ * @param code
38
+ * @param values 值数组
39
+ * @param compose 展示 value-label
40
+ * @returns [标签数组, 选项数组]
41
+ */
42
+
32
43
  /**
33
44
  * 根据 code 从枚举缓存取出对应的 options 、以及回显
34
45
  * @param codes
@@ -68,16 +79,76 @@ function useEnum(codes, value, compose) {
68
79
  if (typeof codes === 'string') {
69
80
  var _catchData$data;
70
81
  var options = (catchData === null || catchData === void 0 || (_catchData$data = catchData.data) === null || _catchData$data === void 0 ? void 0 : _catchData$data[codes]) || [];
82
+
83
+ // 获取 children 字段名
84
+ var fieldChildren = 'children';
85
+ if (fieldNames && Object.keys(fieldNames).length && fieldNames.children) {
86
+ fieldChildren = fieldNames.children;
87
+ }
88
+ if (clear) {
89
+ fieldChildren = 'children';
90
+ }
91
+
92
+ // 递归查找函数:在嵌套结构中查找选项
93
+ var findOptionInNested = (opts, targetValue, fValue, fChildren) => {
94
+ // 当前层级查找
95
+ var foundInCurrentLevel = opts.find(option => String(option[fValue]) === String(targetValue));
96
+ if (foundInCurrentLevel) {
97
+ return foundInCurrentLevel;
98
+ }
99
+ // 递归查找子级
100
+ var foundInChildren = opts.reduce((found, option) => {
101
+ if (found) return found;
102
+ if (option[fChildren] && Array.isArray(option[fChildren])) {
103
+ return findOptionInNested(option[fChildren], targetValue, fValue, fChildren);
104
+ }
105
+ return undefined;
106
+ }, undefined);
107
+ return foundInChildren;
108
+ };
109
+
110
+ // 清理选项:移除 children,保留数据源中的其他所有字段(包括 parentCode 等业务字段)
111
+ var cleanOption = option => {
112
+ var _ = option[fieldChildren],
113
+ restOption = (0, _objectWithoutProperties2.default)(option, [fieldChildren].map(_toPropertyKey2.default));
114
+ return restOption;
115
+ };
71
116
  var getEnumLabel = (v, composezTow) => {
72
- var option = options.find(item => item[fieldValue] === v);
117
+ var option = findOptionInNested(options, v, fieldValue, fieldChildren);
73
118
  if (option) {
74
119
  return composezTow ? `${v}-${option[fieldLabel]}` : option[fieldLabel];
75
120
  }
121
+ return undefined;
76
122
  };
77
- if (value && Array.isArray(options)) {
78
- var option = options.find(item => item[fieldValue] === value);
123
+
124
+ // 处理数组值的情况
125
+ if (value && Array.isArray(value)) {
126
+ var labels = [];
127
+ var foundOptions = [];
128
+ value.forEach(v => {
129
+ var option = findOptionInNested(options, v, fieldValue, fieldChildren);
130
+ if (option) {
131
+ var cleanedOption = cleanOption(option);
132
+ foundOptions.push(cleanedOption);
133
+ labels.push(compose ? `${v}-${option[fieldLabel]}` : option[fieldLabel]);
134
+ } else {
135
+ var emptyOption = {
136
+ label: '',
137
+ value: ''
138
+ };
139
+ foundOptions.push(emptyOption);
140
+ labels.push('');
141
+ }
142
+ });
143
+ return [labels, foundOptions];
144
+ }
145
+
146
+ // 处理单个值的情况(保持向后兼容)
147
+ if (value && !Array.isArray(value) && Array.isArray(options)) {
148
+ var option = findOptionInNested(options, value, fieldValue, fieldChildren);
79
149
  if (option) {
80
- return [compose ? `${value}-${option[fieldLabel]}` : option[fieldLabel], option];
150
+ var cleanedOption = cleanOption(option);
151
+ return [compose ? `${value}-${option[fieldLabel]}` : option[fieldLabel], cleanedOption];
81
152
  }
82
153
  return [options];
83
154
  }
@@ -456,7 +456,7 @@ function useAntdTable(service, options, useRequestOptions) {
456
456
  });
457
457
  }
458
458
  return false;
459
- }, [rowSelections]);
459
+ }, [rowSelections, data.length, total]);
460
460
  var _rowSelection = {
461
461
  fixed: true,
462
462
  type: rowSelectType,
@@ -472,7 +472,7 @@ function useAntdTable(service, options, useRequestOptions) {
472
472
  return acc;
473
473
  }, {});
474
474
  setState({
475
- selectedRecords: newSelectedKeys === null || newSelectedKeys === void 0 ? void 0 : newSelectedKeys.map(item => selectedRecordObj === null || selectedRecordObj === void 0 ? void 0 : selectedRecordObj[item]),
475
+ selectedRecords: newSelectedKeys === null || newSelectedKeys === void 0 ? void 0 : newSelectedKeys.map(item => selectedRecordObj === null || selectedRecordObj === void 0 ? void 0 : selectedRecordObj[String(item)]),
476
476
  selectedRowKeys: newSelectedKeys
477
477
  });
478
478
  } else {