@zat-design/sisyphus-react 4.4.3-beta.2 → 4.5.0-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.
- package/README.md +1 -42
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.d.ts +1 -14
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.js +27 -102
- package/es/ProEditTable/components/RenderField/index.js +313 -366
- package/es/ProEditTable/components/RenderField/propsType.d.ts +30 -0
- package/es/ProEditTable/components/RenderField/propsType.js +1 -0
- package/es/ProEditTable/components/RenderField/tools.d.ts +22 -0
- package/es/ProEditTable/components/RenderField/tools.js +203 -0
- package/es/ProEditTable/components/Validator/index.d.ts +9 -0
- package/es/ProEditTable/components/Validator/index.js +56 -6
- package/es/ProEditTable/index.js +16 -2
- package/es/ProEditTable/utils/config.d.ts +1 -1
- package/es/ProEditTable/utils/config.js +18 -7
- package/es/ProEditTable/utils/tools.d.ts +30 -1
- package/es/ProEditTable/utils/tools.js +95 -12
- package/es/ProEditTable/utils/validateAll.d.ts +86 -0
- package/es/ProEditTable/utils/validateAll.js +319 -0
- package/es/ProForm/components/combination/Group/utils/index.d.ts +25 -25
- package/es/ProTree/components/ProTreeSelect/index.js +3 -2
- package/es/ProTree/utils.d.ts +9 -0
- package/es/ProTree/utils.js +31 -0
- package/package.json +1 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { FormInstance } from 'antd';
|
|
2
|
+
import type { NamePath } from 'antd/es/form/interface';
|
|
3
|
+
/**
|
|
4
|
+
* 单元格规则装配 + 全量数据真实校验(脱离 DOM)。
|
|
5
|
+
*
|
|
6
|
+
* 背景:antd6 虚拟表格滚动时视口外的行会被卸载,其 Form.Item 字段未注册,
|
|
7
|
+
* form.validateFields 无法覆盖;本模块用 form store 里的全量数据 + 真实规则
|
|
8
|
+
* 逐行逐列离屏校验,解决「统一校验」缺口,并产出可常驻的真实报错文案。
|
|
9
|
+
*/
|
|
10
|
+
interface BuildCellRulesParams {
|
|
11
|
+
column: any;
|
|
12
|
+
rowData: any;
|
|
13
|
+
index: number;
|
|
14
|
+
form: FormInstance;
|
|
15
|
+
name: (string | number)[];
|
|
16
|
+
config: any;
|
|
17
|
+
}
|
|
18
|
+
interface BuiltCellRule {
|
|
19
|
+
/** 单元格 Form.Item 的 namePath(用于定位/messageVariables) */
|
|
20
|
+
namePath: (string | number)[];
|
|
21
|
+
/** 列在行内的稳定标识(与 transformColumns 的 dataIndex/key 一致),用于错误存储归集 */
|
|
22
|
+
cellKey: string;
|
|
23
|
+
/** 待校验值(names 列为组合数组) */
|
|
24
|
+
value: any;
|
|
25
|
+
/** 真实规则集合 */
|
|
26
|
+
rules: any[];
|
|
27
|
+
/** 字段 label,供 ${label} 文案插值 */
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 为单行单列装配真实校验规则与取值。
|
|
32
|
+
* 当该单元格处于查看/禁用态、或无任何规则时返回 null(跳过校验)。
|
|
33
|
+
*/
|
|
34
|
+
export declare const buildCellRules: ({ column, rowData, index, form, name, config, }: BuildCellRulesParams) => BuiltCellRule | null;
|
|
35
|
+
interface ValidateAllParams {
|
|
36
|
+
form: FormInstance;
|
|
37
|
+
name: NamePath;
|
|
38
|
+
columns: any[];
|
|
39
|
+
config: any;
|
|
40
|
+
}
|
|
41
|
+
export interface ValidateAllResult {
|
|
42
|
+
hasError: boolean;
|
|
43
|
+
/** rowKey -> { cellKey -> 错误文案数组 } */
|
|
44
|
+
errorMap: Record<string, Record<string, string[]>>;
|
|
45
|
+
/** 首个错误单元格的 namePath(用于滚动定位),无错误为 null */
|
|
46
|
+
firstErrorPath: (string | number)[] | null;
|
|
47
|
+
/** 首个错误行的 rowKey(用于横向滚动时定位错误行 DOM),无错误为 null */
|
|
48
|
+
firstErrorRowKey: string | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 对 form store 中 name 路径下的全量数组数据,逐行逐列用真实规则校验(脱离 DOM)。
|
|
52
|
+
*/
|
|
53
|
+
export declare const validateAllRows: ({ form, name, columns, config, }: ValidateAllParams) => Promise<ValidateAllResult>;
|
|
54
|
+
/**
|
|
55
|
+
* 外部错误存储:以 rowKey + cellKey 为键持久化真实报错文案。
|
|
56
|
+
* 它是「报错常驻」的真实来源——脱离 antd Field 实体生命周期,
|
|
57
|
+
* 行卸载后仍保留,重新挂载时回填显示。
|
|
58
|
+
*/
|
|
59
|
+
export interface ErrorStore {
|
|
60
|
+
/** 读取某单元格错误文案 */
|
|
61
|
+
get(rowKey: string | number, cellKey: string): string[] | undefined;
|
|
62
|
+
/** 读取整行错误 */
|
|
63
|
+
getRow(rowKey: string | number): Record<string, string[]> | undefined;
|
|
64
|
+
/** 全量替换(来自一次完整校验) */
|
|
65
|
+
setAll(errorMap: Record<string, Record<string, string[]>>): void;
|
|
66
|
+
/** 清理某单元格(用户修正后调用),整行清空时移除该行 */
|
|
67
|
+
clearCell(rowKey: string | number, cellKey: string): void;
|
|
68
|
+
/** 清空所有 */
|
|
69
|
+
clearAll(): void;
|
|
70
|
+
/** 是否为空 */
|
|
71
|
+
isEmpty(): boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare const createErrorStore: () => ErrorStore;
|
|
74
|
+
interface RunUnifiedParams extends ValidateAllParams {
|
|
75
|
+
errorStore: ErrorStore;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 统一校验入口:对全量数据跑真实规则,写入 errorStore,返回是否有错与首个错误行索引。
|
|
79
|
+
* 供隐藏聚合校验字段在 form.validateFields() 时调用,从而覆盖视口外未挂载的行。
|
|
80
|
+
*/
|
|
81
|
+
export declare const runUnifiedValidation: ({ form, name, columns, config, errorStore, }: RunUnifiedParams) => Promise<{
|
|
82
|
+
hasError: boolean;
|
|
83
|
+
firstErrorIndex: number | null;
|
|
84
|
+
firstErrorRowKey: string | null;
|
|
85
|
+
}>;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import _isString from "lodash/isString";
|
|
2
|
+
import _isFunction from "lodash/isFunction";
|
|
3
|
+
import _isBoolean from "lodash/isBoolean";
|
|
4
|
+
import _get from "lodash/get";
|
|
5
|
+
// 复用 antd 内部(@rc-component/form)的真实校验内核:与每个 Form.Item 字段走的是同一套
|
|
6
|
+
// async-validator 流程,保证脱离 DOM 校验时的文案/异步 validator 行为与渲染态完全一致。
|
|
7
|
+
import { validateRules } from '@rc-component/form/es/utils/validateUtil';
|
|
8
|
+
import { rulesCreator } from "../../ProForm/utils/rulesCreator";
|
|
9
|
+
import { isSelect, isNullArray, isNotFullArray } from "../../ProForm/utils";
|
|
10
|
+
import { getDisabled, splitNames } from "./tools";
|
|
11
|
+
import locale from "../../locale";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 单元格规则装配 + 全量数据真实校验(脱离 DOM)。
|
|
15
|
+
*
|
|
16
|
+
* 背景:antd6 虚拟表格滚动时视口外的行会被卸载,其 Form.Item 字段未注册,
|
|
17
|
+
* form.validateFields 无法覆盖;本模块用 form store 里的全量数据 + 真实规则
|
|
18
|
+
* 逐行逐列离屏校验,解决「统一校验」缺口,并产出可常驻的真实报错文案。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 纯函数版规则装配,镜像 ProForm/hooks/useRules(去掉 hook 外壳)+ 复用 rulesCreator,
|
|
23
|
+
* 确保与渲染态生成的 rules 完全一致,无文案漂移。
|
|
24
|
+
*/
|
|
25
|
+
const composeRules = ({
|
|
26
|
+
rules,
|
|
27
|
+
required,
|
|
28
|
+
isSelectField,
|
|
29
|
+
label,
|
|
30
|
+
names,
|
|
31
|
+
labelRequired
|
|
32
|
+
}) => {
|
|
33
|
+
const _label = _isString(label) ? label : '';
|
|
34
|
+
const requiredRule = Array.isArray(rules) && rules.find(rule => rule?.required === true);
|
|
35
|
+
const allRequired = required === true || Array.isArray(required) && required.every(item => item === true);
|
|
36
|
+
let resultRules = rules || [];
|
|
37
|
+
if (allRequired) {
|
|
38
|
+
if (!requiredRule) {
|
|
39
|
+
const message = isSelectField ? `${locale.ProForm.selectPlaceHolder}${_label}` : `${locale.ProForm.inputPlaceholder}${_label}`;
|
|
40
|
+
const rule = {
|
|
41
|
+
required: allRequired,
|
|
42
|
+
message
|
|
43
|
+
};
|
|
44
|
+
// names 字段的必填校验(与 useRules 保持一致)
|
|
45
|
+
if (names?.length) {
|
|
46
|
+
rule.validator = (_, value) => {
|
|
47
|
+
if (!value || isNullArray(value)) {
|
|
48
|
+
return Promise.reject(new Error(`${locale.ProForm.inputPlaceholder}${_label}`));
|
|
49
|
+
}
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
resultRules = Array.isArray(rules) ? [...rules, rule] : [rule];
|
|
54
|
+
}
|
|
55
|
+
} else if (requiredRule && names?.length) {
|
|
56
|
+
// 不可变:克隆并替换 requiredRule 的 validator,避免污染外部 column.rules
|
|
57
|
+
resultRules = rules.map(rule => rule === requiredRule ? {
|
|
58
|
+
...rule,
|
|
59
|
+
validator: (_, value) => {
|
|
60
|
+
if (!value || isNullArray(value)) {
|
|
61
|
+
return Promise.reject(new Error(`${locale.ProForm.inputPlaceholder}${_label}`));
|
|
62
|
+
}
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
65
|
+
} : rule);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// type → 内置 rules(直接复用 rulesCreator 纯函数)
|
|
69
|
+
let finalRules = rulesCreator({
|
|
70
|
+
rules: resultRules,
|
|
71
|
+
label: _label,
|
|
72
|
+
isSelect: isSelectField,
|
|
73
|
+
names,
|
|
74
|
+
required
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 完整性校验(镜像 useRules 的 useEffect 分支)
|
|
78
|
+
if (names && !_isBoolean(labelRequired)) {
|
|
79
|
+
const customRequired = {
|
|
80
|
+
validator: (_rules, value) => {
|
|
81
|
+
if (Array.isArray(value) && !isNullArray(value) && isNotFullArray(value, names.length, required)) {
|
|
82
|
+
return Promise.reject(new Error(`${locale.ProForm.completeText}${_label}`));
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
finalRules = [customRequired, ...finalRules];
|
|
88
|
+
}
|
|
89
|
+
return finalRules;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 为单行单列装配真实校验规则与取值。
|
|
94
|
+
* 当该单元格处于查看/禁用态、或无任何规则时返回 null(跳过校验)。
|
|
95
|
+
*/
|
|
96
|
+
export const buildCellRules = ({
|
|
97
|
+
column,
|
|
98
|
+
rowData,
|
|
99
|
+
index,
|
|
100
|
+
form,
|
|
101
|
+
name,
|
|
102
|
+
config
|
|
103
|
+
}) => {
|
|
104
|
+
// 整表查看模式:不校验
|
|
105
|
+
if (config?.isView) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const reactiveParams = {
|
|
109
|
+
form,
|
|
110
|
+
index,
|
|
111
|
+
namePath: [...name, index]
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// 动态 required / rules / isEditable 按行求值
|
|
115
|
+
let lastRequired = column?.required ?? false;
|
|
116
|
+
if (_isFunction(column?.required)) {
|
|
117
|
+
lastRequired = column.required(rowData, reactiveParams);
|
|
118
|
+
}
|
|
119
|
+
let lastRules = column?.rules ?? [];
|
|
120
|
+
if (_isFunction(column?.rules)) {
|
|
121
|
+
lastRules = column.rules(rowData, reactiveParams);
|
|
122
|
+
}
|
|
123
|
+
let lastFieldProps = column?.fieldProps ?? {};
|
|
124
|
+
if (_isFunction(column?.fieldProps)) {
|
|
125
|
+
lastFieldProps = column.fieldProps(rowData, reactiveParams);
|
|
126
|
+
}
|
|
127
|
+
let isEditable = column?.isEditable ?? true;
|
|
128
|
+
if (_isFunction(column?.isEditable)) {
|
|
129
|
+
isEditable = column.isEditable(rowData, reactiveParams);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 与 RenderField 一致的 type 首字母大写
|
|
133
|
+
const type = column?.type?.replace?.(column.type[0], column.type[0].toUpperCase());
|
|
134
|
+
|
|
135
|
+
// 查看/禁用单元格跳过(镜像 RenderField.isView 的核心判定)
|
|
136
|
+
const disabled = getDisabled({
|
|
137
|
+
globalControl: config?.otherProps?.globalControl,
|
|
138
|
+
formDisabled: config?.otherProps?.formDisabled,
|
|
139
|
+
column,
|
|
140
|
+
tabledDisabled: config?.disabled,
|
|
141
|
+
columnFieldProps: lastFieldProps,
|
|
142
|
+
params: [rowData, reactiveParams],
|
|
143
|
+
rowDisabled: config?.rowDisabled || 'empty'
|
|
144
|
+
});
|
|
145
|
+
if (!isEditable || rowData?.['is-view'] || disabled) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const names = column?.names;
|
|
149
|
+
const columnName = column?.name || column?.dataIndex || column?.key;
|
|
150
|
+
const isSelectField = !!isSelect({
|
|
151
|
+
dataSource: lastFieldProps?.dataSource,
|
|
152
|
+
type
|
|
153
|
+
});
|
|
154
|
+
const rules = composeRules({
|
|
155
|
+
rules: lastRules,
|
|
156
|
+
required: lastRequired,
|
|
157
|
+
isSelectField,
|
|
158
|
+
label: column?.label,
|
|
159
|
+
names,
|
|
160
|
+
labelRequired: column?.labelRequired
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// 无实际约束(仅 [{ required: false }] 兜底)时跳过
|
|
164
|
+
const hasRealRule = rules.some(rule => rule?.required === true || rule?.validator || rule?.type || rule?.pattern);
|
|
165
|
+
if (!hasRealRule) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 取值与 cellKey:names 列取组合数组,cellKey 用 splitNames(与 transformColumns 对齐)
|
|
170
|
+
let value;
|
|
171
|
+
let cellKey;
|
|
172
|
+
if (names?.length) {
|
|
173
|
+
value = names.map(key => _get(rowData, key));
|
|
174
|
+
cellKey = splitNames(names);
|
|
175
|
+
} else {
|
|
176
|
+
const path = Array.isArray(columnName) ? columnName : [columnName];
|
|
177
|
+
value = _get(rowData, path);
|
|
178
|
+
cellKey = String(columnName);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
namePath: [...name, index, ...(Array.isArray(columnName) ? columnName : [columnName])],
|
|
182
|
+
cellKey,
|
|
183
|
+
value,
|
|
184
|
+
rules,
|
|
185
|
+
label: _isString(column?.label) ? column.label : ''
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* 对 form store 中 name 路径下的全量数组数据,逐行逐列用真实规则校验(脱离 DOM)。
|
|
190
|
+
*/
|
|
191
|
+
export const validateAllRows = async ({
|
|
192
|
+
form,
|
|
193
|
+
name,
|
|
194
|
+
columns,
|
|
195
|
+
config
|
|
196
|
+
}) => {
|
|
197
|
+
const namePath = Array.isArray(name) ? name : [name];
|
|
198
|
+
const list = form.getFieldValue(namePath) || [];
|
|
199
|
+
const errorMap = {};
|
|
200
|
+
let firstErrorPath = null;
|
|
201
|
+
let firstErrorRowKey = null;
|
|
202
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
203
|
+
const rowData = list[index];
|
|
204
|
+
// 行可能为空位(单行编辑增删残留),跳过
|
|
205
|
+
if (!rowData) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const rowKey = String(rowData.rowKey ?? index);
|
|
209
|
+
for (const column of columns) {
|
|
210
|
+
const built = buildCellRules({
|
|
211
|
+
column,
|
|
212
|
+
rowData,
|
|
213
|
+
index,
|
|
214
|
+
form,
|
|
215
|
+
name: namePath,
|
|
216
|
+
config
|
|
217
|
+
});
|
|
218
|
+
if (!built) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// validateFirst=true:成功 resolve([]),首个失败 reject([{ errors, rule }])
|
|
223
|
+
// eslint-disable-next-line no-await-in-loop
|
|
224
|
+
const ruleErrors = await validateRules(built.namePath, built.value, built.rules, {
|
|
225
|
+
validateMessages: config?.validateMessages
|
|
226
|
+
}, true, {
|
|
227
|
+
label: built.label
|
|
228
|
+
}).then(() => [], err => Array.isArray(err) ? err : []);
|
|
229
|
+
const messages = [];
|
|
230
|
+
ruleErrors.forEach(({
|
|
231
|
+
errors = [],
|
|
232
|
+
rule
|
|
233
|
+
}) => {
|
|
234
|
+
// warningOnly 仅警告,不计入阻断性错误
|
|
235
|
+
if (!rule?.warningOnly) {
|
|
236
|
+
messages.push(...errors);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
if (messages.length) {
|
|
240
|
+
if (!errorMap[rowKey]) {
|
|
241
|
+
errorMap[rowKey] = {};
|
|
242
|
+
}
|
|
243
|
+
errorMap[rowKey][built.cellKey] = messages;
|
|
244
|
+
if (!firstErrorPath) {
|
|
245
|
+
firstErrorPath = built.namePath;
|
|
246
|
+
firstErrorRowKey = rowKey;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
hasError: !!firstErrorPath,
|
|
253
|
+
errorMap,
|
|
254
|
+
firstErrorPath,
|
|
255
|
+
firstErrorRowKey
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 外部错误存储:以 rowKey + cellKey 为键持久化真实报错文案。
|
|
261
|
+
* 它是「报错常驻」的真实来源——脱离 antd Field 实体生命周期,
|
|
262
|
+
* 行卸载后仍保留,重新挂载时回填显示。
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
export const createErrorStore = () => {
|
|
266
|
+
const map = new Map();
|
|
267
|
+
return {
|
|
268
|
+
get: (rowKey, cellKey) => map.get(String(rowKey))?.[cellKey],
|
|
269
|
+
getRow: rowKey => map.get(String(rowKey)),
|
|
270
|
+
setAll: errorMap => {
|
|
271
|
+
map.clear();
|
|
272
|
+
Object.keys(errorMap || {}).forEach(rowKey => {
|
|
273
|
+
map.set(rowKey, errorMap[rowKey]);
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
clearCell: (rowKey, cellKey) => {
|
|
277
|
+
const row = map.get(String(rowKey));
|
|
278
|
+
if (row && cellKey in row) {
|
|
279
|
+
delete row[cellKey];
|
|
280
|
+
if (Object.keys(row).length === 0) {
|
|
281
|
+
map.delete(String(rowKey));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
clearAll: () => map.clear(),
|
|
286
|
+
isEmpty: () => map.size === 0
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* 统一校验入口:对全量数据跑真实规则,写入 errorStore,返回是否有错与首个错误行索引。
|
|
291
|
+
* 供隐藏聚合校验字段在 form.validateFields() 时调用,从而覆盖视口外未挂载的行。
|
|
292
|
+
*/
|
|
293
|
+
export const runUnifiedValidation = async ({
|
|
294
|
+
form,
|
|
295
|
+
name,
|
|
296
|
+
columns,
|
|
297
|
+
config,
|
|
298
|
+
errorStore
|
|
299
|
+
}) => {
|
|
300
|
+
const {
|
|
301
|
+
hasError,
|
|
302
|
+
errorMap,
|
|
303
|
+
firstErrorPath,
|
|
304
|
+
firstErrorRowKey
|
|
305
|
+
} = await validateAllRows({
|
|
306
|
+
form,
|
|
307
|
+
name,
|
|
308
|
+
columns,
|
|
309
|
+
config
|
|
310
|
+
});
|
|
311
|
+
errorStore.setAll(errorMap);
|
|
312
|
+
const namePath = Array.isArray(name) ? name : [name];
|
|
313
|
+
const firstErrorIndex = firstErrorPath && firstErrorPath.length > namePath.length ? Number(firstErrorPath[namePath.length]) : null;
|
|
314
|
+
return {
|
|
315
|
+
hasError,
|
|
316
|
+
firstErrorIndex,
|
|
317
|
+
firstErrorRowKey
|
|
318
|
+
};
|
|
319
|
+
};
|
|
@@ -75,57 +75,57 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
75
75
|
confirm?: boolean | import("antd").ModalFuncProps | import("../../../render/propsType").FunctionArgs<any, boolean | import("antd").ModalFuncProps>;
|
|
76
76
|
show?: boolean | ReactiveFunction<any, boolean>;
|
|
77
77
|
component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
isView?: boolean;
|
|
79
|
+
style?: React.CSSProperties;
|
|
80
|
+
children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
|
|
81
|
+
className?: string;
|
|
82
|
+
hidden?: boolean;
|
|
83
|
+
id?: string;
|
|
84
|
+
onReset?: () => void;
|
|
85
|
+
validateTrigger?: string | false | string[];
|
|
86
|
+
preserve?: boolean;
|
|
82
87
|
trim?: boolean;
|
|
83
|
-
upperCase?: boolean;
|
|
84
88
|
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
85
|
-
|
|
86
|
-
shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
|
|
87
|
-
colon?: boolean;
|
|
88
|
-
htmlFor?: string;
|
|
89
|
+
clearNotShow?: boolean;
|
|
89
90
|
labelAlign?: import("antd/es/form/interface").FormLabelAlign;
|
|
91
|
+
prefixCls?: string;
|
|
92
|
+
colon?: boolean;
|
|
93
|
+
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
90
94
|
labelCol?: import("antd").ColProps;
|
|
95
|
+
wrapperCol?: import("antd").ColProps;
|
|
96
|
+
rootClassName?: string;
|
|
97
|
+
status?: "" | "validating" | "warning" | "error" | "success";
|
|
91
98
|
vertical?: boolean;
|
|
92
|
-
|
|
99
|
+
htmlFor?: string;
|
|
93
100
|
getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
|
|
101
|
+
shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
|
|
94
102
|
trigger?: string;
|
|
95
|
-
validateTrigger?: string | false | string[];
|
|
96
103
|
validateDebounce?: number;
|
|
97
104
|
valuePropName?: string;
|
|
105
|
+
getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
|
|
98
106
|
messageVariables?: Record<string, string>;
|
|
99
107
|
initialValue?: any;
|
|
100
|
-
onReset?: () => void;
|
|
101
108
|
onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
|
|
102
|
-
preserve?: boolean;
|
|
103
109
|
isListField?: boolean;
|
|
104
110
|
isList?: boolean;
|
|
105
|
-
prefixCls?: string;
|
|
106
111
|
noStyle?: boolean;
|
|
107
|
-
style?: React.CSSProperties;
|
|
108
|
-
className?: string;
|
|
109
|
-
rootClassName?: string;
|
|
110
|
-
id?: string;
|
|
111
112
|
hasFeedback?: boolean | {
|
|
112
113
|
icons: import("antd/es/form/FormItem").FeedbackIcons;
|
|
113
114
|
};
|
|
114
|
-
validateStatus?: "" | "
|
|
115
|
-
hidden?: boolean;
|
|
116
|
-
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
117
|
-
wrapperCol?: import("antd").ColProps;
|
|
118
|
-
status?: "" | "success" | "warning" | "error" | "validating";
|
|
115
|
+
validateStatus?: "" | "validating" | "warning" | "error" | "success";
|
|
119
116
|
help?: React.ReactNode;
|
|
120
117
|
fieldId?: string;
|
|
121
118
|
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
122
|
-
|
|
119
|
+
switchValue?: [any, any];
|
|
123
120
|
viewRender?: (value: any, record: any, { form, index, namePath, }: {
|
|
124
121
|
[key: string]: any;
|
|
125
122
|
form: FormInstance<any>;
|
|
126
123
|
index?: number;
|
|
127
124
|
}) => string | React.ReactElement<any, any>;
|
|
128
125
|
viewType?: import("../../../render/propsType").ViewType;
|
|
126
|
+
upperCase?: boolean;
|
|
127
|
+
toISOString?: boolean;
|
|
128
|
+
toCSTString?: boolean;
|
|
129
129
|
desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
|
|
130
130
|
name: any;
|
|
131
131
|
dependencies: any[];
|
|
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
141
141
|
* 创建组件属性
|
|
142
142
|
*/
|
|
143
143
|
export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
|
|
144
|
-
componentProps: import("lodash").Omit<any, "
|
|
144
|
+
componentProps: import("lodash").Omit<any, "clearNotShow" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "precision">;
|
|
145
145
|
formItemTransform: {
|
|
146
146
|
getValueProps: any;
|
|
147
147
|
normalize: any;
|
|
@@ -10,7 +10,7 @@ import locale from "../../../locale";
|
|
|
10
10
|
import { useProConfig } from "../../../ProConfigProvider";
|
|
11
11
|
import Container from "../../../ProForm/components/Container";
|
|
12
12
|
import AdaptiveTooltip from "../AdaptiveTooltip";
|
|
13
|
-
import { getFlatTreeData } from "../../utils";
|
|
13
|
+
import { getFlatTreeData, restoreCodeNameLabel } from "../../utils";
|
|
14
14
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
15
15
|
const {
|
|
16
16
|
SHOW_PARENT
|
|
@@ -629,7 +629,8 @@ export const ProTreeSelect = (props, ref) => {
|
|
|
629
629
|
if (props?.labelInValue) {
|
|
630
630
|
result = getLabelByValue(_selectList, newVal);
|
|
631
631
|
}
|
|
632
|
-
|
|
632
|
+
// showCodeName 仅影响展示,回调返回的 option 需还原原始 label
|
|
633
|
+
const options = restoreCodeNameLabel(findTreeNode(_selectList, extra?.triggerValue), showCodeName);
|
|
633
634
|
onChange && onChange(result, options, extra);
|
|
634
635
|
// 重置搜索
|
|
635
636
|
showSearch && searchTreeEvent('');
|
package/es/ProTree/utils.d.ts
CHANGED
|
@@ -35,6 +35,15 @@ export declare function filterCheckedNodes(data: any, checkedKeys: any, searchSt
|
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
37
|
export declare function getChildrenKeys(node: ProTreeDataType, childrenKeys: string[], fieldNames: ProTreeFieldNamesType, type: 'treeClose' | 'treeCheck'): void;
|
|
38
|
+
/**
|
|
39
|
+
* 还原 showCodeName 合并到 label 上的 `${value}-` 前缀
|
|
40
|
+
* showCodeName 仅影响展示,回调返回的 option 应保持原始 label
|
|
41
|
+
* 注意:此处 option 已是标准格式(label, value)
|
|
42
|
+
* @param option 单个或数组形式的选项(标准格式)
|
|
43
|
+
* @param showCodeName 是否开启了 code-name 展示
|
|
44
|
+
* @returns 还原 label 后的新对象/数组(不可变)
|
|
45
|
+
*/
|
|
46
|
+
export declare function restoreCodeNameLabel<T extends Record<string, any>>(option: T | T[], showCodeName?: boolean): T | T[];
|
|
38
47
|
/**
|
|
39
48
|
* 如果默认全开展那么返回所有key,否则返回空[]
|
|
40
49
|
* @param isExpand 是否全展开
|
package/es/ProTree/utils.js
CHANGED
|
@@ -160,6 +160,37 @@ export function getChildrenKeys(node, childrenKeys, fieldNames, type) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* 还原 showCodeName 合并到 label 上的 `${value}-` 前缀
|
|
165
|
+
* showCodeName 仅影响展示,回调返回的 option 应保持原始 label
|
|
166
|
+
* 注意:此处 option 已是标准格式(label, value)
|
|
167
|
+
* @param option 单个或数组形式的选项(标准格式)
|
|
168
|
+
* @param showCodeName 是否开启了 code-name 展示
|
|
169
|
+
* @returns 还原 label 后的新对象/数组(不可变)
|
|
170
|
+
*/
|
|
171
|
+
export function restoreCodeNameLabel(option, showCodeName) {
|
|
172
|
+
if (!showCodeName || !option) {
|
|
173
|
+
return option;
|
|
174
|
+
}
|
|
175
|
+
const restore = node => {
|
|
176
|
+
const {
|
|
177
|
+
label,
|
|
178
|
+
value
|
|
179
|
+
} = node;
|
|
180
|
+
if (typeof label === 'string') {
|
|
181
|
+
const prefix = `${value}-`;
|
|
182
|
+
if (label.startsWith(prefix)) {
|
|
183
|
+
return {
|
|
184
|
+
...node,
|
|
185
|
+
label: label.slice(prefix.length)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return node;
|
|
190
|
+
};
|
|
191
|
+
return Array.isArray(option) ? option.map(restore) : restore(option);
|
|
192
|
+
}
|
|
193
|
+
|
|
163
194
|
/**
|
|
164
195
|
* 如果默认全开展那么返回所有key,否则返回空[]
|
|
165
196
|
* @param isExpand 是否全展开
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zat-design/sisyphus-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"es",
|
|
@@ -163,7 +163,6 @@
|
|
|
163
163
|
"husky": "^9.0.0",
|
|
164
164
|
"jest-canvas-mock": "^2.5.2",
|
|
165
165
|
"lint-staged": "^10.0.0",
|
|
166
|
-
"mini-css-extract-plugin": "^2.9.4",
|
|
167
166
|
"minimatch": "^9.0.5",
|
|
168
167
|
"mockjs": "^1.0.0",
|
|
169
168
|
"patch-package": "^8.0.1",
|