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

模板未刷新,暂时手动修改

上级 e2668505
<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>
<script lang="ts"> <script lang="ts">
import {Vue,Component,Prop,Model,Emit,Watch,} from "vue-property-decorator"; import {
import { Subject, Subscription } from "rxjs"; Vue,
Component,
Prop,
Model,
Emit,
Watch,
} from "vue-property-decorator";
import { Subject, Subscription } from "rxjs";
@Component({}) @Component({})
export default class AvueCustomForm extends Vue { export default class AvueCustomForm extends Vue {
/** /**
...@@ -16,8 +23,7 @@ export default class AvueCustomForm extends Vue { ...@@ -16,8 +23,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类型
...@@ -25,8 +31,7 @@ export default class AvueCustomForm extends Vue { ...@@ -25,8 +31,7 @@ export default class AvueCustomForm extends Vue {
* @type {boolean} * @type {boolean}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() @Prop() public isParseString?: boolean;
public isParseString?: boolean;
/** /**
* 远端地址 * 远端地址
...@@ -42,7 +47,7 @@ export default class AvueCustomForm extends Vue { ...@@ -42,7 +47,7 @@ export default class AvueCustomForm extends Vue {
* @type {any} * @type {any}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
@Prop() public value: any; @Model('change') public value: any;
/** /**
* 是否将表单数据通过组件配置带入组件中 * 是否将表单数据通过组件配置带入组件中
...@@ -52,25 +57,6 @@ export default class AvueCustomForm extends Vue { ...@@ -52,25 +57,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));
}
}
/** /**
* 表单数据 * 表单数据
* *
...@@ -89,29 +75,46 @@ export default class AvueCustomForm extends Vue { ...@@ -89,29 +75,46 @@ export default class AvueCustomForm extends Vue {
@Prop() public formState!: Subject<any>; @Prop() public formState!: Subject<any>;
/** /**
* 视图状态事件 * 获取组件值
* *
* @protected * @return {any}
* @type {(Subscription | undefined)}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
protected formStateEvent: Subscription | undefined; get formVal() {
let obj: any = {};
if (this.value) {
if (this.isParseString) obj = JSON.parse(this.value);
else obj = this.value;
}
return obj;
}
/** /**
* 当前组件配置设置属性 * 设置组件值
* *
* @type {any} * @param value
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
public formOption: any = null; set formVal(value: any) {
this.setValue(value);
}
/**
* 订阅对象
*
* @protected
* @type {(Subscription | undefined)}
* @memberof AvueCustomForm
*/
protected formStateEvent: Subscription | undefined;
/** /**
* avue-form绑定值 * 当前组件配置设置属性
* *
* @type {any} * @type {any}
* @memberof AvueCustomForm * @memberof AvueCustomForm
*/ */
public formvalue: any = {}; public formOption: any = null;
/** /**
* avue-form默认配置 * avue-form默认配置
...@@ -189,10 +192,8 @@ export default class AvueCustomForm extends Vue { ...@@ -189,10 +192,8 @@ export default class AvueCustomForm extends Vue {
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) => { get.then((response: any) => {
if (response && response.data && response.data.view_config) { if (response && response.data) {
that.formOption = JSON.parse(response.data.view_config)[ that.formOption = response.data;
"formConfig"
];
if (this.isFormData) that.getFormData(); if (this.isFormData) that.getFormData();
} }
}); });
...@@ -214,7 +215,7 @@ export default class AvueCustomForm extends Vue { ...@@ -214,7 +215,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) => {
...@@ -242,5 +243,17 @@ export default class AvueCustomForm extends Vue { ...@@ -242,5 +243,17 @@ export default class AvueCustomForm extends Vue {
if (this.isParseString) this.$emit("change", JSON.stringify(value)); if (this.isParseString) this.$emit("change", JSON.stringify(value));
else this.$emit("change", value); else this.$emit("change", value);
} }
/**
* 销毁组件(vue生命周期)
*
* @type {Subject<any>}
* @memberof AvueCustomForm
*/
public destroy(){
if(this.formStateEvent){
this.formStateEvent.unsubscribe();
}
}
} }
</script> </script>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册