zy-react-library 1.1.1 → 1.1.3

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.
Files changed (75) hide show
  1. package/README.md +5 -1
  2. package/components/Cascader/Area/index.js +1 -20
  3. package/components/Cascader/Basic/index.js +1 -64
  4. package/components/Cascader/Dictionary/index.js +1 -42
  5. package/components/Cascader/Industry/index.js +1 -20
  6. package/components/Editor/index.js +1 -102
  7. package/components/FormBuilder/FormBuilder.js +1 -87
  8. package/components/FormBuilder/FormItemsRenderer.js +1 -591
  9. package/components/FormBuilder/index.js +1 -3
  10. package/components/HeaderBack/index.js +1 -37
  11. package/components/HiddenInfo/gwj/index.js +1 -518
  12. package/components/Icon/AddIcon/index.js +1 -9
  13. package/components/Icon/BackIcon/index.js +1 -9
  14. package/components/Icon/DeleteIcon/index.js +1 -9
  15. package/components/Icon/DownloadIcon/index.js +1 -9
  16. package/components/Icon/EditIcon/index.js +1 -9
  17. package/components/Icon/ExportIcon/index.js +1 -9
  18. package/components/Icon/ImportIcon/index.js +1 -9
  19. package/components/Icon/LocationIcon/index.js +1 -9
  20. package/components/Icon/PrintIcon/index.js +1 -9
  21. package/components/Icon/ResetIcon/index.js +1 -9
  22. package/components/Icon/SearchIcon/index.js +1 -9
  23. package/components/Icon/VideoIcon/index.js +1 -9
  24. package/components/Icon/ViewIcon/index.js +1 -9
  25. package/components/ImportFile/index.js +1 -91
  26. package/components/LeftTree/Area/index.js +1 -15
  27. package/components/LeftTree/Basic/index.js +1 -171
  28. package/components/LeftTree/Department/Gwj/index.js +1 -32
  29. package/components/LeftTree/Dictionary/index.js +1 -42
  30. package/components/Map/MapSelector.js +1 -254
  31. package/components/Map/index.js +1 -77
  32. package/components/Page/index.js +1 -50
  33. package/components/Pdf/index.js +1 -134
  34. package/components/PreviewImg/index.js +1 -32
  35. package/components/PreviewPdf/index.js +1 -86
  36. package/components/Search/index.js +1 -141
  37. package/components/Select/Basic/index.js +1 -76
  38. package/components/Select/Dictionary/index.js +1 -42
  39. package/components/Select/Personnel/Gwj/index.js +1 -49
  40. package/components/SelectCreate/index.js +1 -55
  41. package/components/SelectTree/Area/index.js +1 -26
  42. package/components/SelectTree/Basic/index.js +1 -102
  43. package/components/SelectTree/Department/Gwj/index.js +1 -46
  44. package/components/SelectTree/Dictionary/index.js +1 -42
  45. package/components/SelectTree/HiddenLevel/Gwj/index.js +1 -72
  46. package/components/SelectTree/HiddenPart/Gwj/index.js +1 -39
  47. package/components/SelectTree/Industry/index.js +1 -27
  48. package/components/Signature/index.js +1 -94
  49. package/components/Table/index.js +1 -73
  50. package/components/Table/index.less +7 -1
  51. package/components/TooltipPreviewImg/index.js +1 -27
  52. package/components/Upload/index.js +1 -275
  53. package/components/Video/AliPlayer.js +1 -160
  54. package/components/Video/index.js +1 -90
  55. package/css/common.less +4 -0
  56. package/enum/dictionary/index.js +1 -7
  57. package/enum/formItemRender/index.js +1 -37
  58. package/enum/hidden/gwj/index.js +1 -31
  59. package/enum/uploadFile/gwj/index.js +1 -176
  60. package/hooks/useDeleteFile/index.js +1 -101
  61. package/hooks/useDictionary/index.js +1 -66
  62. package/hooks/useDownloadBlob/index.js +1 -79
  63. package/hooks/useDownloadFile/index.js +1 -81
  64. package/hooks/useGetFile/index.js +1 -74
  65. package/hooks/useGetUrlQuery/index.js +1 -16
  66. package/hooks/useGetUserInfo/index.js +1 -49
  67. package/hooks/useIdle/index.js +1 -67
  68. package/hooks/useImportFile/index.js +1 -59
  69. package/hooks/useIsExistenceDuplicateSelection/index.js +1 -20
  70. package/hooks/useTable/index.js +1 -113
  71. package/hooks/useUploadFile/index.js +1 -149
  72. package/hooks/useUrlQueryCriteria/index.js +1 -77
  73. package/package.json +18 -1
  74. package/regular/index.js +1 -61
  75. package/utils/index.js +1 -587
