提交 94233f1c 编写于 作者: llz's avatar llz

修改avue-custom-form组件数据传递方式为双向绑定

上级 9e9286ee
<template> <template>
<div v-if="formOption!=null" class="app-custom-form"> <div v-if="formOption!=null" class="app-custom-form">
<avue-form :option="formOption" v-model="formvalue"></avue-form> <avue-form :option="formOption" v-model="formVal"></avue-form>
</div> </div>
</template> </template>
...@@ -15,7 +15,7 @@ import { ...@@ -15,7 +15,7 @@ import {
} from "vue-property-decorator"; } from "vue-property-decorator";
import { Subject, Subscription } from "rxjs"; import { Subject, Subscription } from "rxjs";
import axios from 'axios'; import axios from "axios";
@Component({}) @Component({})
export default class AvueCustomForm extends Vue { export default class AvueCustomForm extends Vue {
/** /**
...@@ -24,8 +24,7 @@ export default class AvueCustomForm extends Vue { ...@@ -24,8 +24,7 @@ export default class AvueCustomForm extends Vue {
* @type {any} * @type {any}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() @Prop() public options?: any;
public options?: any;
/** /**
* 是否需要转换为string类型 * 是否需要转换为string类型
...@@ -33,8 +32,7 @@ export default class AvueCustomForm extends Vue { ...@@ -33,8 +32,7 @@ export default class AvueCustomForm extends Vue {
* @type {boolean} * @type {boolean}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() @Prop() public isParseString?: boolean;
public isParseString?: boolean;
/** /**
* 远端地址 * 远端地址
...@@ -50,7 +48,7 @@ export default class AvueCustomForm extends Vue { ...@@ -50,7 +48,7 @@ export default class AvueCustomForm extends Vue {
* @type {any} * @type {any}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() public value: any; @Model('change') public value: any;
/** /**
* 是否将表单数据通过组件配置带入组件中 * 是否将表单数据通过组件配置带入组件中
...@@ -60,25 +58,6 @@ export default class AvueCustomForm extends Vue { ...@@ -60,25 +58,6 @@ export default class AvueCustomForm extends Vue {
*/ */
@Prop() public isFormData?: boolean; @Prop() public isFormData?: boolean;
/**
* 监听事件
*
* @param {*} newVal
* @param {*} oldVal
* @memberof AvueCustomForm
*/
@Watch("value")
public onValueChange(newVal: any, oldVal: any) {
if (newVal) {
let obj: any = {};
if (newVal && newVal != null) {
if (this.isParseString) obj = JSON.parse(newVal);
else obj = newVal;
}
if (obj) this.formvalue = JSON.parse(JSON.stringify(obj));
}
}
/** /**
* 表单数据 * 表单数据
* *
...@@ -96,6 +75,31 @@ export default class AvueCustomForm extends Vue { ...@@ -96,6 +75,31 @@ export default class AvueCustomForm extends Vue {
*/ */
@Prop() public formState!: Subject<any>; @Prop() public formState!: Subject<any>;
/**
* 获取组件值
*
* @return {any}
* @memberof AvueCustomForm
*/
get formVal() {
let obj: any = {};
if (this.value) {
if (this.isParseString) obj = JSON.parse(this.value);
else obj = this.value;
}
return obj;
}
/**
* 设置组件值
*
* @param value
* @memberof AvueCustomForm
*/
set formVal(value: any) {
this.setValue(value);
}
/** /**
* 视图状态事件 * 视图状态事件
* *
...@@ -113,14 +117,6 @@ export default class AvueCustomForm extends Vue { ...@@ -113,14 +117,6 @@ export default class AvueCustomForm extends Vue {
*/ */
public formOption: any = null; public formOption: any = null;
/**
* avue-form绑定值
*
* @type {any}
* @memberof AvueCustomForm
*/
public formvalue: any = {};
/** /**
* avue-form默认配置 * avue-form默认配置
* *
...@@ -177,9 +173,9 @@ export default class AvueCustomForm extends Vue { ...@@ -177,9 +173,9 @@ export default class AvueCustomForm extends Vue {
* *
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
public created(){ public created() {
const win: any = window; const win: any = window;
win.axios=axios; win.axios = axios;
Vue.use(win.AVUE); Vue.use(win.AVUE);
} }
...@@ -209,9 +205,7 @@ export default class AvueCustomForm extends Vue { ...@@ -209,9 +205,7 @@ export default class AvueCustomForm extends Vue {
const get: Promise<any> = this.$http.get(this.url); const get: Promise<any> = this.$http.get(this.url);
get.then((response: any) => { get.then((response: any) => {
if (response && response.data && response.data.view_config) { if (response && response.data && response.data.view_config) {
that.formOption = JSON.parse(response.data.view_config)[ that.formOption = JSON.parse(response.data);
"formConfig"
];
if (this.isFormData) that.getFormData(); if (this.isFormData) that.getFormData();
} }
}); });
...@@ -233,7 +227,7 @@ export default class AvueCustomForm extends Vue { ...@@ -233,7 +227,7 @@ export default class AvueCustomForm extends Vue {
public getFormData() { public getFormData() {
let that: any = this; let that: any = this;
let obj: any; let obj: any;
if (this.value) obj = JSON.parse(JSON.stringify(this.value)); if (this.formVal) obj = JSON.parse(JSON.stringify(this.formVal));
else obj = {}; else obj = {};
let recursionOption: any = function (group: any) { let recursionOption: any = function (group: any) {
group.column.forEach((gItem: any) => { group.column.forEach((gItem: any) => {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册