zy-react-library 1.0.78 → 1.0.80
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/components/FormBuilder/FormBuilder.js +1 -1
- package/components/FormBuilder/FormItemsRenderer.d.ts +1 -1
- package/components/FormBuilder/FormItemsRenderer.js +63 -64
- package/components/HiddenInfo/gwj/index.js +9 -7
- package/components/SelectTree/Basic/index.d.ts +2 -0
- package/components/SelectTree/Basic/index.js +6 -2
- package/hooks/useTable/index.js +1 -1
- package/package.json +1 -1
- package/utils/index.d.ts +19 -0
- package/utils/index.js +27 -0
|
@@ -61,7 +61,7 @@ export interface FormOption {
|
|
|
61
61
|
tip?: ReactNode;
|
|
62
62
|
/** 是否隐藏,默认 false,支持函数动态计算 */
|
|
63
63
|
hidden?: boolean | ((formValues: FormValues) => boolean);
|
|
64
|
-
/**
|
|
64
|
+
/** 是否自定义渲染,完全交给外部控制渲染,默认 false */
|
|
65
65
|
customizeRender?: boolean;
|
|
66
66
|
/** 选项数据(用于 select、radio、checkbox) */
|
|
67
67
|
items?: OptionItem[];
|
|
@@ -135,8 +135,8 @@ const FormItemsRenderer = ({
|
|
|
135
135
|
|
|
136
136
|
// 获取key
|
|
137
137
|
const getKey = (option) => {
|
|
138
|
-
return option.key || option.name
|
|
139
|
-
}
|
|
138
|
+
return option.key || option.name;
|
|
139
|
+
};
|
|
140
140
|
|
|
141
141
|
// 渲染表单控件
|
|
142
142
|
const renderFormControl = (option) => {
|
|
@@ -272,6 +272,23 @@ const FormItemsRenderer = ({
|
|
|
272
272
|
return (
|
|
273
273
|
<>
|
|
274
274
|
{options.map((option, index) => {
|
|
275
|
+
// 列数
|
|
276
|
+
const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : option.span ?? span;
|
|
277
|
+
const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);
|
|
278
|
+
const itemWrapperCol = option.wrapperCol ?? { span: 24 - itemLabelCol.span };
|
|
279
|
+
|
|
280
|
+
// 使用 style 控制显示/隐藏
|
|
281
|
+
const style = collapse && index >= 3 ? { display: "none" } : undefined;
|
|
282
|
+
|
|
283
|
+
// 如果是 customizeRender 类型,完全交给外部控制渲染
|
|
284
|
+
if (option.customizeRender) {
|
|
285
|
+
return (
|
|
286
|
+
<Col key={getKey(option) || index} span={itemSpan} style={style}>
|
|
287
|
+
{option.render}
|
|
288
|
+
</Col>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
275
292
|
// 如果是 onlyForLabel 类型,不渲染任何UI,只在表单中保存数据
|
|
276
293
|
if (option.onlyForLabel) {
|
|
277
294
|
return (
|
|
@@ -286,14 +303,6 @@ const FormItemsRenderer = ({
|
|
|
286
303
|
);
|
|
287
304
|
}
|
|
288
305
|
|
|
289
|
-
// 列数
|
|
290
|
-
const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : option.span ?? span;
|
|
291
|
-
const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);
|
|
292
|
-
const itemWrapperCol = option.wrapperCol ?? { span: 24 - itemLabelCol.span };
|
|
293
|
-
|
|
294
|
-
// 使用 style 控制显示/隐藏
|
|
295
|
-
const style = collapse && index >= 3 ? { display: "none" } : undefined;
|
|
296
|
-
|
|
297
306
|
// 如果是分割线
|
|
298
307
|
if (option.render === FORM_ITEM_RENDER_ENUM.DIVIDER) {
|
|
299
308
|
return (
|
|
@@ -306,43 +315,39 @@ const FormItemsRenderer = ({
|
|
|
306
315
|
// 如果配置了 shouldUpdate 或 dependencies,使用 Form.Item 的联动机制
|
|
307
316
|
if ((option.shouldUpdate ?? option.dependencies) || (option?.componentProps?.shouldUpdate ?? option?.componentProps?.dependencies)) {
|
|
308
317
|
return (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
);
|
|
343
|
-
}}
|
|
344
|
-
</Form.Item>
|
|
345
|
-
)
|
|
318
|
+
<Form.Item
|
|
319
|
+
key={getKey(option) || index}
|
|
320
|
+
noStyle
|
|
321
|
+
preserve={false}
|
|
322
|
+
shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
|
|
323
|
+
dependencies={option.dependencies || option?.componentProps?.dependencies}
|
|
324
|
+
>
|
|
325
|
+
{() => {
|
|
326
|
+
// 支持动态计算 hidden
|
|
327
|
+
const hidden = typeof option.hidden === "function"
|
|
328
|
+
? option.hidden(getFormValues())
|
|
329
|
+
: (option.hidden ?? false);
|
|
330
|
+
|
|
331
|
+
if (hidden)
|
|
332
|
+
return null;
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<Col key={getKey(option) || index} span={itemSpan} style={style}>
|
|
336
|
+
<Form.Item
|
|
337
|
+
name={option.name}
|
|
338
|
+
label={renderLabel(option)}
|
|
339
|
+
rules={getRules(option)}
|
|
340
|
+
labelCol={itemLabelCol}
|
|
341
|
+
wrapperCol={itemWrapperCol}
|
|
342
|
+
preserve={false}
|
|
343
|
+
{...getFormItemProps(option)}
|
|
344
|
+
>
|
|
345
|
+
{renderFormControl(option)}
|
|
346
|
+
</Form.Item>
|
|
347
|
+
</Col>
|
|
348
|
+
);
|
|
349
|
+
}}
|
|
350
|
+
</Form.Item>
|
|
346
351
|
);
|
|
347
352
|
}
|
|
348
353
|
|
|
@@ -357,23 +362,17 @@ const FormItemsRenderer = ({
|
|
|
357
362
|
|
|
358
363
|
return (
|
|
359
364
|
<Col key={getKey(option) || index} span={itemSpan} style={style}>
|
|
360
|
-
|
|
361
|
-
option.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
{...getFormItemProps(option)}
|
|
372
|
-
>
|
|
373
|
-
{renderFormControl(option)}
|
|
374
|
-
</Form.Item>
|
|
375
|
-
)
|
|
376
|
-
}
|
|
365
|
+
<Form.Item
|
|
366
|
+
name={option.name}
|
|
367
|
+
label={renderLabel(option)}
|
|
368
|
+
rules={getRules(option)}
|
|
369
|
+
labelCol={itemLabelCol}
|
|
370
|
+
wrapperCol={itemWrapperCol}
|
|
371
|
+
preserve={false}
|
|
372
|
+
{...getFormItemProps(option)}
|
|
373
|
+
>
|
|
374
|
+
{renderFormControl(option)}
|
|
375
|
+
</Form.Item>
|
|
377
376
|
</Col>
|
|
378
377
|
);
|
|
379
378
|
})}
|
|
@@ -90,15 +90,17 @@ function HiddenInfo(props) {
|
|
|
90
90
|
{ label: "隐患状态", children: getLabelName({ list: HIDDEN_STATE_ENUM, status: info.state }) },
|
|
91
91
|
{ label: "隐患描述", children: info.hiddenDesc },
|
|
92
92
|
{ label: "隐患部位", children: info.hiddenPart },
|
|
93
|
-
...(
|
|
93
|
+
...(
|
|
94
|
+
(info.source === 2 || info.source === 3) && (info.hiddenCheckListCO && Object.keys(info.hiddenCheckListCO).length > 0)
|
|
94
95
|
? [
|
|
95
|
-
{ label: "风险点(单元)", children:
|
|
96
|
-
{ label: "辨识部位", children:
|
|
97
|
-
{ label: "存在风险", children:
|
|
98
|
-
{ label: "风险分级", children:
|
|
99
|
-
{ label: "隐患清单", children:
|
|
96
|
+
{ label: "风险点(单元)", children: info.hiddenCheckListCO.listRiskPoints },
|
|
97
|
+
{ label: "辨识部位", children: info.hiddenCheckListCO.identifiedLocations },
|
|
98
|
+
{ label: "存在风险", children: info.hiddenCheckListCO.existingRisks },
|
|
99
|
+
{ label: "风险分级", children: info.hiddenCheckListCO.riskLevel },
|
|
100
|
+
{ label: "隐患清单", children: info.hiddenCheckListCO.listName },
|
|
100
101
|
]
|
|
101
|
-
: []
|
|
102
|
+
: []
|
|
103
|
+
),
|
|
102
104
|
{
|
|
103
105
|
label: "隐患上报位置(经纬度)",
|
|
104
106
|
children: [info.longitude && `经度:${info.longitude}`, info.latitude && `纬度:${info.latitude}`].filter(Boolean).join(" "),
|
|
@@ -23,6 +23,8 @@ export interface BasicSelectTreeProps extends Omit<TreeSelectProps, "fieldNames"
|
|
|
23
23
|
onGetLabel?: (label: string) => void;
|
|
24
24
|
/** 获取数据 */
|
|
25
25
|
onGetData?: (data: Record<string, any>[], processedData: Record<string, any>[]) => void;
|
|
26
|
+
/** 是否只允许选择最后一级,默认 false */
|
|
27
|
+
onlyLastLevel?: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TreeSelect } from "antd";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
import { getTreeNodePaths, processTreeDataByLevel } from "../../../utils";
|
|
3
|
+
import { getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 基础下拉树组件(不建议直接使用此组件,二次继承使用)
|
|
@@ -18,11 +18,12 @@ function BasicSelectTree(props) {
|
|
|
18
18
|
idKey = "id",
|
|
19
19
|
childrenKey = "children",
|
|
20
20
|
level,
|
|
21
|
+
onlyLastLevel = false,
|
|
21
22
|
...restProps
|
|
22
23
|
} = props;
|
|
23
24
|
|
|
24
25
|
// 根据 level 处理树数据
|
|
25
|
-
|
|
26
|
+
let processedTreeData = level
|
|
26
27
|
? processTreeDataByLevel({
|
|
27
28
|
data: treeData,
|
|
28
29
|
level,
|
|
@@ -31,6 +32,9 @@ function BasicSelectTree(props) {
|
|
|
31
32
|
})
|
|
32
33
|
: treeData;
|
|
33
34
|
|
|
35
|
+
// 根据 onlyLastLevel 处理树数据
|
|
36
|
+
processedTreeData = processTreeDataForOnlyLastLevel({ data: processedTreeData, childrenKey, onlyLastLevel });
|
|
37
|
+
|
|
34
38
|
const handleChange = (value, label, extra) => {
|
|
35
39
|
if (value) {
|
|
36
40
|
const parentNodes = getTreeNodePaths({
|
package/hooks/useTable/index.js
CHANGED
|
@@ -115,7 +115,7 @@ function useTable(service, options) {
|
|
|
115
115
|
usePagination = true,
|
|
116
116
|
defaultType = "advance",
|
|
117
117
|
defaultCurrent = 1,
|
|
118
|
-
defaultPageSize =
|
|
118
|
+
defaultPageSize = 20,
|
|
119
119
|
defaultPagination = { current: defaultCurrent, pageSize: defaultPageSize },
|
|
120
120
|
...restRestOptions
|
|
121
121
|
} = restOptions;
|
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
|
@@ -301,3 +301,22 @@ export function processTreeDataByLevel(
|
|
|
301
301
|
/** 子节点 */
|
|
302
302
|
[key: string]: any;
|
|
303
303
|
}[];
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 根据 onlyLastLevel 属性处理树数据,添加 selectable 属性控制节点是否可选择
|
|
307
|
+
*/
|
|
308
|
+
export function processTreeDataForOnlyLastLevel(
|
|
309
|
+
options: {
|
|
310
|
+
/** 树形数据 */
|
|
311
|
+
data: any[];
|
|
312
|
+
/** 子节点字段名 */
|
|
313
|
+
childrenKey: string;
|
|
314
|
+
/** 是否只允许选择最后一级 */
|
|
315
|
+
onlyLastLevel?: boolean;
|
|
316
|
+
},
|
|
317
|
+
): {
|
|
318
|
+
/** 是否允许选择 */
|
|
319
|
+
selectable: boolean;
|
|
320
|
+
/** 子节点 */
|
|
321
|
+
[key: string]: any;
|
|
322
|
+
}[];
|
package/utils/index.js
CHANGED
|
@@ -462,6 +462,33 @@ export const processTreeDataByLevel = (options) => {
|
|
|
462
462
|
});
|
|
463
463
|
};
|
|
464
464
|
|
|
465
|
+
/**
|
|
466
|
+
* 根据 onlyLastLevel 属性处理树数据,添加 selectable 属性控制节点是否可选择
|
|
467
|
+
*/
|
|
468
|
+
export const processTreeDataForOnlyLastLevel = (options) => {
|
|
469
|
+
const { data, childrenKey, onlyLastLevel = false } = options;
|
|
470
|
+
if (!onlyLastLevel)
|
|
471
|
+
return data;
|
|
472
|
+
|
|
473
|
+
return data.map((item) => {
|
|
474
|
+
// 检查是否有子节点
|
|
475
|
+
const hasChildren = item[childrenKey] && item[childrenKey].length > 0;
|
|
476
|
+
|
|
477
|
+
// 如果有子节点,则不可选择
|
|
478
|
+
const processedItem = {
|
|
479
|
+
...item,
|
|
480
|
+
selectable: !hasChildren,
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// 递归处理子节点
|
|
484
|
+
if (hasChildren) {
|
|
485
|
+
processedItem[childrenKey] = processTreeDataForOnlyLastLevel({ data: item[childrenKey], childrenKey, onlyLastLevel });
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return processedItem;
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
|
|
465
492
|
/**
|
|
466
493
|
* 获取文件url
|
|
467
494
|
*/
|