提交 30bf7934 编写于 作者: llz's avatar llz

avue自定义配置表单新增动态从主表单配置下拉请求参数

上级 5fb67a50
...@@ -23,7 +23,7 @@ export default class AvueCustomForm extends Vue { ...@@ -23,7 +23,7 @@ export default class AvueCustomForm extends Vue {
* @type {*} * @type {*}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() public options?: any; public options: any;
/** /**
* 是否需要转换为string类型 * 是否需要转换为string类型
...@@ -72,7 +72,7 @@ export default class AvueCustomForm extends Vue { ...@@ -72,7 +72,7 @@ export default class AvueCustomForm extends Vue {
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() @Prop()
public formData: any; public formData?: any;
/** /**
* 表单状态 * 表单状态
...@@ -93,7 +93,8 @@ export default class AvueCustomForm extends Vue { ...@@ -93,7 +93,8 @@ export default class AvueCustomForm extends Vue {
if (this.value) { if (this.value) {
if (this.isParseString) obj = JSON.parse(this.value); if (this.isParseString) obj = JSON.parse(this.value);
else obj = this.value; else obj = this.value;
if (this.isSubForm && obj instanceof Array) obj = this.loadSubFormData(obj); if (this.isSubForm && obj instanceof Array)
obj = this.loadSubFormData(obj);
} }
return obj; return obj;
} }
...@@ -195,22 +196,26 @@ export default class AvueCustomForm extends Vue { ...@@ -195,22 +196,26 @@ export default class AvueCustomForm extends Vue {
* *
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
public load() { public async load() {
let that: any = this; let that: any = this;
if (!this.options && this.options == null) { if (!this.options && this.options == null) {
if (this.url && this.options == null) { if (this.url && this.options == null) {
const get: Promise<any> = this.$http.get(this.url); const get: Promise<any> = this.$http.get(this.url);
get.then((response: any) => { await get.then((response: any) => {
if (response && response.data) { if (response && response.data) {
that.formOption = response.data; let options: any = response.data;
if (this.isFormData) that.getFormData(); this.transitionDicUrlCondition(options);
that.formOption = options;
if (that.isFormData) that.getFormData();
} }
}); });
} else { } else {
this.transitionDicUrlCondition(this.defaultOptions);
this.formOption = this.defaultOptions; this.formOption = this.defaultOptions;
if (this.isFormData) that.getFormData(); if (this.isFormData) that.getFormData();
} }
} else { } else {
this.transitionDicUrlCondition(this.options);
this.formOption = this.options; this.formOption = this.options;
if (this.isFormData) that.getFormData(); if (this.isFormData) that.getFormData();
} }
...@@ -263,8 +268,6 @@ export default class AvueCustomForm extends Vue { ...@@ -263,8 +268,6 @@ export default class AvueCustomForm extends Vue {
public getSubFormData(value: any): Array<any> { public getSubFormData(value: any): Array<any> {
let arr: Array<any> = []; let arr: Array<any> = [];
for (let val in value) { for (let val in value) {
arr = value[val]; arr = value[val];
break; break;
} }
...@@ -283,6 +286,37 @@ export default class AvueCustomForm extends Vue { ...@@ -283,6 +286,37 @@ export default class AvueCustomForm extends Vue {
return value; return value;
} }
/**
* 配置的下拉列表转换符号支持动态配置
*
* @memberof AvueCustomForm
* @param {*}
*/
public transitionDicUrlCondition(options: any) {
let that: any = this;
let recursive: any = function (obj: any) {
if (obj.column && obj.column.length > 0) {
obj.column.forEach((col: any) => {
if (col.dicUrl && col.dicUrl.indexOf("$") > 0) {
let g = /\${[^+]+}/;
let dicGroup = col.dicUrl.match(g);
dicGroup.forEach((dic: any) => {
col.dicUrl = col.dicUrl.replace(
dic,
that.formData[dic.substring(2, dic.length - 1)]
);
});
}
if (col.children) recursive(col.children);
if (col.group) recursive(col.group);
});
}
if (obj.children) recursive(obj.children);
if (obj.group) recursive(obj.group);
};
recursive(options);
}
/** /**
* 销毁组件(vue生命周期) * 销毁组件(vue生命周期)
* *
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册