2023-02-11 00:44:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* 针对 https://github.com/xaboy/form-create-designer 封装的工具类
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 编码表单 Conf
|
|
|
|
|
export const encodeConf = (designerRef: object) => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return JSON.stringify(designerRef.value.getOption())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 编码表单 Fields
|
|
|
|
|
export const encodeFields = (designerRef: object) => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const rule = designerRef.value.getRule()
|
|
|
|
|
const fields: string[] = []
|
|
|
|
|
rule.forEach((item) => {
|
|
|
|
|
fields.push(JSON.stringify(item))
|
|
|
|
|
})
|
|
|
|
|
return fields
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解码表单 Fields
|
|
|
|
|
export const decodeFields = (fields: string[]) => {
|
|
|
|
|
const rule: object[] = []
|
|
|
|
|
fields.forEach((item) => {
|
|
|
|
|
rule.push(JSON.parse(item))
|
|
|
|
|
})
|
|
|
|
|
return rule
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 12:50:59 +08:00
|
|
|
|
// 设置表单的 Conf 和 Fields,适用 FcDesigner 场景
|
2023-02-11 00:44:00 +08:00
|
|
|
|
export const setConfAndFields = (designerRef: object, conf: string, fields: string) => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
designerRef.value.setOption(JSON.parse(conf))
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
designerRef.value.setRule(decodeFields(fields))
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 12:50:59 +08:00
|
|
|
|
// 设置表单的 Conf 和 Fields,适用 form-create 场景
|
2023-02-11 00:44:00 +08:00
|
|
|
|
export const setConfAndFields2 = (
|
|
|
|
|
detailPreview: object,
|
|
|
|
|
conf: string,
|
2024-03-26 10:59:03 +08:00
|
|
|
|
fields: string[],
|
2023-02-11 00:44:00 +08:00
|
|
|
|
value?: object
|
|
|
|
|
) => {
|
2024-03-20 12:50:59 +08:00
|
|
|
|
if (isRef(detailPreview)) {
|
|
|
|
|
detailPreview = detailPreview.value
|
|
|
|
|
}
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// @ts-ignore
|
2024-03-20 12:50:59 +08:00
|
|
|
|
detailPreview.option = JSON.parse(conf)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// @ts-ignore
|
2024-03-20 12:50:59 +08:00
|
|
|
|
detailPreview.rule = decodeFields(fields)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
if (value) {
|
|
|
|
|
// @ts-ignore
|
2024-03-20 12:50:59 +08:00
|
|
|
|
detailPreview.value = value
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|