Преглед на файлове

表单组布局组件样式渲染

lph преди 1 година
родител
ревизия
d4f7bd5416

+ 16 - 0
zkqy-ui/src/components/FormGroup/formList.vue

@@ -38,6 +38,12 @@ export default {
         return [];
       },
     },
+    layoutData: {
+      type: String,
+      default: () => {
+        return "";
+      },
+    },
   },
   components: {},
   data() {
@@ -100,6 +106,16 @@ export default {
       // });
       // return this.formList;
     },
+    isLayout() {
+      if (!this.layoutData) {
+        return false;
+      }
+      let layoutData = JSON.parse(this.layoutData);
+      if (!layoutData.list?.length) {
+        return false;
+      }
+      return true;
+    },
   },
   watch: {
     myFormList: {

+ 32 - 4
zkqy-ui/src/views/tablelist/commonTable/listInfo.vue

@@ -263,10 +263,15 @@
         </div>
         <template>
           <FormList
-            v-show="formType == 'dragFormGroup' && !times"
+            v-if="formType == 'dragFormGroup' && !times && !isLayout"
             ref="formGroupRef"
             :formList="formList"
           ></FormList>
+          <LayoutIndex
+            v-else-if="formType == 'dragFormGroup' && !times && isLayout"
+            ref="formGroupRef"
+            :layoutData="layoutData"
+          ></LayoutIndex>
           <!-- <div v-show="times" class="times">
             <i class="el-icon-loading" style="font-size: 30px"></i>
           </div> -->
@@ -390,12 +395,21 @@ import DialogTemplate from "@/views/dialogTemplate/components/index.vue";
 import FormList from "@/components/FormGroup/formList.vue";
 import { v4 as uuidv4 } from "uuid";
 import printHtml from "./print";
+import LayoutIndex from "@/views/tablelist/components/FormGroupLayout/LayoutIndex.vue";
 // let times = 2; //请求次数
 export default {
   name: "listInfo",
-  components: { Queryfrom, Menu, DialogTemplate, FormList, BtnMenuList },
+  components: {
+    Queryfrom,
+    Menu,
+    DialogTemplate,
+    FormList,
+    BtnMenuList,
+    LayoutIndex,
+  },
   data() {
     return {
+      layoutData: "", //表单组布局数据
       times: 2, //请求次数
       // 提示信息 start
       toastMsg: "",
@@ -850,6 +864,7 @@ export default {
     },
     /** 修改按钮操作 */
     async handleUpdate(row, btnData) {
+      console.log("handleUpdate");
       let nameTable = this.templateInfo.template.dtTableName;
       this.rowobj = {};
       let obj = {};
@@ -904,7 +919,7 @@ export default {
           },
           conditionMap: {},
         };
-        console.log("primary", primary);
+        console.log("primary111", primary);
         payLoad.conditionMap[this.templateInfo.template?.primaryKey] =
           row[primary];
         // }
@@ -930,14 +945,23 @@ export default {
             this.$message.error("当前按钮未绑定表单!");
             return;
           }
+          console.log(res);
           if (btnFormType == "dragFormGroup") {
             //表单组
             if (res.code == 200) {
               if (res.data.mainForm) {
                 //表单组
                 // console.log(res.data);
-
+                // 判断是否有布局数据
+                this.isLayout =
+                  res.data.layoutJson &&
+                  JSON.parse(res.data.layoutJson)?.list.length > 0;
                 this.transformDataFormat(res.data);
+                if (this.isLayout) {
+                  //自定义布局
+                  this.layoutData = res.data;
+                }
+
                 // this.tableName = res.data.mainForm.showTemplate.dfTableName;
               } else {
                 this.formList = res.data;
@@ -1185,6 +1209,10 @@ export default {
         });
       }
     },
+    // 格式化表单组布局数据
+    formateLayout(data) {
+      let { layoutJson, mainForm, subFormList } = data;
+    },
     // 添加真正的字段名
     addRealFieldName(row) {
       let fieldList = Object.keys(row);

+ 196 - 0
zkqy-ui/src/views/tablelist/components/FormGroupLayout/LayoutIndex.vue

@@ -0,0 +1,196 @@
+<template>
+  <div class="">
+    <LayoutItem
+      v-for="(item, index) of layoutJson.list"
+      :key="index"
+      :record="item"
+      ref="layoutItemRef"
+    ></LayoutItem>
+  </div>
+</template>
+
+<script>
+import { camelCase, toUnderline } from "@/utils";
+import LayoutItem from "./LayoutItem.vue";
+export default {
+  name: "LayoutIndex",
+  props: ["layoutData"],
+  components: { LayoutItem },
+  data() {
+    return {
+      FormNameList: [],
+      formList: [],
+      layoutJson: {},
+    };
+  },
+  watch: {
+    myLayoutData: {
+      handler(newVal, oldVal) {
+        if (newVal) {
+          this.initLayoutData(newVal);
+        }
+      },
+      deep: true,
+      immediate: true,
+    },
+  },
+  computed: {
+    myLayoutData() {
+      return this.layoutData;
+    },
+  },
+  methods: {
+    initLayoutData(formData) {
+      let { layoutJson, mainForm, subFormList } = formData;
+      this.layoutJson = JSON.parse(layoutJson);
+      console.log(formData);
+      this.transformDataFormat(formData);
+      this.formArray = this.disableHandler(this.formList);
+      this.setFormInfo(this.layoutJson.list);
+      console.log("this.formArray", this.formArray);
+      console.log("this.layoutJson", this.layoutJson);
+      console.log("this.FormNameList", this.FormNameList);
+      console.log("this.formList", this.formList);
+    },
+    // 格式化表单数据
+    transformDataFormat(data) {
+      this.FormNameList = [];
+      let { mainForm, subFormList } = data;
+      this.formList = [];
+      let showValue = null;
+      if (mainForm.showValue) {
+        showValue = mainForm.showValue[0]?.resultMap;
+      }
+
+      if (showValue) {
+        for (const key of Object.keys(showValue)) {
+          if (key != "remark") {
+            showValue[toUnderline(key)] = showValue[key];
+            delete showValue[key];
+          }
+        }
+        mainForm.showTemplate.resultMap = [showValue];
+      }
+
+      this.formList.push({
+        template: mainForm.showTemplate,
+        tableName: mainForm.mainFormTable,
+        formKey: mainForm.formKey,
+      });
+      this.FormNameList.push({
+        formKey: mainForm.formKey,
+        tableName: mainForm.mainFormTable,
+        formItem: mainForm.mainFormItem,
+        relateFormItem: null,
+        formType: mainForm.showTemplate.spare == "2" ? "batch" : "normal",
+        defaultValue: mainForm.showValue ? mainForm.showValue[0].resultMap : {},
+      });
+      if (subFormList && subFormList.length > 0) {
+        subFormList.forEach((item) => {
+          let showValue = null;
+          if (item.showValue) {
+            showValue = item.showValue[0];
+          }
+          let defaultValue = {};
+          if (showValue) {
+            if (item.showTemplate.spare == "2") {
+              //动态表格表单
+              let batch = {},
+                tableName = item.formItem?.split(".")?.[0];
+              batch[tableName] = item.showValue.map((item) => item.resultMap);
+              defaultValue = JSON.parse(JSON.stringify(batch));
+              console.log(JSON.parse(JSON.stringify(batch)));
+              // 所有字段驼峰转下划线
+              batch[tableName].forEach((i) => {
+                for (const key of Object.keys(i)) {
+                  i[toUnderline(key)] = i[key];
+                  if (toUnderline(key) != key) {
+                    delete i[key];
+                  }
+                }
+              });
+              item.showTemplate.resultMap = [
+                {
+                  batch,
+                },
+              ];
+            } else {
+              for (const key of Object.keys(item.showValue[0].resultMap)) {
+                item.showValue[0].resultMap[toUnderline(key)] =
+                  item.showValue[0].resultMap[key];
+                delete item.showValue[0].resultMap[key];
+              }
+
+              item.showTemplate.resultMap = [item.showValue[0].resultMap];
+            }
+          }
+          this.formList.push({
+            template: item.showTemplate,
+            tableName: item.formItem?.split(".")?.[0],
+            formKey: item.formKey,
+          });
+          this.FormNameList.push({
+            formKey: item.formKey,
+            tableName: item.formItem?.split(".")?.[0],
+            formItem: item.formItem,
+            relateFormItem: item.relateMainItem,
+            formType: item.showTemplate.spare == "2" ? "batch" : "normal",
+            defaultValue,
+            insertMap: item.insertMap,
+          });
+        });
+      }
+    },
+    // 调整数据格式
+    disableHandler(formList) {
+      if (formList.length == 0) return [];
+      formList.forEach((item) => {
+        item.template.dfFormSql =
+          typeof item.template.dfFormSql == "object"
+            ? item.template.dfFormSql
+            : JSON.parse(item.template.dfFormSql);
+        item.template.dfVueTemplate =
+          typeof item.template.dfVueTemplate == "object"
+            ? item.template.dfVueTemplate
+            : JSON.parse(item.template.dfVueTemplate);
+
+        if (item.template.resultMap) {
+          item.template.defaultValue = item.template.resultMap[0]
+            ? item.template.resultMap[0]
+            : {};
+        }
+      });
+      return formList;
+    },
+    // 递归设置表单数据
+    setFormInfo(list) {
+      list.forEach((item) => {
+        if (["tabs", "grid"].includes(item.type)) {
+          item.columns.forEach((i) => {
+            this.setFormInfo(i.list);
+          });
+        }
+        if (item.type == "form") {
+          let targeForm = this.formArray.find((i) => i.formKey == item.formKey);
+          item.dfVueTemplate = targeForm.template.dfVueTemplate;
+          item.defaultValue = targeForm.template.defaultValue
+            ? targeForm.template.defaultValue
+            : {};
+          item.dynamicData = targeForm.template.dfFormSql
+            ? targeForm.template.dfFormSql
+            : {};
+          item.tableName = targeForm.tableName;
+        }
+      });
+    },
+    // 获取所有表单数据
+    getFormData() {
+      this.$refs["layoutItemRef"].forEach((element) => {
+        console.log(element.getFormData());
+      });
+    },
+  },
+};
+</script>
+
+<style scoped lang="scss"></style>

+ 140 - 0
zkqy-ui/src/views/tablelist/components/FormGroupLayout/LayoutItem.vue

@@ -0,0 +1,140 @@
+<template>
+  <div class="layout-width">
+    <template v-if="record.type == 'tabs'">
+      <div class="grid-box" @click.stop="handleSelectItem(record)">
+        <el-tabs value="1">
+          <el-tab-pane
+            v-for="(tabItem, index) in record.columns"
+            :key="index"
+            :label="tabItem.label"
+            :name="index + ''"
+          >
+            <div class="grid-box-content">
+              <LayoutItem
+                class="drag-move"
+                v-for="(item, index) in tabItem.list"
+                :key="index"
+                :record="item"
+                @handleDelete="handleDelete"
+              />
+            </div>
+          </el-tab-pane>
+        </el-tabs>
+      </div>
+    </template>
+    <template v-else-if="record.type == 'grid'">
+      <!-- 栅格布局 -->
+      <div class="grid-box" @click.stop="handleSelectItem(record)">
+        <el-row class="grid-row" :gutter="record.options.gutter">
+          <el-col
+            class="grid-col"
+            v-for="(colItem, idnex) in record.columns"
+            :key="idnex"
+            :span="colItem.span || 0"
+          >
+            <div class="grid-box-content">
+              <LayoutItem
+                class="drag-move"
+                v-for="(item, index) in colItem.list"
+                :key="index"
+                :record="item"
+                @handleDelete="handleDelete"
+              />
+            </div>
+          </el-col>
+        </el-row>
+      </div>
+    </template>
+    <template v-else-if="record.type == 'divider'">
+      <!-- 分割线 -->
+      <div class="grid-box divider-wrap" style="width: 100%">
+        <el-divider
+          @click.stop="handleSelectItem(record)"
+          :content-position="record.options.orientation"
+          >{{ record.options.title || "" }}</el-divider
+        >
+      </div>
+    </template>
+    <template v-else-if="record.type == 'form'">
+      <k-form-build :value="record.dfVueTemplate"></k-form-build>
+    </template>
+  </div>
+</template>
+
+<script>
+// import KFormDesign from "./KFormDesign.vue";
+export default {
+  name: "LayoutItem",
+  props: ["record", "formData"],
+  data() {
+    return {};
+  },
+  computed: {},
+  watch: {
+    record() {
+      console.log("record", this.record);
+    },
+  },
+  methods: {
+    // 获取表单json数据
+    getFormJson(formKey) {
+      return this.formData.filter((item) => item.formKey == formKey)
+        ?.dfVueTemplate;
+    },
+    // 删除
+    deleHandle(record) {
+      console.log("dele", record);
+      this.$emit("handleDelete", record);
+    },
+    handleSelectItem(record) {
+      this.$emit("handleSelectItem", record);
+    },
+    handleDelete(record) {
+      this.$emit("handleDelete", record);
+    },
+    // 获取表单数据
+    getFormData() {
+      return new Promise((resolve, reject) => {
+        let { tableName } = this.record;
+        if (this.record.type == "form") {
+          this.$refs.formBuild.getData().then((values) => {
+            resolve({
+              tableName,
+              data: values,
+            });
+          });
+        }
+      });
+    },
+  },
+};
+</script>
+
+<style scoped lang="scss">
+.grid-box-content {
+  min-height: 60px !important;
+  min-width: 50px !important;
+  border: 1px dashed #ccc;
+  background: #fff;
+}
+.layout-width {
+  position: relative;
+  .delete {
+    position: absolute;
+    top: 0;
+    right: 0;
+    width: 30px;
+    height: 30px;
+    line-height: 30px;
+    text-align: center;
+    color: #ee88e5;
+  }
+}
+.divider-wrap {
+  height: 50px;
+  background: #fff;
+  display: flex;
+  border: 1px dashed #ccc;
+  justify-content: center;
+}
+</style>