detail-echo.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 详情回显 ACL — 解析 jsonContent 为 initialValues,与模版 schema 分离
* @see packageDynamicForm/docs/ARCHITECTURE.md
*/
import { parseJsonContentDetailValues } from './submit-adapter.js'
/** 从详情解析引擎 initialValues(不写入 schema.list) */
export function parseDetailEchoValues(detail, schemaList = [], fallbackValues = {}) {
if (!detail?.jsonContent || !schemaList?.length) {
return fallbackValues || {}
}
return parseJsonContentDetailValues(detail.jsonContent, schemaList)
}
/** 剥离 schema 字段上的 value,保持模版定义 */
export function stripValuesFromSchemaRoot(schemaRoot = {}) {
const next = JSON.parse(JSON.stringify(schemaRoot))
function stripList(list = []) {
return (list || []).map(field => {
const copy = { ...field }
delete copy.value
if (copy.type === 'subform' && Array.isArray(copy.children)) {
copy.children = copy.children.map(row =>
Array.isArray(row) ? row.map(stripField) : row
)
}
if (copy.type === 'group' && Array.isArray(copy.children)) {
copy.children = copy.children.map(stripField)
}
return copy
})
}
function stripField(field) {
const copy = { ...field }
delete copy.value
return copy
}
next.list = stripList(next.list)
return next
}