@@ -26,9 +26,10 @@ export function makeUpJs(formConfig, type) {
26
26
const propsList = [ ]
27
27
const methodList = mixinMethod ( type )
28
28
const uploadVarList = [ ]
29
+ const created = [ ]
29
30
30
31
formConfig . fields . forEach ( el => {
31
- buildAttributes ( el , dataList , ruleList , optionsList , methodList , propsList , uploadVarList )
32
+ buildAttributes ( el , dataList , ruleList , optionsList , methodList , propsList , uploadVarList , created )
32
33
} )
33
34
34
35
const script = buildexport (
@@ -39,14 +40,15 @@ export function makeUpJs(formConfig, type) {
39
40
optionsList . join ( '\n' ) ,
40
41
uploadVarList . join ( '\n' ) ,
41
42
propsList . join ( '\n' ) ,
42
- methodList . join ( '\n' )
43
+ methodList . join ( '\n' ) ,
44
+ created . join ( '\n' )
43
45
)
44
46
confGlobal = null
45
47
return script
46
48
}
47
49
48
50
// 构建组件属性
49
- function buildAttributes ( scheme , dataList , ruleList , optionsList , methodList , propsList , uploadVarList ) {
51
+ function buildAttributes ( scheme , dataList , ruleList , optionsList , methodList , propsList , uploadVarList , created ) {
50
52
const config = scheme . __config__
51
53
const slot = scheme . __slot__
52
54
buildData ( scheme , dataList )
@@ -58,7 +60,9 @@ function buildAttributes(scheme, dataList, ruleList, optionsList, methodList, pr
58
60
if ( config . dataType === 'dynamic' ) {
59
61
const model = `${ scheme . __vModel__ } Options`
60
62
const options = titleCase ( model )
61
- buildOptionMethod ( `get${ options } ` , model , methodList )
63
+ const methodName = `get${ options } `
64
+ buildOptionMethod ( methodName , model , methodList , scheme )
65
+ callInCreated ( methodName , created )
62
66
}
63
67
}
64
68
@@ -83,11 +87,16 @@ function buildAttributes(scheme, dataList, ruleList, optionsList, methodList, pr
83
87
// 构建子级组件属性
84
88
if ( config . children ) {
85
89
config . children . forEach ( item => {
86
- buildAttributes ( item , dataList , ruleList , optionsList , methodList , propsList , uploadVarList )
90
+ buildAttributes ( item , dataList , ruleList , optionsList , methodList , propsList , uploadVarList , created )
87
91
} )
88
92
}
89
93
}
90
94
95
+ // 在Created调用函数
96
+ function callInCreated ( methodName , created ) {
97
+ created . push ( `this.${ methodName } ()` )
98
+ }
99
+
91
100
// 混入处理函数
92
101
function mixinMethod ( type ) {
93
102
const list = [ ] ; const
@@ -214,16 +223,23 @@ function buildSubmitUpload(scheme) {
214
223
return str
215
224
}
216
225
217
- function buildOptionMethod ( methodName , model , methodList ) {
226
+ function buildOptionMethod ( methodName , model , methodList , scheme ) {
227
+ const config = scheme . __config__
218
228
const str = `${ methodName } () {
219
- // TODO 发起请求获取数据
220
- this.${ model }
229
+ // 注意:this.$axios是通过Vue.prototype.$axios = axios挂载产生的
230
+ this.$axios({
231
+ method: '${ config . method } ',
232
+ url: '${ config . url } '
233
+ }).then(resp => {
234
+ var { data } = resp
235
+ this.${ model } = data.${ config . dataKey }
236
+ })
221
237
},`
222
238
methodList . push ( str )
223
239
}
224
240
225
241
// js整体拼接
226
- function buildexport ( conf , type , data , rules , selectOptions , uploadVar , props , methods ) {
242
+ function buildexport ( conf , type , data , rules , selectOptions , uploadVar , props , methods , created ) {
227
243
const str = `${ exportDefault } {
228
244
${ inheritAttrs [ type ] }
229
245
components: {},
@@ -243,7 +259,9 @@ function buildexport(conf, type, data, rules, selectOptions, uploadVar, props, m
243
259
},
244
260
computed: {},
245
261
watch: {},
246
- created () {},
262
+ created () {
263
+ ${ created }
264
+ },
247
265
mounted () {},
248
266
methods: {
249
267
${ methods }
0 commit comments