fix(表单设计器): 修复表单设计级联选择动态数据无法获取问题。

This commit is contained in:
konbai
2022-09-17 21:28:54 +08:00
parent f220dcf002
commit 2206cbb966
6 changed files with 43 additions and 29 deletions

View File

@@ -186,7 +186,7 @@ export const selectComponents = [
label: '级联选择',
url: 'https://www.fastmock.site/mock/f8d7a54fb1e60561e2f720d5a810009d/fg/cascaderList',
method: 'get',
dataPath: 'list',
dataKey: 'list',
dataConsumer: 'options',
showLabel: true,
labelWidth: null,

View File

@@ -232,7 +232,7 @@ function buildOptionMethod(methodName, model, methodList, scheme) {
url: '${config.url}'
}).then(resp => {
var { data } = resp
this.${model} = data.${config.dataPath}
this.${model} = data.${config.dataKey}
})
},`
methodList.push(str)

View File

@@ -1,6 +1,10 @@
import { deepClone } from '@/utils/index';
import { getToken } from '@/utils/auth';
import render from '@/utils/generator/render';
import axios from 'axios'
import Vue from 'vue';
Vue.prototype.$axios = axios
const ruleTrigger = {
'el-input': 'blur',
@@ -140,6 +144,7 @@ export default {
methods: {
initFormData(componentList, formData) {
componentList.forEach(cur => {
this.buildOptionMethod(cur)
const config = cur.__config__;
if (cur.__vModel__) {
formData[cur.__vModel__] = config.defaultValue;
@@ -173,6 +178,21 @@ export default {
}
})
},
// 特殊处理的 Option
buildOptionMethod(scheme) {
const config = scheme.__config__;
if (config && config.tag === 'el-cascader') {
if (config.dataType === 'dynamic') {
this.$axios({
method: config.method,
url: config.url
}).then(resp => {
var { data } = resp
scheme[config.dataConsumer] = data[config.dataKey]
});
}
}
},
buildRules(componentList, rules) {
componentList.forEach(cur => {
const config = cur.__config__