szld-libs 0.2.74 → 0.2.76
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/dist/szld-components.es.js +8220 -8207
- package/dist/szld-components.umd.js +42 -42
- package/es/components/DynamicForm/func.d.ts +9 -0
- package/es/components/DynamicForm/func.js +104 -0
- package/es/components/DynamicForm/index.d.ts +2 -1
- package/es/components/DynamicForm/useDynamicForm.js +83 -157
- package/lib/components/DynamicForm/func.d.ts +9 -0
- package/lib/components/DynamicForm/func.js +104 -0
- package/lib/components/DynamicForm/index.d.ts +2 -1
- package/lib/components/DynamicForm/useDynamicForm.js +87 -161
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IformConfigItem } from './index.d';
|
|
2
|
+
import { RangePickerProps } from 'antd/es/date-picker';
|
|
3
|
+
export declare const handleGetPlaceholder: (itemWithJson: IformConfigItem) => string;
|
|
4
|
+
/**
|
|
5
|
+
* 处理表单项目初始值
|
|
6
|
+
* 根据输入类型转换初始值为组件所需格式
|
|
7
|
+
*/
|
|
8
|
+
export declare const handleSetFormItemInitialValue: (itemWithJson: IformConfigItem) => any;
|
|
9
|
+
export declare const disabledDate: RangePickerProps['disabledDate'];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
const handleGetPlaceholder = (itemWithJson) => {
|
|
3
|
+
const { input = "" } = itemWithJson.json || {};
|
|
4
|
+
let placeholder = "请输入";
|
|
5
|
+
if ([
|
|
6
|
+
"radio",
|
|
7
|
+
"checkbox",
|
|
8
|
+
"select",
|
|
9
|
+
"mult-select",
|
|
10
|
+
"modal-select",
|
|
11
|
+
"date-picker",
|
|
12
|
+
"range-picker",
|
|
13
|
+
"multiple-date-picker",
|
|
14
|
+
"time-picker",
|
|
15
|
+
"week-picker",
|
|
16
|
+
"month-picker",
|
|
17
|
+
"quarter-picker",
|
|
18
|
+
"year-picker",
|
|
19
|
+
"second-picker"
|
|
20
|
+
].includes(input)) {
|
|
21
|
+
placeholder = "请选择";
|
|
22
|
+
}
|
|
23
|
+
if (["image", "file", "video", "audio"].includes(input)) {
|
|
24
|
+
placeholder = "请上传";
|
|
25
|
+
}
|
|
26
|
+
return placeholder;
|
|
27
|
+
};
|
|
28
|
+
const handleSetFormItemInitialValue = (itemWithJson) => {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
const inputType = (_a = itemWithJson.json) == null ? void 0 : _a.input;
|
|
31
|
+
const isFormList = (_b = itemWithJson == null ? void 0 : itemWithJson.json) == null ? void 0 : _b["properties-multiple"];
|
|
32
|
+
let initialValue = itemWithJson.attrvalue || ((_c = itemWithJson.json) == null ? void 0 : _c.default);
|
|
33
|
+
if (inputType === "label" && initialValue) {
|
|
34
|
+
initialValue = ((_d = itemWithJson.json) == null ? void 0 : _d["label-value"]) ?? initialValue ?? "-";
|
|
35
|
+
}
|
|
36
|
+
if ((inputType === "date-picker" || inputType === "time-picker") && initialValue) {
|
|
37
|
+
try {
|
|
38
|
+
const date = dayjs(initialValue);
|
|
39
|
+
initialValue = date.isValid() ? date : void 0;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
initialValue = void 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (inputType === "range-picker" && initialValue) {
|
|
45
|
+
try {
|
|
46
|
+
initialValue = initialValue == null ? void 0 : initialValue.split("~");
|
|
47
|
+
initialValue = initialValue.map((v) => dayjs(v));
|
|
48
|
+
} catch (error) {
|
|
49
|
+
initialValue = void 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (inputType === "multiple-date-picker" && initialValue) {
|
|
53
|
+
try {
|
|
54
|
+
initialValue = initialValue == null ? void 0 : initialValue.split(",");
|
|
55
|
+
initialValue = initialValue.map((v) => dayjs(v));
|
|
56
|
+
} catch (error) {
|
|
57
|
+
initialValue = void 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (inputType === "cascader" && initialValue && typeof initialValue === "string") {
|
|
61
|
+
const delimiter = (_e = itemWithJson.json) == null ? void 0 : _e["cascader-delimiter"];
|
|
62
|
+
if (delimiter) {
|
|
63
|
+
initialValue = initialValue.split(delimiter).filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (["mult-select", "checkbox"].includes(inputType) && initialValue && typeof initialValue === "string") {
|
|
67
|
+
initialValue = initialValue.split(",").filter(Boolean);
|
|
68
|
+
}
|
|
69
|
+
if (["image", "video", "audio", "file"].includes(inputType) && initialValue) {
|
|
70
|
+
try {
|
|
71
|
+
const fileList = Array.isArray(initialValue) ? initialValue : JSON.parse(initialValue);
|
|
72
|
+
initialValue = fileList.map((file) => ({
|
|
73
|
+
...file,
|
|
74
|
+
url: file.FilePath,
|
|
75
|
+
name: file.FileName,
|
|
76
|
+
uid: file.FileId
|
|
77
|
+
}));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
initialValue = [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (isFormList && itemWithJson.attrtype === 1) {
|
|
83
|
+
const children = itemWithJson.children || [];
|
|
84
|
+
if (Array.isArray(children)) {
|
|
85
|
+
initialValue = [
|
|
86
|
+
Object.assign(
|
|
87
|
+
{},
|
|
88
|
+
...children == null ? void 0 : children.map((child) => ({
|
|
89
|
+
[child.attrid]: handleSetFormItemInitialValue(child)
|
|
90
|
+
}))
|
|
91
|
+
)
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return initialValue || null;
|
|
96
|
+
};
|
|
97
|
+
const disabledDate = (current) => {
|
|
98
|
+
return current && current < dayjs().startOf("day");
|
|
99
|
+
};
|
|
100
|
+
export {
|
|
101
|
+
disabledDate,
|
|
102
|
+
handleGetPlaceholder,
|
|
103
|
+
handleSetFormItemInitialValue
|
|
104
|
+
};
|
|
@@ -18,7 +18,8 @@ export interface IformConfigItem {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export interface Ijson {
|
|
21
|
-
|
|
21
|
+
'disable-date-goover'?: boolean; // 禁用日期选择器超出当前日期
|
|
22
|
+
'default-prompt'?: string; // 提示信息
|
|
22
23
|
'regexp-message'?: string; // 正则表达式提示信息
|
|
23
24
|
regexp: any; // 正则表达式
|
|
24
25
|
'properties-width'?: number; // 属性集表单宽度
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useRef, useEffect, useCallback, Fragment as Fragment$1 } from "react";
|
|
2
|
+
import { handleSetFormItemInitialValue, handleGetPlaceholder, disabledDate } from "./func";
|
|
4
3
|
import { handleAttrList, getJson, base64ToString } from "../../utils/method";
|
|
4
|
+
import { useRef, useEffect, useCallback, Fragment as Fragment$1 } from "react";
|
|
5
5
|
import isoWeek from "dayjs/plugin/isoWeek";
|
|
6
6
|
import SelectModel from "./selectModel";
|
|
7
7
|
import MyCheckbox from "./myCheckbox";
|
|
@@ -12,6 +12,7 @@ import MySelect from "./mySelect";
|
|
|
12
12
|
import MyUpload from "./myUpload";
|
|
13
13
|
import MyRadio from "./myRadio";
|
|
14
14
|
import _ from "lodash";
|
|
15
|
+
import { MinusSquareOutlined, PlusSquareOutlined, CloseOutlined, InfoCircleOutlined } from "@ant-design/icons";
|
|
15
16
|
import { App, Col, Collapse, Form, Card, Flex, Button, Space, Input, DatePicker, InputNumber, Tooltip } from "antd";
|
|
16
17
|
dayjs.extend(isoWeek);
|
|
17
18
|
function useDynamicForm(props) {
|
|
@@ -137,75 +138,6 @@ function useDynamicForm(props) {
|
|
|
137
138
|
},
|
|
138
139
|
[handleNormFile]
|
|
139
140
|
);
|
|
140
|
-
const handleSetFormItemInitialValue = useCallback((itemWithJson) => {
|
|
141
|
-
var _a, _b, _c, _d, _e;
|
|
142
|
-
const inputType = (_a = itemWithJson.json) == null ? void 0 : _a.input;
|
|
143
|
-
const isFormList = (_b = itemWithJson == null ? void 0 : itemWithJson.json) == null ? void 0 : _b["properties-multiple"];
|
|
144
|
-
let initialValue = itemWithJson.attrvalue ?? ((_c = itemWithJson.json) == null ? void 0 : _c.default);
|
|
145
|
-
if (inputType === "label" && initialValue) {
|
|
146
|
-
initialValue = ((_d = itemWithJson.json) == null ? void 0 : _d["label-value"]) ?? initialValue ?? "-";
|
|
147
|
-
}
|
|
148
|
-
if ((inputType === "date-picker" || inputType === "time-picker") && initialValue) {
|
|
149
|
-
try {
|
|
150
|
-
const date = dayjs(initialValue);
|
|
151
|
-
initialValue = date.isValid() ? date : void 0;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
initialValue = void 0;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (inputType === "range-picker" && initialValue) {
|
|
157
|
-
try {
|
|
158
|
-
initialValue = initialValue == null ? void 0 : initialValue.split("~");
|
|
159
|
-
initialValue = initialValue.map((v) => dayjs(v));
|
|
160
|
-
} catch (error) {
|
|
161
|
-
initialValue = void 0;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (inputType === "multiple-date-picker" && initialValue) {
|
|
165
|
-
try {
|
|
166
|
-
initialValue = initialValue == null ? void 0 : initialValue.split(",");
|
|
167
|
-
initialValue = initialValue.map((v) => dayjs(v));
|
|
168
|
-
} catch (error) {
|
|
169
|
-
initialValue = void 0;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (inputType === "cascader" && initialValue && typeof initialValue === "string") {
|
|
173
|
-
const delimiter = (_e = itemWithJson.json) == null ? void 0 : _e["cascader-delimiter"];
|
|
174
|
-
if (delimiter) {
|
|
175
|
-
initialValue = initialValue.split(delimiter).filter(Boolean);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (["mult-select", "checkbox"].includes(inputType) && initialValue && typeof initialValue === "string") {
|
|
179
|
-
initialValue = initialValue.split(",").filter(Boolean);
|
|
180
|
-
}
|
|
181
|
-
if (["image", "video", "audio", "file"].includes(inputType) && initialValue) {
|
|
182
|
-
try {
|
|
183
|
-
const fileList = Array.isArray(initialValue) ? initialValue : JSON.parse(initialValue);
|
|
184
|
-
initialValue = fileList.map((file) => ({
|
|
185
|
-
...file,
|
|
186
|
-
url: file.FilePath,
|
|
187
|
-
name: file.FileName,
|
|
188
|
-
uid: file.FileId
|
|
189
|
-
}));
|
|
190
|
-
} catch (error) {
|
|
191
|
-
initialValue = [];
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (isFormList && itemWithJson.attrtype === 1) {
|
|
195
|
-
const children = itemWithJson.children || [];
|
|
196
|
-
if (Array.isArray(children)) {
|
|
197
|
-
initialValue = [
|
|
198
|
-
Object.assign(
|
|
199
|
-
{},
|
|
200
|
-
...children == null ? void 0 : children.map((child) => ({
|
|
201
|
-
[child.attrid]: handleSetFormItemInitialValue(child)
|
|
202
|
-
}))
|
|
203
|
-
)
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return initialValue || null;
|
|
208
|
-
}, []);
|
|
209
141
|
const handleCollapseIcon = useCallback(
|
|
210
142
|
({ isActive }) => isActive ? /* @__PURE__ */ jsx(MinusSquareOutlined, { style: { fontSize: 18, color: "#999" } }) : /* @__PURE__ */ jsx(PlusSquareOutlined, { style: { fontSize: 18, color: "#999" } }),
|
|
211
143
|
[]
|
|
@@ -241,7 +173,7 @@ function useDynamicForm(props) {
|
|
|
241
173
|
formListField,
|
|
242
174
|
isShowLabel = true
|
|
243
175
|
}) => {
|
|
244
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
176
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
245
177
|
const isFormList = (_a = itemWithJson == null ? void 0 : itemWithJson.json) == null ? void 0 : _a["properties-multiple"];
|
|
246
178
|
let formListInitValue = [];
|
|
247
179
|
if (isFormList) {
|
|
@@ -354,84 +286,71 @@ function useDynamicForm(props) {
|
|
|
354
286
|
}
|
|
355
287
|
if (itemWithJson.attrtype === 0) {
|
|
356
288
|
let initialValue = handleSetFormItemInitialValue(itemWithJson);
|
|
357
|
-
const message2 = (_c = itemWithJson.json) == null ? void 0 : _c["
|
|
358
|
-
|
|
359
|
-
const { input = "" } = itemWithJson.json || {};
|
|
360
|
-
if ([
|
|
361
|
-
"radio",
|
|
362
|
-
"checkbox",
|
|
363
|
-
"select",
|
|
364
|
-
"mult-select",
|
|
365
|
-
"modal-select",
|
|
366
|
-
"date-picker",
|
|
367
|
-
"range-picker",
|
|
368
|
-
"multiple-date-picker",
|
|
369
|
-
"time-picker",
|
|
370
|
-
"week-picker",
|
|
371
|
-
"month-picker",
|
|
372
|
-
"quarter-picker",
|
|
373
|
-
"year-picker",
|
|
374
|
-
"second-picker"
|
|
375
|
-
].includes(input)) {
|
|
376
|
-
placeholder = "请选择";
|
|
377
|
-
}
|
|
378
|
-
if (["image", "file", "video", "audio"].includes(input)) {
|
|
379
|
-
placeholder = "请上传";
|
|
380
|
-
}
|
|
289
|
+
const message2 = (_c = itemWithJson.json) == null ? void 0 : _c["default-prompt"];
|
|
290
|
+
const placeholder = handleGetPlaceholder(itemWithJson);
|
|
381
291
|
const { combinations = [] } = itemWithJson.json || {};
|
|
382
292
|
if (combinations == null ? void 0 : combinations.length) {
|
|
383
|
-
return /* @__PURE__ */ jsx(Col, { span: 24 / colNum, children: /* @__PURE__ */ jsx(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
293
|
+
return /* @__PURE__ */ jsx(Col, { span: 24 / colNum, children: /* @__PURE__ */ jsx(
|
|
294
|
+
Form.Item,
|
|
295
|
+
{
|
|
296
|
+
label: (_d = itemWithJson == null ? void 0 : itemWithJson.json) == null ? void 0 : _d["combination-name"],
|
|
297
|
+
required: (_e = itemWithJson.json) == null ? void 0 : _e.must,
|
|
298
|
+
children: /* @__PURE__ */ jsx(Space.Compact, { children: combinations.map((item, index) => {
|
|
299
|
+
var _a2, _b2, _c2, _d2;
|
|
300
|
+
let initValue = handleSetFormItemInitialValue(item);
|
|
301
|
+
let width = defaultWidth;
|
|
302
|
+
const customWidth = {};
|
|
303
|
+
const mode = item.json.input || "text";
|
|
304
|
+
const itemStyle = formItemStyle == null ? void 0 : formItemStyle.find((v) => v.type === mode);
|
|
305
|
+
if (itemStyle) {
|
|
306
|
+
const { width: width2 } = (itemStyle == null ? void 0 : itemStyle.style) || {};
|
|
307
|
+
if (width2) {
|
|
308
|
+
customWidth["width"] = width2;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const widthRatio = (_a2 = item == null ? void 0 : item.json) == null ? void 0 : _a2["combination-width-ratio"];
|
|
312
|
+
const placeholder2 = handleGetPlaceholder(item);
|
|
313
|
+
if (widthRatio) {
|
|
314
|
+
width = defaultWidth * widthRatio;
|
|
315
|
+
}
|
|
316
|
+
return /* @__PURE__ */ jsx(
|
|
317
|
+
Form.Item,
|
|
318
|
+
{
|
|
319
|
+
name: item.attrid,
|
|
320
|
+
noStyle: true,
|
|
321
|
+
initialValue: initValue,
|
|
322
|
+
rules: [
|
|
323
|
+
...((_b2 = item.json) == null ? void 0 : _b2.must) ? [
|
|
324
|
+
{
|
|
325
|
+
required: true,
|
|
326
|
+
message: message2 || `${placeholder2}${item.attrname}`
|
|
327
|
+
}
|
|
328
|
+
] : [],
|
|
329
|
+
...((_c2 = itemWithJson.json) == null ? void 0 : _c2.regexp) ? [
|
|
330
|
+
{
|
|
331
|
+
pattern: new RegExp(itemWithJson.json.regexp),
|
|
332
|
+
message: ((_d2 = itemWithJson.json) == null ? void 0 : _d2["regexp-message"]) || `${itemWithJson.attrname}格式不正确`
|
|
333
|
+
}
|
|
334
|
+
] : []
|
|
335
|
+
],
|
|
336
|
+
...handleSetFormItemProps(item),
|
|
337
|
+
children: handleRenderItemInputMode({
|
|
338
|
+
item,
|
|
339
|
+
readonly,
|
|
340
|
+
formItemStyle,
|
|
341
|
+
radioAlign,
|
|
342
|
+
relatedid,
|
|
343
|
+
form,
|
|
344
|
+
defaultWidth: width,
|
|
345
|
+
customWidth
|
|
346
|
+
})
|
|
347
|
+
},
|
|
348
|
+
index
|
|
349
|
+
);
|
|
350
|
+
}) })
|
|
351
|
+
},
|
|
352
|
+
`${itemWithJson.attrid}+1`
|
|
353
|
+
) });
|
|
435
354
|
}
|
|
436
355
|
if (isFormListItem && formListField) {
|
|
437
356
|
return /* @__PURE__ */ jsx(Col, { span: 24 / colNum, children: /* @__PURE__ */ jsx(
|
|
@@ -441,16 +360,16 @@ function useDynamicForm(props) {
|
|
|
441
360
|
label: isShowLabel && handleDealInstruction(itemWithJson, instructionShowMode) || null,
|
|
442
361
|
initialValue,
|
|
443
362
|
rules: [
|
|
444
|
-
...((
|
|
363
|
+
...((_f = itemWithJson.json) == null ? void 0 : _f.must) ? [
|
|
445
364
|
{
|
|
446
365
|
required: true,
|
|
447
366
|
message: `${placeholder}${itemWithJson.attrname}`
|
|
448
367
|
}
|
|
449
368
|
] : [],
|
|
450
|
-
...((
|
|
369
|
+
...((_g = itemWithJson.json) == null ? void 0 : _g.regexp) ? [
|
|
451
370
|
{
|
|
452
371
|
pattern: new RegExp(itemWithJson.json.regexp),
|
|
453
|
-
message: ((
|
|
372
|
+
message: ((_h = itemWithJson.json) == null ? void 0 : _h["regexp-message"]) || `${itemWithJson.attrname}格式不正确`
|
|
454
373
|
}
|
|
455
374
|
] : []
|
|
456
375
|
],
|
|
@@ -475,16 +394,16 @@ function useDynamicForm(props) {
|
|
|
475
394
|
label: isShowLabel && handleDealInstruction(itemWithJson, instructionShowMode) || null,
|
|
476
395
|
initialValue,
|
|
477
396
|
rules: [
|
|
478
|
-
...((
|
|
397
|
+
...((_i = itemWithJson.json) == null ? void 0 : _i.must) ? [
|
|
479
398
|
{
|
|
480
399
|
required: true,
|
|
481
400
|
message: `${placeholder}${itemWithJson.attrname}`
|
|
482
401
|
}
|
|
483
402
|
] : [],
|
|
484
|
-
...((
|
|
403
|
+
...((_j = itemWithJson.json) == null ? void 0 : _j.regexp) ? [
|
|
485
404
|
{
|
|
486
405
|
pattern: new RegExp(itemWithJson.json.regexp),
|
|
487
|
-
message: ((
|
|
406
|
+
message: ((_k = itemWithJson.json) == null ? void 0 : _k["regexp-message"]) || `${itemWithJson.attrname}格式不正确`
|
|
488
407
|
}
|
|
489
408
|
] : []
|
|
490
409
|
],
|
|
@@ -540,10 +459,11 @@ function useDynamicForm(props) {
|
|
|
540
459
|
defaultWidth = 358,
|
|
541
460
|
customWidth = {}
|
|
542
461
|
}) => {
|
|
543
|
-
var _a, _b, _c;
|
|
462
|
+
var _a, _b, _c, _d;
|
|
544
463
|
const mode = item.json.input || "text";
|
|
545
464
|
const formatValue = handleSetFormItemInitialValue(item);
|
|
546
|
-
const message2 = ((_a = item.json) == null ? void 0 : _a
|
|
465
|
+
const message2 = ((_a = item.json) == null ? void 0 : _a["default-prompt"]) || "";
|
|
466
|
+
const disableDateGoover = ((_b = item.json) == null ? void 0 : _b["disable-date-goover"]) || false;
|
|
547
467
|
const params = item.json.length && {
|
|
548
468
|
maxLength: item.json.length
|
|
549
469
|
} || {};
|
|
@@ -554,7 +474,7 @@ function useDynamicForm(props) {
|
|
|
554
474
|
Input,
|
|
555
475
|
{
|
|
556
476
|
disabled: true,
|
|
557
|
-
value: ((
|
|
477
|
+
value: ((_c = item.json) == null ? void 0 : _c["label-value"]) || item.attrvalue || ((_d = item.json) == null ? void 0 : _d.default) || "-",
|
|
558
478
|
style: { width: defaultWidth, ...itemStyle == null ? void 0 : itemStyle.style, ...customWidth }
|
|
559
479
|
}
|
|
560
480
|
);
|
|
@@ -659,12 +579,17 @@ function useDynamicForm(props) {
|
|
|
659
579
|
"year-picker": "year",
|
|
660
580
|
"second-picker": "time"
|
|
661
581
|
};
|
|
582
|
+
let disabledDateFunc = void 0;
|
|
583
|
+
if (mode === "date-picker") {
|
|
584
|
+
disabledDateFunc = disableDateGoover ? disabledDate : void 0;
|
|
585
|
+
}
|
|
662
586
|
return /* @__PURE__ */ jsx(
|
|
663
587
|
DatePicker,
|
|
664
588
|
{
|
|
665
589
|
showTime: mode === "time-picker",
|
|
666
590
|
picker: pickerObj[mode] || "date",
|
|
667
591
|
disabled: readonly,
|
|
592
|
+
disabledDate: disabledDateFunc,
|
|
668
593
|
placement: "bottomLeft",
|
|
669
594
|
style: { width: defaultWidth, ...itemStyle == null ? void 0 : itemStyle.style, ...customWidth }
|
|
670
595
|
}
|
|
@@ -674,6 +599,7 @@ function useDynamicForm(props) {
|
|
|
674
599
|
return /* @__PURE__ */ jsx(
|
|
675
600
|
DatePicker.RangePicker,
|
|
676
601
|
{
|
|
602
|
+
disabledDate: disableDateGoover ? disabledDate : void 0,
|
|
677
603
|
disabled: readonly,
|
|
678
604
|
style: { width: defaultWidth, ...itemStyle == null ? void 0 : itemStyle.style, ...customWidth }
|
|
679
605
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IformConfigItem } from './index.d';
|
|
2
|
+
import { RangePickerProps } from 'antd/es/date-picker';
|
|
3
|
+
export declare const handleGetPlaceholder: (itemWithJson: IformConfigItem) => string;
|
|
4
|
+
/**
|
|
5
|
+
* 处理表单项目初始值
|
|
6
|
+
* 根据输入类型转换初始值为组件所需格式
|
|
7
|
+
*/
|
|
8
|
+
export declare const handleSetFormItemInitialValue: (itemWithJson: IformConfigItem) => any;
|
|
9
|
+
export declare const disabledDate: RangePickerProps['disabledDate'];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const dayjs = require("dayjs");
|
|
4
|
+
const handleGetPlaceholder = (itemWithJson) => {
|
|
5
|
+
const { input = "" } = itemWithJson.json || {};
|
|
6
|
+
let placeholder = "请输入";
|
|
7
|
+
if ([
|
|
8
|
+
"radio",
|
|
9
|
+
"checkbox",
|
|
10
|
+
"select",
|
|
11
|
+
"mult-select",
|
|
12
|
+
"modal-select",
|
|
13
|
+
"date-picker",
|
|
14
|
+
"range-picker",
|
|
15
|
+
"multiple-date-picker",
|
|
16
|
+
"time-picker",
|
|
17
|
+
"week-picker",
|
|
18
|
+
"month-picker",
|
|
19
|
+
"quarter-picker",
|
|
20
|
+
"year-picker",
|
|
21
|
+
"second-picker"
|
|
22
|
+
].includes(input)) {
|
|
23
|
+
placeholder = "请选择";
|
|
24
|
+
}
|
|
25
|
+
if (["image", "file", "video", "audio"].includes(input)) {
|
|
26
|
+
placeholder = "请上传";
|
|
27
|
+
}
|
|
28
|
+
return placeholder;
|
|
29
|
+
};
|
|
30
|
+
const handleSetFormItemInitialValue = (itemWithJson) => {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const inputType = (_a = itemWithJson.json) == null ? void 0 : _a.input;
|
|
33
|
+
const isFormList = (_b = itemWithJson == null ? void 0 : itemWithJson.json) == null ? void 0 : _b["properties-multiple"];
|
|
34
|
+
let initialValue = itemWithJson.attrvalue || ((_c = itemWithJson.json) == null ? void 0 : _c.default);
|
|
35
|
+
if (inputType === "label" && initialValue) {
|
|
36
|
+
initialValue = ((_d = itemWithJson.json) == null ? void 0 : _d["label-value"]) ?? initialValue ?? "-";
|
|
37
|
+
}
|
|
38
|
+
if ((inputType === "date-picker" || inputType === "time-picker") && initialValue) {
|
|
39
|
+
try {
|
|
40
|
+
const date = dayjs(initialValue);
|
|
41
|
+
initialValue = date.isValid() ? date : void 0;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
initialValue = void 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (inputType === "range-picker" && initialValue) {
|
|
47
|
+
try {
|
|
48
|
+
initialValue = initialValue == null ? void 0 : initialValue.split("~");
|
|
49
|
+
initialValue = initialValue.map((v) => dayjs(v));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
initialValue = void 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (inputType === "multiple-date-picker" && initialValue) {
|
|
55
|
+
try {
|
|
56
|
+
initialValue = initialValue == null ? void 0 : initialValue.split(",");
|
|
57
|
+
initialValue = initialValue.map((v) => dayjs(v));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
initialValue = void 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (inputType === "cascader" && initialValue && typeof initialValue === "string") {
|
|
63
|
+
const delimiter = (_e = itemWithJson.json) == null ? void 0 : _e["cascader-delimiter"];
|
|
64
|
+
if (delimiter) {
|
|
65
|
+
initialValue = initialValue.split(delimiter).filter(Boolean);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (["mult-select", "checkbox"].includes(inputType) && initialValue && typeof initialValue === "string") {
|
|
69
|
+
initialValue = initialValue.split(",").filter(Boolean);
|
|
70
|
+
}
|
|
71
|
+
if (["image", "video", "audio", "file"].includes(inputType) && initialValue) {
|
|
72
|
+
try {
|
|
73
|
+
const fileList = Array.isArray(initialValue) ? initialValue : JSON.parse(initialValue);
|
|
74
|
+
initialValue = fileList.map((file) => ({
|
|
75
|
+
...file,
|
|
76
|
+
url: file.FilePath,
|
|
77
|
+
name: file.FileName,
|
|
78
|
+
uid: file.FileId
|
|
79
|
+
}));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
initialValue = [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (isFormList && itemWithJson.attrtype === 1) {
|
|
85
|
+
const children = itemWithJson.children || [];
|
|
86
|
+
if (Array.isArray(children)) {
|
|
87
|
+
initialValue = [
|
|
88
|
+
Object.assign(
|
|
89
|
+
{},
|
|
90
|
+
...children == null ? void 0 : children.map((child) => ({
|
|
91
|
+
[child.attrid]: handleSetFormItemInitialValue(child)
|
|
92
|
+
}))
|
|
93
|
+
)
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return initialValue || null;
|
|
98
|
+
};
|
|
99
|
+
const disabledDate = (current) => {
|
|
100
|
+
return current && current < dayjs().startOf("day");
|
|
101
|
+
};
|
|
102
|
+
exports.disabledDate = disabledDate;
|
|
103
|
+
exports.handleGetPlaceholder = handleGetPlaceholder;
|
|
104
|
+
exports.handleSetFormItemInitialValue = handleSetFormItemInitialValue;
|
|
@@ -18,7 +18,8 @@ export interface IformConfigItem {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export interface Ijson {
|
|
21
|
-
|
|
21
|
+
'disable-date-goover'?: boolean; // 禁用日期选择器超出当前日期
|
|
22
|
+
'default-prompt'?: string; // 提示信息
|
|
22
23
|
'regexp-message'?: string; // 正则表达式提示信息
|
|
23
24
|
regexp: any; // 正则表达式
|
|
24
25
|
'properties-width'?: number; // 属性集表单宽度
|