2022-01-02 12:56:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* 将服务端返回的 fields 字符串数组,解析成 JSON 数组
|
2022-04-29 09:46:10 +08:00
|
|
|
|
* 如果指定了 variables 参数可对表单进行初始化
|
2022-01-02 12:56:34 +08:00
|
|
|
|
*
|
|
|
|
|
* @param fields JSON 字符串数组
|
2022-04-29 09:46:10 +08:00
|
|
|
|
* @param variables Object 表单初始值
|
2022-01-02 12:56:34 +08:00
|
|
|
|
* @returns {*[]} JSON 数组
|
|
|
|
|
*/
|
2022-04-29 09:46:10 +08:00
|
|
|
|
export function decodeFields(fields, variables) {
|
|
|
|
|
const drawingList = (fields || []).map(json => {
|
|
|
|
|
const item = JSON.parse(json)
|
|
|
|
|
|
|
|
|
|
if (typeof variables === 'undefined' ) return item
|
|
|
|
|
|
|
|
|
|
const setDefault = (item, variables) => {
|
|
|
|
|
if (typeof variables[item.__vModel__] !== 'undefined') {
|
|
|
|
|
item.__config__.defaultValue = variables[item.__vModel__]
|
|
|
|
|
}
|
|
|
|
|
if (item.__config__.children && item.__config__.children.length) {
|
|
|
|
|
item.__config__.children.forEach(child => {
|
|
|
|
|
setDefault(child, variables)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setDefault(item, variables)
|
|
|
|
|
|
|
|
|
|
return item
|
2022-01-02 12:56:34 +08:00
|
|
|
|
})
|
2022-04-29 09:46:10 +08:00
|
|
|
|
|
2022-01-02 12:56:34 +08:00
|
|
|
|
return drawingList
|
|
|
|
|
}
|