File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* 将服务端返回的 fields 字符串数组,解析成 JSON 数组
3
+ * 如果指定了 variables 参数可对表单进行初始化
3
4
*
4
5
* @param fields JSON 字符串数组
6
+ * @param variables Object 表单初始值
5
7
* @returns {*[] } JSON 数组
6
8
*/
7
- export function decodeFields ( fields ) {
8
- const drawingList = [ ]
9
- fields . forEach ( item => {
10
- drawingList . push ( JSON . parse ( item ) )
9
+ export function decodeFields ( fields , variables ) {
10
+ const drawingList = ( fields || [ ] ) . map ( json => {
11
+ const item = JSON . parse ( json )
12
+
13
+ if ( typeof variables === 'undefined' ) return item
14
+
15
+ const setDefault = ( item , variables ) => {
16
+ if ( typeof variables [ item . __vModel__ ] !== 'undefined' ) {
17
+ item . __config__ . defaultValue = variables [ item . __vModel__ ]
18
+ }
19
+ if ( item . __config__ . children && item . __config__ . children . length ) {
20
+ item . __config__ . children . forEach ( child => {
21
+ setDefault ( child , variables )
22
+ } )
23
+ }
24
+ }
25
+
26
+ setDefault ( item , variables )
27
+
28
+ return item
11
29
} )
30
+
12
31
return drawingList
13
32
}
You can’t perform that action at this time.
0 commit comments