avue-component.vue 2.8 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10
  <div class="avue-component">
    <div v-if="type === 'DynamicForm'">
      <avue-form-design
        :widconfigProps="widconfigProps"
        class="app-form-design"
        style="height: 86vh;"
        :options="formOpt"
        @change="handleChange"
      ></avue-form-design>
11
    </div>
12 13 14 15 16 17 18 19 20 21 22 23 24
    <div v-else-if="type === 'DynamicSubForm'">
      <avue-form-design
        :widconfigProps="widconfigProps"
        class="app-form-design"
        style="height: 86vh;"
        :options="formOpt"
        @change="handleChange"
      ></avue-form-design>
    </div>
    <div v-else-if="type === 'DynamicGrid'">
      <app-avue-crud :colOptions="tableOpt" @change="handleChange"></app-avue-crud>
    </div>
  </div>
25 26
</template>
<script lang="ts">
27 28 29 30 31 32 33 34
import {
  Vue,
  Component,
  Prop,
  Model,
  Emit,
  Watch,
} from "vue-property-decorator";
35 36
import { Subject, Subscription } from "rxjs";
import { component } from "vue/types/umd";
37
import "./avue-component.less";
38 39 40

@Component({})
export default class AvueComponent extends Vue {
41
  @Prop() public type?: string;
42

43
  @Prop() public options?: any;
44

45
  @Prop() public formState!: Subject<any>;
46

47
  @Prop() public name: any;
48

49
  @Prop() public systemid: any;
50

51
  @Prop() public entityname: any;
52

53
  public widconfigProps: Array<any> = [];
54

55 56 57 58 59 60 61 62 63 64
  public formOpt: any = {};

  public tableOpt: any = [];

  public handleChange(val: any) {
    let value: any;
    if (typeof val === "string") {
      value = val;
    } else {
      value = JSON.stringify(val);
65
    }
66 67 68
    let params: any = { name: this.name, value: value };
    this.$emit("formitemvaluechange", params);
  }
69

70 71 72 73 74 75 76 77
  /**
   * 订阅对象
   *
   * @protected
   * @type {(Subscription | undefined)}
   * @memberof AvueComponent
   */
  protected formStateEvent: Subscription | undefined;
78

79 80 81 82 83 84
  public created() {
    let that: any = this;
    if (this.formState) {
      this.formStateEvent = this.formState.subscribe(({ type, data }) => {
        if (Object.is("load", type)) that.load();
      });
85
    }
86
  }
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  public load() {
    let that: any = this;
    let url: string = "lite/Sample/entitys/CITY";
    if (this.systemid && this.entityname) {
      url = `lite/${this.systemid}/entitys/${this.entityname}`;
    }
    this.$http.get(url).then((response: any) => {
      if (response && response.data) {
        let arr: Array<any> = [];
        let data: any = response.data;
        data.fields.forEach((field: any) => {
          arr.push({ value: field.codeName.toLowerCase(), label: field.showName, comment: field.comment });
        });
        that.widconfigProps = arr;
        that.$forceUpdate();
      }
    });
    if (this.options) {
      let opt: any = this.options.replace(/[\n\r]/g, "");
      if (this.type)
        if (this.type.indexOf("Form") > 0) {
          this.formOpt = JSON.parse(opt);
        } else {
          this.tableOpt = JSON.parse(opt);
112 113
        }
    }
114
  }
115 116
}
</script>