mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-24 08:11:55 +08:00
commit
0ca750a8c4
@ -1,13 +1,32 @@
|
|||||||
/**
|
/**
|
||||||
* 将服务端返回的 fields 字符串数组,解析成 JSON 数组
|
* 将服务端返回的 fields 字符串数组,解析成 JSON 数组
|
||||||
|
* 如果指定了 variables 参数可对表单进行初始化
|
||||||
*
|
*
|
||||||
* @param fields JSON 字符串数组
|
* @param fields JSON 字符串数组
|
||||||
|
* @param variables Object 表单初始值
|
||||||
* @returns {*[]} JSON 数组
|
* @returns {*[]} JSON 数组
|
||||||
*/
|
*/
|
||||||
export function decodeFields(fields) {
|
export function decodeFields(fields, variables) {
|
||||||
const drawingList = []
|
const drawingList = (fields || []).map(json => {
|
||||||
fields.forEach(item => {
|
const item = JSON.parse(json)
|
||||||
drawingList.push(JSON.parse(item))
|
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
return drawingList
|
return drawingList
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user