田源
2023-09-05 a0afca557a160565e2aafb781500023a9f2a36d9
Source/UBCS-WEB/src/components/FormTemplate/FormTemplate.vue
@@ -50,7 +50,7 @@
    // 默认禁用元素
    disabledProp: {
      type: Array,
      default: () => ["id","lcstatus"],
      default: () => ["id", "lcstatus"],
    },
    templateOid: {
      type: String,
@@ -80,6 +80,11 @@
      type: Object,
      default: () => ({}),
    },
    // 一行放几个表单
    trendsSpan: {
      type: Number,
      default: 8,
    }
  },
  data() {
    return {
@@ -103,9 +108,6 @@
        date: "date",
        refer: "refer",
      },
      // 假数据
      testItems: [],
      trendsSpan: 8,
      defaultValue: {},
      // 表单属性
      attributes: [],
@@ -114,6 +116,16 @@
  },
  mounted() {
    this.handleResize();
  },
  computed: {
    localTrendsSpan() {
      if (this.trendsSpan) {
        return this.trendsSpan;
      } else {
        let windowWidth = document.body.clientWidth;
        return 24 / Math.floor(windowWidth / 500);
      }
    },
  },
  methods: {
    // 渲染表单模板
@@ -137,7 +149,8 @@
        if (
          formItem.type === "combox" &&
          formItem.comboxKey &&
          (!Array.isArray(formItem.dicData) || formItem.dicData.length === 0) &&(!Array.isArray(formItem.data) || formItem.data.length === 0)
          (!Array.isArray(formItem.dicData) || formItem.dicData.length === 0) &&
          (!Array.isArray(formItem.data) || formItem.data.length === 0)
        ) {
          dictKeys.push({ dictKey: formItem.comboxKey, field: formItem.field });
        }
@@ -145,9 +158,9 @@
        if (this.disabledProp.includes(formItem.field)) {
          formItem.readOnly = true;
        }
        if(formItem.field=='lcstatus'){
          formItem.field=formItem.field+'_text';
          formItem.readOnly=true;
        if (formItem.field == "lcstatus") {
          formItem.field = formItem.field + "_text";
          formItem.readOnly = true;
        }
        // 设置表单校验的规则,文本
        let message = "请选择";
@@ -155,6 +168,12 @@
        if (formItem.type === "text") {
          message = "请输入";
          trigger = "blur";
        }
        let fieldMapKey=''
        if( formItem.type == "refer"){
          if(!formItem.fieldMap){
            fieldMapKey=formItem.field+'Id'
          }
        }
        let columnItem = {
          label: formItem.text,
@@ -186,15 +205,21 @@
                  title: formItem.text,
                  showField: formItem.showField || formItem.field,
                  field: formItem.field,
                  fieldMap:formItem.fieldMap || {fieldMapKey:'id'},
                  placeholder: formItem.inputTip,
                  options: formItem.referConfig,
                  options: formItem.referConfig
                }
              : {},
          span: formItem.span ? formItem.span : formItem.type === "textarea" ? 24 : this.trendsSpan,
          span: formItem.span
            ? formItem.span
            : formItem.type === "textarea"
            ? 24
            : this.localTrendsSpan,
          rules: [
            {
              required: formItem.required,
              message: `请${message}${formItem.text}`,
              message: `${message}${formItem.text}`,
              trigger,
            },
            {
@@ -260,9 +285,9 @@
    },
    // 根据屏幕动态配置表单布局
    handleResize() {
      let windowWidth = document.body.clientWidth;
      this.trendsSpan = 24 / Math.floor(windowWidth / 500);
      this.updateIndex++;
      // let windowWidth = document.body.clientWidth;
      // this.trendsSpan = 24 / Math.floor(windowWidth / 500);
      // this.updateIndex++;
    },
    // 前后缀
    preOrSufFixShow(type, val) {
@@ -337,6 +362,42 @@
      if (data.field) {
        this.form[data.field] = data.value || "";
        this.form[data.showField] = data.text || "";
        if (data.fieldMap) {
          //说明需要映射
          for (let key in data.fieldMap) {
            let mapFields = data.fieldMap[key].split(",");
            let value = [];
            data.rawData.forEach(_item => {
              var temp;
              if (!_item.attributes) {
                _item.attributes = _item;
              }
              if (mapFields.length == 1) {
                var mapField = mapFields[0];
                if (mapField.indexOf("attribute.") > -1) {
                  temp = _item['attributes'][mapField.subString("attribute.".length)];
                } else {
                  temp = _item['attributes'][mapField] || _item[mapField];
                }
              } else {
                //有多个
                var mutiTemp = [];
                layui.each(mapFields, function (_indexField, _itemField) {
                  if (_itemField.indexOf("attribute.") > -1) {
                    mutiTemp.push(_item['attributes'][_itemField.subString("attribute.".length)]);
                  } else {
                    mutiTemp.push(_item['attributes'][_itemField] || _item[_itemField]);
                  }
                });
                temp = mutiTemp.join(' ');
              }
              if (temp != null && temp != '') {
                value.push(temp);
              }
            })
            this.form[key] = value.join(',');
          }
        }
        this.$emit("getFormData", this.form);
        this.$emit("referConfigDataUpdate", data);
      }