@zat-design/sisyphus-react 3.14.0-beta.2 → 3.14.2

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
  }
@@ -100,6 +100,8 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
100
100
  optimize?: boolean;
101
101
  /** 是否在遇到第一个错误时停止验证 */
102
102
  stopOnFirstError?: boolean;
103
+ /** label 对齐方式 */
104
+ labelAlign?: 'left' | 'right';
103
105
  }
104
106
  export interface TransformType<T = any> {
105
107
  normalize?: (value: StoreValue, prevValue: StoreValue, allValues: Store) => StoreValue;
@@ -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 {
@@ -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
  }
@@ -100,6 +100,8 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
100
100
  optimize?: boolean;
101
101
  /** 是否在遇到第一个错误时停止验证 */
102
102
  stopOnFirstError?: boolean;
103
+ /** label 对齐方式 */
104
+ labelAlign?: 'left' | 'right';
103
105
  }
104
106
  export interface TransformType<T = any> {
105
107
  normalize?: (value: StoreValue, prevValue: StoreValue, allValues: Store) => StoreValue;
@@ -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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.14.0-beta.2",
3
+ "version": "3.14.2",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">=18.19.0"