提交 | 用户 | 时间
|
820397
|
1 |
/** |
H |
2 |
* 针对 https://github.com/xaboy/form-create-designer 封装的工具类 |
|
3 |
*/ |
|
4 |
|
|
5 |
// 编码表单 Conf |
|
6 |
export const encodeConf = (designerRef: object) => { |
|
7 |
// @ts-ignore |
|
8 |
return JSON.stringify(designerRef.value.getOption()) |
|
9 |
} |
|
10 |
|
|
11 |
// 编码表单 Fields |
|
12 |
export const encodeFields = (designerRef: object) => { |
|
13 |
// @ts-ignore |
|
14 |
const rule = designerRef.value.getRule() |
|
15 |
const fields: string[] = [] |
|
16 |
rule.forEach((item) => { |
|
17 |
fields.push(JSON.stringify(item)) |
|
18 |
}) |
|
19 |
return fields |
|
20 |
} |
|
21 |
|
|
22 |
// 解码表单 Fields |
|
23 |
export const decodeFields = (fields: string[]) => { |
|
24 |
const rule: object[] = [] |
|
25 |
fields.forEach((item) => { |
|
26 |
rule.push(JSON.parse(item)) |
|
27 |
}) |
|
28 |
return rule |
|
29 |
} |
|
30 |
|
|
31 |
// 设置表单的 Conf 和 Fields,适用 FcDesigner 场景 |
|
32 |
export const setConfAndFields = (designerRef: object, conf: string, fields: string) => { |
|
33 |
// @ts-ignore |
|
34 |
designerRef.value.setOption(JSON.parse(conf)) |
|
35 |
// @ts-ignore |
|
36 |
designerRef.value.setRule(decodeFields(fields)) |
|
37 |
} |
|
38 |
|
|
39 |
// 设置表单的 Conf 和 Fields,适用 form-create 场景 |
|
40 |
export const setConfAndFields2 = ( |
|
41 |
detailPreview: object, |
|
42 |
conf: string, |
|
43 |
fields: string[], |
|
44 |
value?: object |
|
45 |
) => { |
|
46 |
if (isRef(detailPreview)) { |
9259c2
|
47 |
// @ts-ignore |
820397
|
48 |
detailPreview = detailPreview.value |
H |
49 |
} |
|
50 |
// @ts-ignore |
|
51 |
detailPreview.option = JSON.parse(conf) |
|
52 |
// @ts-ignore |
|
53 |
detailPreview.rule = decodeFields(fields) |
|
54 |
if (value) { |
|
55 |
// @ts-ignore |
|
56 |
detailPreview.value = value |
|
57 |
} |
|
58 |
} |