@@ -1,591 +1 @@
1
- import { InfoCircleOutlined } from "@ant-design/icons";
2
- import {
3
- Button,
4
- Checkbox,
5
- Col,
6
- DatePicker,
7
- Divider,
8
- Form,
9
- Input,
10
- InputNumber,
11
- Radio,
12
- Row,
13
- Select,
14
- Tooltip,
15
- } from "antd";
16
- import dayjs from "dayjs";
17
- import { FORM_ITEM_RENDER_ENUM } from "../../enum/formItemRender";
18
-
19
- const { TextArea } = Input;
20
- const { RangePicker } = DatePicker;
21
-
22
- /**
23
- * 表单项渲染器组件
24
- * @param {object} props - 组件属性
25
- * @param {Array} props.options - 表单配置项数组
26
- * @param {object} props.labelCol - label 栅格配置
27
- * @param {number} props.gutter - 栅格间距
28
- * @param {number} props.span - 默认栅格占据列数
29
- * @param {boolean} props.collapse - 是否折叠(仅显示前3项)
30
- * @param {boolean} props.useAutoGenerateRequired - 是否自动生成必填规则
31
- * @param {object} props.initialValues - 初始值
32
- */
33
- const FormItemsRenderer = ({
34
- options,
35
- labelCol,
36
- gutter = 24,
37
- span = 12,
38
- collapse = false,
39
- useAutoGenerateRequired = true,
40
- initialValues,
41
- }) => {
42
- const form = Form.useFormInstance();
43
-
44
- // 获取表单值,优先使用 initialValues
45
- const getFormValues = () => {
46
- const formValues = form.getFieldsValue();
47
- // 如果表单值为空但有 initialValues,则使用 initialValues
48
- if (Object.keys(formValues).length === 0 && initialValues) {
49
- return initialValues;
50
- }
51
- return formValues;
52
- };
53
-
54
- // 获取传给组件的属性
55
- const getComponentProps = (option) => {
56
- return typeof option.componentProps === "function"
57
- ? option.componentProps(getFormValues())
58
- : (option.componentProps || {});
59
- };
60
-
61
- // 获取 Form.List 独有的属性
62
- const getFormListUniqueProps = (option) => {
63
- const defaultProps = {
64
- showAddButton: true,
65
- showRemoveButton: true,
66
- addButtonText: "添加",
67
- removeButtonText: "删除",
68
- options: [],
69
- addDefaultValue: {},
70
- addInsertIndex: undefined,
71
- };
72
-
73
- if (typeof option.formListUniqueProps === "function") {
74
- return {
75
- ...defaultProps,
76
- ...option.formListUniqueProps(getFormValues()),
77
- };
78
- }
79
-
80
- return {
81
- ...defaultProps,
82
- ...(option.formListUniqueProps || {}),
83
- };
84
- };
85
-
86
- // 获取传给formItem的属性
87
- const getFormItemProps = (option) => {
88
- const formItemProps = typeof option.formItemProps === "function"
89
- ? option.formItemProps(getFormValues())
90
- : (option.formItemProps || {});
91
-
92
- // 为日期组件添加特殊处理
93
- if ([
94
- FORM_ITEM_RENDER_ENUM.DATE,
95
- FORM_ITEM_RENDER_ENUM.DATE_MONTH,
96
- FORM_ITEM_RENDER_ENUM.DATE_YEAR,
97
- FORM_ITEM_RENDER_ENUM.DATETIME,
98
- ].includes(option.render)) {
99
- formItemProps.getValueFromEvent = (_, dateString) => dateString;
100
- formItemProps.getValueProps = value => ({ value: value ? dayjs(value) : undefined });
101
- }
102
-
103
- // 为日期周组件添加特殊处理
104
- if ([
105
- FORM_ITEM_RENDER_ENUM.DATE_WEEK,
106
- ].includes(option.render)) {
107
- formItemProps.getValueFromEvent = (_, dateString) => dateString;
108
- formItemProps.getValueProps = value => ({ value: value ? dayjs(value, "YYYY-wo") : undefined });
109
- }
110
-
111
- // 为日期范围组件添加特殊处理
112
- if ([
113
- FORM_ITEM_RENDER_ENUM.DATE_RANGE,
114
- FORM_ITEM_RENDER_ENUM.DATETIME_RANGE,
115
- ].includes(option.render)) {
116
- formItemProps.getValueFromEvent = (_, dateString) => dateString;
117
- formItemProps.getValueProps = value => ({ value: Array.isArray(value) ? value.map(v => v ? dayjs(v) : undefined) : undefined });
118
- }
119
-
120
- return formItemProps;
121
- };
122
-
123
- // 获取items里的value和label字段key
124
- const getItemsFieldKey = (option) => {
125
- return {
126
- valueKey: option?.itemsField?.valueKey || "bianma",
127
- labelKey: option?.itemsField?.labelKey || "name",
128
- };
129
- };
130
-
131
- // 获取 required
132
- const getRequired = (required) => {
133
- // 支持动态计算 required
134
- return typeof required === "function"
135
- ? required(getFormValues())
136
- : (required ?? true);
137
- };
138
-
139
- // 获取验证规则
140
- const getRules = (option) => {
141
- if (option.render === FORM_ITEM_RENDER_ENUM.DIVIDER)
142
- return [];
143
-
144
- const rules = [];
145
-
146
- /** @type {string | Function} */
147
- const render = option.render || FORM_ITEM_RENDER_ENUM.INPUT;
148
- switch (render) {
149
- case FORM_ITEM_RENDER_ENUM.INPUT:
150
- option.useConstraints !== false && rules.push({ max: 50, message: "最多输入50字符" });
151
- break;
152
-
153
- case FORM_ITEM_RENDER_ENUM.TEXTAREA:
154
- option.useConstraints !== false && rules.push({ max: 500, message: "最多输入500字符" });
155
- break;
156
-
157
- case FORM_ITEM_RENDER_ENUM.INPUT_NUMBER:
158
- case FORM_ITEM_RENDER_ENUM.NUMBER:
159
- option.useConstraints !== false && rules.push({ pattern: /^(\d+)(\.\d{1,2})?$/, message: "请输入正确的数字,最多保留两位小数" });
160
- option.useConstraints !== false && rules.push({
161
- validator: (_, value) => {
162
- if (value && Math.abs(Number.parseFloat(value)) > 999999999) {
163
- return Promise.reject("输入数值超出安全范围");
164
- }
165
- return Promise.resolve();
166
- },
167
- });
168
- break;
169
- }
170
-
171
- if (!useAutoGenerateRequired)
172
- return option.rules ? (Array.isArray(option.rules) ? [...option.rules, ...rules] : [option.rules, ...rules]) : rules;
173
-
174
- if (getRequired(option.required)) {
175
- const isBlurTrigger = !option.render || [
176
- FORM_ITEM_RENDER_ENUM.INPUT,
177
- FORM_ITEM_RENDER_ENUM.TEXTAREA,
178
- FORM_ITEM_RENDER_ENUM.INPUT_NUMBER,
179
- FORM_ITEM_RENDER_ENUM.NUMBER,
180
- ].includes(option.render);
181
-
182
- rules.push({ required: true, message: `${isBlurTrigger ? "请输入" : "请选择"}${option.label}` });
183
-
184
- if (option.rules) {
185
- if (Array.isArray(option.rules)) {
186
- rules.push(...option.rules);
187
- }
188
- else {
189
- rules.push(option.rules);
190
- }
191
- }
192
-
193
- return rules;
194
- }
195
-
196
- return option.rules ? (Array.isArray(option.rules) ? [...option.rules, ...rules] : [option.rules, ...rules]) : rules;
197
- };
198
-
199
- // 获取key
200
- const getKey = (option) => {
201
- return option.key || option.name;
202
- };
203
-
204
- // 使用 style 控制显示/隐藏
205
- const getStyle = (index) => {
206
- return collapse && index >= 3 ? { display: "none" } : undefined;
207
- };
208
-
209
- // 列数
210
- const getCol = (option) => {
211
- const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : (option.span ?? span);
212
- const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);
213
- const itemWrapperCol = option.wrapperCol ?? { span: 24 - itemLabelCol.span };
214
- return { span: itemSpan, labelCol: itemLabelCol, wrapperCol: itemWrapperCol };
215
- };
216
-
217
- // 获取 hidden
218
- const getHidden = (hidden) => {
219
- // 支持动态计算 hidden
220
- return typeof hidden === "function"
221
- ? hidden(getFormValues())
222
- : (hidden ?? false);
223
- };
224
-
225
- // 获取 listOptions
226
- const getListOptions = (listOptions, field, fieldIndex, add, remove, move) => {
227
- return typeof listOptions === "function"
228
- ? listOptions(field, fieldIndex, { field, fieldIndex, add, remove, move })
229
- : (listOptions ?? []);
230
- };
231
-
232
- // 渲染表单控件
233
- const renderFormControl = (option) => {
234
- const componentProps = getComponentProps(option);
235
- const itemsFieldKey = getItemsFieldKey(option);
236
- /** @type {string | Function} */
237
- const render = option.render || FORM_ITEM_RENDER_ENUM.INPUT;
238
- const placeholder = option.placeholder || `请${[FORM_ITEM_RENDER_ENUM.INPUT, FORM_ITEM_RENDER_ENUM.TEXTAREA, FORM_ITEM_RENDER_ENUM.INPUT_NUMBER, FORM_ITEM_RENDER_ENUM.NUMBER].includes(render) ? "输入" : "选择"}${option.label}`;
239
-
240
- switch (render) {
241
- case FORM_ITEM_RENDER_ENUM.INPUT:
242
- return <Input placeholder={placeholder} maxLength={50} {...componentProps} />;
243
-
244
- case FORM_ITEM_RENDER_ENUM.TEXTAREA:
245
- return <TextArea placeholder={placeholder} maxLength={500} showCount={true} rows={3} {...componentProps} />;
246
-
247
- case FORM_ITEM_RENDER_ENUM.INPUT_NUMBER:
248
- case FORM_ITEM_RENDER_ENUM.NUMBER:
249
- return <InputNumber placeholder={placeholder} style={{ width: "100%" }} {...componentProps} />;
250
-
251
- case FORM_ITEM_RENDER_ENUM.SELECT:
252
- return (
253
- <Select placeholder={placeholder} showSearch allowClear optionFilterProp="children" {...componentProps}>
254
- {(option.items || []).map((item) => {
255
- const value = item[itemsFieldKey.valueKey];
256
- const label = item[typeof itemsFieldKey.labelKey === "function" ? itemsFieldKey.labelKey(item) : itemsFieldKey.labelKey];
257
- return (
258
- <Select.Option key={value} value={value}>
259
- {label}
260
- </Select.Option>
261
- );
262
- })}
263
- </Select>
264
- );
265
-
266
- case FORM_ITEM_RENDER_ENUM.RADIO:
267
- return (
268
- <Radio.Group {...componentProps}>
269
- {(option.items || []).map((item) => {
270
- const value = item[itemsFieldKey.valueKey];
271
- const label = item[typeof itemsFieldKey.labelKey === "function" ? itemsFieldKey.labelKey(item) : itemsFieldKey.labelKey];
272
- return (
273
- <Radio key={value} value={value}>
274
- {label}
275
- </Radio>
276
- );
277
- })}
278
- </Radio.Group>
279
- );
280
-
281
- case FORM_ITEM_RENDER_ENUM.CHECKBOX:
282
- return (
283
- <Checkbox.Group {...componentProps}>
284
- {(option.items || []).map((item) => {
285
- const value = item[itemsFieldKey.valueKey];
286
- const label = item[typeof itemsFieldKey.labelKey === "function" ? itemsFieldKey.labelKey(item) : itemsFieldKey.labelKey];
287
- return (
288
- <Checkbox key={value} value={value}>
289
- {label}
290
- </Checkbox>
291
- );
292
- })}
293
- </Checkbox.Group>
294
- );
295
-
296
- case FORM_ITEM_RENDER_ENUM.DATE:
297
- return <DatePicker placeholder={placeholder} format="YYYY-MM-DD" style={{ width: "100%" }} {...componentProps} />;
298
-
299
- case FORM_ITEM_RENDER_ENUM.DATE_MONTH:
300
- return (
301
- <DatePicker
302
- picker="month"
303
- placeholder={placeholder}
304
- format="YYYY-MM"
305
- style={{ width: "100%" }}
306
- {...componentProps}
307
- />
308
- );
309
-
310
- case FORM_ITEM_RENDER_ENUM.DATE_YEAR:
311
- return (
312
- <DatePicker
313
- picker="year"
314
- placeholder={placeholder}
315
- format="YYYY"
316
- style={{ width: "100%" }}
317
- {...componentProps}
318
- />
319
- );
320
-
321
- case FORM_ITEM_RENDER_ENUM.DATE_WEEK:
322
- return (
323
- <DatePicker
324
- picker="week"
325
- placeholder={placeholder}
326
- format="YYYY-wo"
327
- style={{ width: "100%" }}
328
- {...componentProps}
329
- />
330
- );
331
-
332
- case FORM_ITEM_RENDER_ENUM.DATE_RANGE:
333
- return (
334
- <RangePicker
335
- placeholder={[`请选择开始${option.label}`, `请选择结束${option.label}`]}
336
- format="YYYY-MM-DD"
337
- style={{ width: "100%" }}
338
- {...componentProps}
339
- />
340
- );
341
-
342
- case FORM_ITEM_RENDER_ENUM.DATETIME:
343
- return (
344
- <DatePicker
345
- showTime
346
- placeholder={placeholder}
347
- format="YYYY-MM-DD HH:mm:ss"
348
- style={{ width: "100%" }}
349
- {...componentProps}
350
- />
351
- );
352
-
353
- case FORM_ITEM_RENDER_ENUM.DATETIME_RANGE:
354
- return (
355
- <RangePicker
356
- showTime
357
- placeholder={[`请选择开始${option.label}`, `请选择结束${option.label}`]}
358
- format="YYYY-MM-DD HH:mm:ss"
359
- style={{ width: "100%" }}
360
- {...componentProps}
361
- />
362
- );
363
-
364
- case FORM_ITEM_RENDER_ENUM.DIVIDER:
365
- return null;
366
-
367
- default:
368
- return render;
369
- }
370
- };
371
-
372
- // 渲染 label(带提示)
373
- const renderLabel = (option) => {
374
- if (!option.tip)
375
- return option.label;
376
-
377
- return (
378
- <>
379
- {option.label}
380
- <Tooltip title={option.tip}>
381
- <InfoCircleOutlined style={{ marginLeft: 4, fontSize: 12 }} />
382
- </Tooltip>
383
- </>
384
- );
385
- };
386
-
387
- // 渲染普通表单项
388
- const renderFormItem = ({ option, style, col, index }) => {
389
- if (getHidden(option.hidden))
390
- return null;
391
-
392
- return (
393
- <Col key={getKey(option) || index} span={col.span} style={style}>
394
- <Form.Item
395
- name={option.name}
396
- label={renderLabel(option)}
397
- rules={getRules(option)}
398
- labelCol={col.labelCol}
399
- wrapperCol={col.wrapperCol}
400
- preserve={false}
401
- {...getFormItemProps(option)}
402
- >
403
- {renderFormControl(option)}
404
- </Form.Item>
405
- </Col>
406
- );
407
- };
408
-
409
- // 渲染特殊类型的表单项
410
- const renderOtherTypeItem = ({ option, style, col, index }) => {
411
- const componentProps = getComponentProps(option);
412
-
413
- // 如果是 customizeRender 类型,完全交给外部控制渲染
414
- if (option.customizeRender) {
415
- return (
416
- <Col key={getKey(option) || index} span={col.span} style={style}>
417
- {option.render}
418
- </Col>
419
- );
420
- }
421
-
422
- // 如果是 onlyForLabel 类型,不渲染任何UI,只在表单中保存数据
423
- if (option.onlyForLabel) {
424
- return (
425
- <Form.Item
426
- key={getKey(option) || index}
427
- name={option.name}
428
- noStyle
429
- preserve={false}
430
- >
431
- <input type="hidden" />
432
- </Form.Item>
433
- );
434
- }
435
-
436
- // 如果是分割线
437
- if (option.render === FORM_ITEM_RENDER_ENUM.DIVIDER) {
438
- return (
439
- <Col key={getKey(option) || index} span={col.span} style={style}>
440
- <Divider orientation="left" {...componentProps}>{option.label}</Divider>
441
- </Col>
442
- );
443
- }
444
-
445
- return null;
446
- };
447
-
448
- // 渲染 Form.List
449
- const renderFormList = (option, index, col, style) => {
450
- const formListUniqueProps = getFormListUniqueProps(option);
451
- const componentProps = getComponentProps(option);
452
-
453
- return (
454
- <Col key={getKey(option) || index} span={col.span} style={style}>
455
- <Form.List name={option.name} {...componentProps}>
456
- {(fields, { add, remove, move }) => (
457
- <>
458
- {fields.map((field, fieldIndex) => {
459
- const listOptions = getListOptions(option.formListUniqueProps.options, field, fieldIndex, add, remove, move);
460
- return (
461
- <Row gutter={gutter} key={field.key}>
462
- {listOptions.map((listOption, listIndex) => {
463
- const col = getCol(listOption);
464
-
465
- const params = {
466
- option: listOption,
467
- style,
468
- col,
469
- index: `${fieldIndex}_${listIndex}`,
470
- };
471
- const otherTypeItem = renderOtherTypeItem(params);
472
- if (otherTypeItem)
473
- return otherTypeItem;
474
-
475
- // 如果是最后一个表单项,则在其后添加操作按钮
476
- // 这样可以确保每个表单项组都有添加/删除按钮
477
- if (listIndex === listOptions.length - 1) {
478
- return (
479
- <Col key={getKey(listOption) || listIndex} span={col.span} style={style}>
480
- <Form.Item
481
- label={renderLabel(listOption)}
482
- labelCol={col.labelCol}
483
- wrapperCol={col.wrapperCol}
484
- preserve={false}
485
- required={getRequired(listOption.required)}
486
- {...getFormItemProps(listOption)}
487
- >
488
- <div style={{ display: "flex", gap: 10, alignItems: "center", justifyContent: "space-between" }}>
489
- <div style={{ flex: 1 }}>
490
- <Form.Item
491
- noStyle
492
- rules={getRules(listOption)}
493
- name={listOption.name}
494
- >
495
- {renderFormControl(listOption)}
496
- </Form.Item>
497
- </div>
498
- {
499
- // 只有当不是第一行时才显示删除按钮
500
- fieldIndex >= 1
501
- ? (
502
- formListUniqueProps.showRemoveButton
503
- && (
504
- <Button
505
- type="primary"
506
- danger
507
- onClick={() => remove(field.name)}
508
- >
509
- {formListUniqueProps.removeButtonText}
510
- </Button>
511
- )
512
- )
513
- : (
514
- // 第一行显示添加按钮
515
- formListUniqueProps.showAddButton
516
- && (
517
- <Button
518
- type="primary"
519
- onClick={() => add(formListUniqueProps.addDefaultValue, formListUniqueProps.addInsertIndex)}
520
- >
521
- {formListUniqueProps.addButtonText}
522
- </Button>
523
- )
524
- )
525
- }
526
- </div>
527
- </Form.Item>
528
- </Col>
529
- );
530
- }
531
-
532
- return renderFormItem(params);
533
- })}
534
- </Row>
535
- );
536
- })}
537
- </>
538
- )}
539
- </Form.List>
540
- </Col>
541
- );
542
- };
543
-
544
- // 渲染需要动态更新的表单项
545
- const renderDynamicFormItem = (option, index, style, col) => {
546
- return (
547
- <Form.Item
548
- key={getKey(option) || index}
549
- noStyle
550
- preserve={false}
551
- shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
552
- dependencies={option.dependencies ?? option?.componentProps?.dependencies}
553
- >
554
- {() => {
555
- return renderFormItem({ option, style, col, index });
556
- }}
557
- </Form.Item>
558
- );
559
- };
560
-
561
- return (
562
- <>
563
- {options.map((option, index) => {
564
- const col = getCol(option);
565
- const style = getStyle(index);
566
-
567
- // 处理特殊类型的表单项
568
- const otherTypeItem = renderOtherTypeItem({ option, style, col, index });
569
- if (otherTypeItem)
570
- return otherTypeItem;
571
-
572
- // 如果是 Form.List
573
- if (option.render === FORM_ITEM_RENDER_ENUM.FORM_LIST) {
574
- return renderFormList(option, index, col, style);
575
- }
576
-
577
- // 如果配置了 shouldUpdate 或 dependencies,使用 Form.Item 的联动机制
578
- if ((option.shouldUpdate ?? option.dependencies) || (option?.componentProps?.shouldUpdate ?? option?.componentProps?.dependencies)) {
579
- return renderDynamicFormItem(option, index, style, col);
580
- }
581
-
582
- // 普通表单项(静态配置)
583
- return renderFormItem({ option, style, col, index });
584
- })}
585
- </>
586
- );
587
- };
588
-
589
- FormItemsRenderer.displayName = "FormItemsRenderer";
590
-
591
- export default FormItemsRenderer;
1
+ import{InfoCircleOutlined as e}from"@ant-design/icons";import{Input as r,DatePicker as n,Form as t,Col as l,Divider as o,Row as s,Button as a,Tooltip as i,Checkbox as d,Radio as p,Select as u,InputNumber as c}from"antd";import m from"dayjs";import{FORM_ITEM_RENDER_ENUM as h}from"../../enum/formItemRender/index.js";import{jsx as y,Fragment as E,jsxs as f}from"react/jsx-runtime";const{TextArea:T}=r,{RangePicker:A}=n,I=({options:I,labelCol:b,gutter:v=24,span:Y=12,collapse:D=!1,useAutoGenerateRequired:P=!0,initialValues:R})=>{const w=t.useFormInstance(),U=()=>{const e=w.getFieldsValue();return 0===Object.keys(e).length&&R?R:e},M=e=>"function"==typeof e.componentProps?e.componentProps(U()):e.componentProps||{},N=e=>{const r="function"==typeof e.formItemProps?e.formItemProps(U()):e.formItemProps||{};return[h.DATE,h.DATE_MONTH,h.DATE_YEAR,h.DATETIME].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?m(e):void 0})),[h.DATE_WEEK].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?m(e,"YYYY-wo"):void 0})),[h.DATE_RANGE,h.DATETIME_RANGE].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:Array.isArray(e)?e.map(e=>e?m(e):void 0):void 0})),r},C=e=>"function"==typeof e?e(U()):e??!0,g=e=>{if(e.render===h.DIVIDER)return[];const r=[];switch(e.render||h.INPUT){case h.INPUT:!1!==e.useConstraints&&r.push({max:50,message:"最多输入50字符"});break;case h.TEXTAREA:!1!==e.useConstraints&&r.push({max:500,message:"最多输入500字符"});break;case h.INPUT_NUMBER:case h.NUMBER:!1!==e.useConstraints&&r.push({pattern:/^(\d+)(\.\d{1,2})?$/,message:"请输入正确的数字,最多保留两位小数"}),!1!==e.useConstraints&&r.push({validator:(e,r)=>r&&Math.abs(Number.parseFloat(r))>999999999?Promise.reject("输入数值超出安全范围"):Promise.resolve()})}if(!P)return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r;if(C(e.required)){const n=!e.render||[h.INPUT,h.TEXTAREA,h.INPUT_NUMBER,h.NUMBER].includes(e.render);return r.push({required:!0,message:`${n?"请输入":"请选择"}${e.label}`}),e.rules&&(Array.isArray(e.rules)?r.push(...e.rules):r.push(e.rules)),r}return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r},x=e=>e.key||e.name,K=e=>{const r=e.render===h.DIVIDER?24:e.span??Y,n=e.labelCol??(24===r?{span:b.span/2}:b);return{span:r,labelCol:n,wrapperCol:e.wrapperCol??{span:24-n.span}}},B=e=>{const t=M(e),l=(e=>({valueKey:e?.itemsField?.valueKey||"bianma",labelKey:e?.itemsField?.labelKey||"name"}))(e),o=e.render||h.INPUT,s=e.placeholder||`请${[h.INPUT,h.TEXTAREA,h.INPUT_NUMBER,h.NUMBER].includes(o)?"输入":"选择"}${e.label}`;switch(o){case h.INPUT:return y(r,{placeholder:s,maxLength:50,...t});case h.TEXTAREA:return y(T,{placeholder:s,maxLength:500,showCount:!0,rows:3,...t});case h.INPUT_NUMBER:case h.NUMBER:return y(c,{placeholder:s,style:{width:"100%"},...t});case h.SELECT:return y(u,{placeholder:s,showSearch:!0,allowClear:!0,optionFilterProp:"children",...t,children:(e.items||[]).map(e=>{const r=e[l.valueKey],n=e["function"==typeof l.labelKey?l.labelKey(e):l.labelKey];return y(u.Option,{value:r,children:n},r)})});case h.RADIO:return y(p.Group,{...t,children:(e.items||[]).map(e=>{const r=e[l.valueKey],n=e["function"==typeof l.labelKey?l.labelKey(e):l.labelKey];return y(p,{value:r,children:n},r)})});case h.CHECKBOX:return y(d.Group,{...t,children:(e.items||[]).map(e=>{const r=e[l.valueKey],n=e["function"==typeof l.labelKey?l.labelKey(e):l.labelKey];return y(d,{value:r,children:n},r)})});case h.DATE:return y(n,{placeholder:s,format:"YYYY-MM-DD",style:{width:"100%"},...t});case h.DATE_MONTH:return y(n,{picker:"month",placeholder:s,format:"YYYY-MM",style:{width:"100%"},...t});case h.DATE_YEAR:return y(n,{picker:"year",placeholder:s,format:"YYYY",style:{width:"100%"},...t});case h.DATE_WEEK:return y(n,{picker:"week",placeholder:s,format:"YYYY-wo",style:{width:"100%"},...t});case h.DATE_RANGE:return y(A,{placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD",style:{width:"100%"},...t});case h.DATETIME:return y(n,{showTime:!0,placeholder:s,format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...t});case h.DATETIME_RANGE:return y(A,{showTime:!0,placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...t});case h.DIVIDER:return null;default:return o}},_=r=>r.tip?f(E,{children:[r.label,y(i,{title:r.tip,children:y(e,{style:{marginLeft:4,fontSize:12}})})]}):r.label,V=({option:e,style:r,col:n,index:o})=>{return("function"==typeof(s=e.hidden)?s(U()):s)?null:y(l,{span:n.span,style:r,children:y(t.Item,{name:e.name,label:_(e),rules:g(e),labelCol:n.labelCol,wrapperCol:n.wrapperCol,preserve:!1,...N(e),children:B(e)})},x(e)||o);var s},k=({option:e,style:r,col:n,index:s})=>{const a=M(e);return e.customizeRender?y(l,{span:n.span,style:r,children:e.render},x(e)||s):e.onlyForLabel?y(t.Item,{name:e.name,noStyle:!0,preserve:!1,children:y("input",{type:"hidden"})},x(e)||s):e.render===h.DIVIDER?y(l,{span:n.span,style:r,children:y(o,{orientation:"left",...a,children:e.label})},x(e)||s):null};return y(E,{children:I.map((e,r)=>{const n=K(e),o=(e=>D&&e>=3?{display:"none"}:void 0)(r);return k({option:e,style:o,col:n,index:r})||(e.render===h.FORM_LIST?((e,r,n,o)=>{const i=(e=>{const r={showAddButton:!0,showRemoveButton:!0,addButtonText:"添加",removeButtonText:"删除",options:[],addDefaultValue:{},addInsertIndex:void 0};return"function"==typeof e.formListUniqueProps?{...r,...e.formListUniqueProps(U())}:{...r,...e.formListUniqueProps||{}}})(e),d=M(e);return y(l,{span:n.span,style:o,children:y(t.List,{name:e.name,...d,children:(r,{add:n,remove:d,move:p})=>y(E,{children:r.map((r,u)=>{const c=((e,r,n,t,l,o)=>"function"==typeof e?e(r,n,{field:r,fieldIndex:n,add:t,remove:l,move:o}):e??[])(e.formListUniqueProps.options,r,u,n,d,p);return y(s,{gutter:v,children:c.map((e,s)=>{const p=K(e),m={option:e,style:o,col:p,index:`${u}_${s}`};return k(m)||(s===c.length-1?y(l,{span:p.span,style:o,children:y(t.Item,{label:_(e),labelCol:p.labelCol,wrapperCol:p.wrapperCol,preserve:!1,required:C(e.required),...N(e),children:f("div",{style:{display:"flex",gap:10,alignItems:"center",justifyContent:"space-between"},children:[y("div",{style:{flex:1},children:y(t.Item,{noStyle:!0,rules:g(e),name:e.name,children:B(e)})}),u>=1?i.showRemoveButton&&y(a,{type:"primary",danger:!0,onClick:()=>d(r.name),children:i.removeButtonText}):i.showAddButton&&y(a,{type:"primary",onClick:()=>n(i.addDefaultValue,i.addInsertIndex),children:i.addButtonText})]})})},x(e)||s):V(m))})},r.key)})})})},x(e)||r)})(e,r,n,o):(e.shouldUpdate??e.dependencies)||(e?.componentProps?.shouldUpdate??e?.componentProps?.dependencies)?((e,r,n,l)=>y(t.Item,{noStyle:!0,preserve:!1,shouldUpdate:e.shouldUpdate??e?.componentProps?.shouldUpdate,dependencies:e.dependencies??e?.componentProps?.dependencies,children:()=>V({option:e,style:n,col:l,index:r})},x(e)||r))(e,r,o,n):V({option:e,style:o,col:n,index:r}))})})};I.displayName="FormItemsRenderer";export{I as default};
@@ -1,3 +1 @@
1
- import FormBuilder from "./FormBuilder";
2
-
3
- export default FormBuilder;
1
+ import r from"./FormBuilder.js";export{r as default};
@@ -1,37 +1 @@
1
- import { ArrowLeftOutlined } from "@ant-design/icons";
2
- import { Divider } from "antd";
3
- import "./index.less";
4
-
5
- /**
6
- * 头部返回组件
7
- */
8
- function HeaderBack(props) {
9
- const { title, history, previous = true } = props;
10
-
11
- return (
12
- <div className="header-back">
13
- <div className="action">
14
- {
15
- previous
16
- && (
17
- <>
18
- <div
19
- className="back"
20
- onClick={() => history?.goBack?.() || window.history.back()}
21
- >
22
- <ArrowLeftOutlined style={{ fontSize: 14 }} />
23
- <span>返回</span>
24
- </div>
25
- <Divider type="vertical" style={{ backgroundColor: "#dcdfe6", marginLeft: 15, marginRight: 15 }} />
26
- </>
27
- )
28
- }
29
- <div className="title">{title}</div>
30
- </div>
31
- </div>
32
- );
33
- }
34
-
35
- HeaderBack.displayName = "HeaderBack";
36
-
37
- export default HeaderBack;
1
+ import{ArrowLeftOutlined as e}from"@ant-design/icons";import{Divider as i}from"antd";import"./index.less";import{jsx as a,jsxs as r,Fragment as t}from"react/jsx-runtime";function c(c){const{title:n,history:o,previous:s=!0}=c;return a("div",{className:"header-back",children:r("div",{className:"action",children:[s&&r(t,{children:[r("div",{className:"back",onClick:()=>o?.goBack?.()||window.history.back(),children:[a(e,{style:{fontSize:14}}),a("span",{children:"返回"})]}),a(i,{type:"vertical",style:{backgroundColor:"#dcdfe6",marginLeft:15,marginRight:15}})]}),a("div",{className:"title",children:n})]})})}c.displayName="HeaderBack";export{c as default};