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

数据统计修改删除回显功能,表格联动基础搭建

Zn преди 1 година
родител
ревизия
5e0e8b434a

+ 44 - 0
ruoyi-ui/src/api/relateTable/index.js

@@ -0,0 +1,44 @@
+import request from '@/utils/request'
+
+// 查询拖拽格组列表
+export function listGroup(query) {
+  return request({
+    url: '/system/group/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询拖拽格组详细
+export function getGroup(id) {
+  return request({
+    url: '/system/group/' + id,
+    method: 'get'
+  })
+}
+
+// 新增拖拽格组
+export function addGroup(data) {
+  return request({
+    url: '/system/group',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改拖拽格组
+export function updateGroup(data) {
+  return request({
+    url: '/system/group',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除拖拽格组
+export function delGroup(id) {
+  return request({
+    url: '/system/group/' + id,
+    method: 'delete'
+  })
+}

+ 12 - 5
ruoyi-ui/src/api/system/menu.js

@@ -61,9 +61,16 @@ export function updateMenu(data) {
 }
 
 // 删除菜单
+// export function delMenu(menuId) {
+//   return request({
+//     url: '/system/menu/' + menuId,
+//     method: 'delete'
+//   })
+// }
+
 export function delMenu(menuId) {
-  return request({
-    url: '/system/menu/' + menuId,
-    method: 'delete'
-  })
-}
+    return request({
+      url: '/system/menu/removeBatch/' + menuId,
+      method: 'delete',
+    })
+  }

+ 19 - 9
ruoyi-ui/src/views/dragform/tableList.vue

@@ -237,6 +237,8 @@ export default {
       loading: true,
       // 选中数组
       ids: [],
+      // 选中tablekey
+      tableKeys: [],
       // 选中数组(包含所有数据)
       selection: [],
       Keys: [],
@@ -275,6 +277,8 @@ export default {
       form: {},
       // 表单校验
       rules: {},
+      // 多选框勾选数据
+      tempSelection: [],
     };
   },
   created() {
@@ -288,17 +292,17 @@ export default {
     /** 查询动态格列表 */
     getList() {
       this.loading = true;
-      let tempSelection = JSON.parse(JSON.stringify(this.selection));
+      this.tempSelection = JSON.parse(JSON.stringify(this.selection));
       listTable(this.queryParams).then((response) => {
         response.rows = response.rows.filter(
-          (item) => !tempSelection.find((val) => val.tId == item.tId)
+          (item) => !this.tempSelection.find((val) => val.tId == item.tId)
         );
-        this.tableList = [...tempSelection, ...response.rows];
+        this.tableList = [...this.tempSelection, ...response.rows];
         this.total = response.total;
         this.loading = false;
-        if (tempSelection.length) {
+        if (this.tempSelection.length) {
           this.$nextTick(() => {
-            tempSelection.forEach((item) => {
+            this.tempSelection.forEach((item) => {
               this.$refs.tableRef.toggleRowSelection(item);
             });
           });
@@ -346,6 +350,7 @@ export default {
     // 多选框选中数据
     handleSelectionChange(selection) {
       this.ids = selection.map((item) => item.tId);
+      this.tableKeys = selection.map((item) =>item.tableKey);
       this.Keys = selection.map((item) => item.sqlKey);
       this.menuIds = selection.map((item) => item.menuId);
       this.selection = selection;
@@ -410,8 +415,10 @@ export default {
       if (row.tId && row.sqlKey) {
         data.tIds = [row.tId];
         data.sqlKeys = [row.sqlKey];
+        data.tableKeys = [row.tableKey];
         menuIdList.push(row.menuId);
       } else {
+        data.tableKeys = this.tableKeys;
         data.tIds = this.ids;
         data.sqlKeys = this.Keys;
         menuIdList = this.menuIds;
@@ -424,10 +431,12 @@ export default {
             '"的数据项?删除后菜单中相关数据也将删除!'
         )
         .then(async function () {
-          let res = await delMenu(row.menuId);
+          let res = await delMenu(menuIdList);
+          // await delStatistic(row.tableKey) 
+
+          //  await removeTableList(data);
+
           if (res.code == 200) { 
-            console.log(row.tableKey);
-            await delStatistic(row.tableKey) 
             await removeTableList(data);
           } else {
             return Promise.reject();
@@ -453,10 +462,11 @@ export default {
         })
         .then(() => {
           this.getList();
+          this.tempSelection = []
           this.reloadRouter();
           this.$modal.msgSuccess("删除成功");
         })
-        .catch(() => {});
+        .catch((e) => {console.log(e);});
     },
     // 更新路由
     reloadRouter() {

+ 302 - 131
ruoyi-ui/src/views/relateTable/index.vue

@@ -38,7 +38,7 @@
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
-          >新增</el-button
+          >新增123</el-button
         >
       </el-col>
 
@@ -62,15 +62,30 @@
 
     <el-table
       v-loading="loading"
-      :data="tableList"
+      :data="tableGroupList"
       ref="tableRef"
       @selection-change="handleSelectionChange"
     >
       <el-table-column type="selection" width="55" align="center" />
-      <el-table-column label="表格组名" align="center" prop="tId" />
-      <el-table-column label="描述" align="center" prop="dtName" />
-      <el-table-column label="表格数" align="center" prop="dtNickname" />
-      <el-table-column label="成员表格" align="center" prop="tableKey" />
+      <el-table-column label="表格组名" align="center" prop="groupname" />
+      <el-table-column label="描述" align="center" prop="groupdescribe" />
+      <el-table-column label="表格数" align="center" prop="groupcount" />
+
+      <el-table-column
+        label="成员表格"
+        width="180"
+        >
+        <template slot-scope="scope">
+          <el-popover trigger="hover" placement="top">
+            <p v-for="(item,index) in scope.row.contentList"> {{ item.tableName}}</p>
+            
+            <div slot="reference" class="name-wrapper">
+            <el-tag size="medium">{{ scope.row.tableKey }}</el-tag>
+            </div>
+          </el-popover>
+        </template>
+      </el-table-column>
+
       <el-table-column
         label="操作"
         align="center"
@@ -87,7 +102,7 @@
                   size="mini"
                   type="text"
                   icon="el-icon-edit"
-                  @click="handleUpdate(scope.row)"
+                  @click="UpdateTableGroup(scope.row)"
                   >修改
                 </el-button>
               </el-dropdown-item>
@@ -114,7 +129,7 @@
       @pagination="getList"
     />
     <!-- 新增联动表格组弹窗 -->
-    <el-dialog title="新增动态表格组" :visible.sync="isShowTable" width="50%">
+    <el-dialog :title="groupTitle ? '新增动态表格组' : '修改动态表格组'" :visible.sync="isShowTable">
       <div class="dialog_wrap">
         <el-button
           type="primary"
@@ -136,29 +151,18 @@
           stripe
           @selection-change="handleSelectionChange"
         >
-          <el-table-column type="index" width="50" />
-          <el-table-column label="标题" prop="title" />
+          <el-table-column label="序号" type="index" />
+          <el-table-column label="表格标题" prop="title" />
           <el-table-column
-            label="表格名"
+            label="表格名"
             prop="tableName"
-            type="index"
-            width="50"
           ></el-table-column>
-          <el-table-column label="显示字段" prop="showFields">
-            <template slot-scope="scope">
-              {{ scope.row.showFields }}
-            </template>
-          </el-table-column>
-          <el-table-column label="关联字段" prop="theRelateField">
+          <el-table-column label="关联字段" prop="selectFields">
             <template slot-scope="scope">
-              {{ scope.row.theRelateField }}
-            </template>
-          </el-table-column>
-          <el-table-column label="可执行操作" prop="executeOptions">
-            <template slot-scope="scope">
-              {{ scope.row.executeOptions }}
+              {{ scope.row.selectFields }}
             </template>
           </el-table-column>
+
           <el-table-column
             label="操作"
             align="center"
@@ -175,7 +179,7 @@
                       size="mini"
                       type="text"
                       icon="el-icon-edit"
-                      @click="handleUpdate(scope.row)"
+                      @click="relateOne(scope.row)"
                       >修改
                     </el-button>
                   </el-dropdown-item>
@@ -197,20 +201,21 @@
       <template #footer>
         <span>
           <el-button @click="isShowTable = false">取消</el-button>
-          <el-button type="primary" @click="() => {}">确认</el-button>
+          <el-button type="primary" @click="addTableGroup">确认</el-button>
         </span>
       </template>
     </el-dialog>
+
     <!-- 编辑某一条表格数据弹窗 -->
-    <el-dialog title="添加关联表格" :visible.sync="isShowForm" width="500px">
+    <el-dialog :title="relateTitle ? '添加关联表格' :'修改关联表格' " :visible.sync="isShowForm" width="800px">
       <div class="formWrap">
         <el-form
           ref="tableItemForm"
-          style="max-width: 350px"
+          style="max-width: 750px; width: 700px"
           :model="tableItemForm"
           label-width="100px"
         >
-          <el-form-item label="标题:">
+          <el-form-item label="表格标题:">
             <el-input
               v-model="tableItemForm.title"
               style="max-width: 221px"
@@ -218,43 +223,81 @@
           </el-form-item>
           <el-form-item label="表格名称:">
             <el-select
-              v-model="tableItemForm.tableId"
+              v-model="tableItemForm.tableName"
+              @change="getList()"
               placeholder="请选择表格名称"
             >
-              <el-option label="表格一" value="1"></el-option>
-              <el-option label="表格二" value="2"></el-option>
-            </el-select>
-          </el-form-item>
-          <el-form-item label="展示字段:">
-            <el-select
-              v-model="tableItemForm.showFields"
-              multiple
-              filterable
-              placeholder="请选择展示字段"
-            >
-              <el-option label="字段1" value="field1"></el-option>
-              <el-option label="字段2" value="field2"></el-option>
+              <el-option
+              v-for="item in tableList"
+              :key="item.tableName"
+              :label="item.tableComment"
+              :value="item.tableName"
+              >
+              <span style="float: left">{{ item.tableComment }}</span>
+              <span style="float: right; color: #8492a6; font-size: 13px">{{
+                item.tableName
+              }}</span>
+              </el-option>
             </el-select>
           </el-form-item>
           <el-form-item label="关联字段:">
             <el-select
-              v-model="tableItemForm.theRelateField"
+              v-model="tableItemForm.selectFields"
               placeholder="请选择关联字段"
             >
-              <el-option label="关联1" value="1"></el-option>
-              <el-option label="关联2" value="2"></el-option>
+            <el-option
+              v-for="item in tableFieldList"
+              :key="item.fieldName"
+              :label="item.fieldDescription"
+              :value="item.fieldName"
+            >
+              <span style="float: left">{{ item.fieldDescription }}</span>
+              <span style="float: right; color: #8492a6; font-size: 13px">{{
+                item.fieldName
+              }}</span>
+            </el-option>
             </el-select>
           </el-form-item>
-          <el-form-item label="可执行操作:">
-            <el-select
-              v-model="tableItemForm.executeOptions"
-              multiple
-              filterable
-              placeholder="请选择执行操作"
+          <el-form-item label="展示字段:">
+            <el-table
+            :data="tableFieldList"
+            border
+            ref="dragTable"
+            row-key="id"
+            max-height="500px"
             >
-              <el-option label="操作1" value="field1"></el-option>
-              <el-option label="操作2" value="field2"></el-option>
-            </el-select>
+            
+            <el-table-column
+              type="index"
+              label="序号"
+              width="50"
+              class-name="allowDrag"
+            >
+            </el-table-column>
+            <el-table-column prop="fieldName" label="数据字段">
+            </el-table-column>
+            <el-table-column prop="fieldDescription" label="字段描述">
+              <template slot-scope="scope">
+                <input
+                  :class="{
+                    isNullDesc:
+                      scope.row.fieldDescription == '' &&
+                      scope.row.isShow &&
+                      isInputInvalid
+                        ? true
+                        : false,
+                    ipt: true,
+                  }"
+                  v-model="scope.row.fieldDescription"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column prop="isShow" label="是否显示">
+              <template slot-scope="scope">
+                <el-switch v-model="scope.row.isShow"> </el-switch>
+              </template>
+            </el-table-column>
+          </el-table>
           </el-form-item>
         </el-form>
       </div>
@@ -269,14 +312,24 @@
 </template>
 <script>
 import { listTable, removeTableList } from "@/api/dragform/tableList";
+import {
+  getFormName,
+  getListName,
+  dragTablePreview,
+} from "@/api/dragform/form.js";
 import { delMenu } from "@/api/system/menu";
-import { mapGetters } from "vuex";
+import { addGroup } from '@/api/relateTable/index.js'
+import { addDragTable } from "@/api/tablelist/commonTable.js";
+import { mapGetters, mapState } from "vuex";
 import DictData from "@/components/DictData";
+import { FastBackwardFill } from "@/components/updateModule/k-form-design/lib/k-form-design.common";
 
 export default {
   name: "relateTable",
   data() {
     return {
+      // 修改row
+      updataGroupRow:{},
       // 遮罩层
       loading: false,
       // 选中数组
@@ -293,8 +346,7 @@ export default {
       showSearch: true,
       // 总条数
       total: 0,
-      // 动态格表格数据
-      tableList: [],
+      tableList: [], //所有表格列表
       // 弹出层标题
       title: "",
       // 是否显示弹出层
@@ -323,57 +375,181 @@ export default {
       // dialog弹窗数据
       isShowTable: false,
       isShowForm: false,
-      tableDataList: [
-        {
-          title: "",
-          tableId: "",
-          tableName: "",
-          showFields: [],
-          theRelateField: "",
-          executeOptions: [],
-        },
-      ],
+      // 新增关联表数据
+      tableDataList: [],
 
+      tableFieldList: [], // 当前表格字段数据
+      tableName: "", // 当前表名称
+      selectFields: '', //关联字段
+      relateTitle: true,
+      relateTableName: "", //关联表名称
+      relateFields: "", //子集关联字段
+      relateFieldList: [], //子集关联字段数据
+      groupTitle: true,
       tableItemForm: {
         title: "",
-        tableId: "",
         tableName: "",
-        showFields: [],
-        theRelateField: "",
-        executeOptions: [],
+        selectFields: "",
       },
       groupname: '',
-      groupdescribe: ''
+      groupdescribe: '',
+      tableGroupList: [],
+      // 成员表格提示
+      tableKeyContent: '',
     };
   },
   created() {
     // this.getList();
   },
   computed: {
+    selectRelate(){
+      if(this.tableItemForm.tableName =='') return
+      return this.tableList.filter(item => item.tableName !== this.tableItemForm.tableName)
+    },
+    dataArr() {
+      return this.tableFieldList.filter((item) => item.isShow);
+    },
     ...mapGetters(["addRoutes"]),
+    ...mapState({
+      databaseName: (state) => state.user.dataSource.databaseName,
+      databaseType: (state) => state.user.dataSource.databaseType,
+      username: (state) => state.user.dataSource.username,
+    }),
+  },
+  watch: {
+    'tableItemForm.tableName': function (val) {
+      if (val) {
+        this.relationTableList = this.tableList
+          .filter((item) => item.tableName != val)
+          .map((item) => {
+            return {
+              tableName: item.tableName,
+              tableComment: item.tableComment,
+            };
+          });
+      } else {
+        this.relationTableList = [];
+      }
+    },
   },
-
   methods: {
-    /** 查询动态格列表 */
-    getList() {
-      this.loading = true;
-      let tempSelection = JSON.parse(JSON.stringify(this.selection));
-      listTable(this.queryParams).then((response) => {
-        response.rows = response.rows.filter(
-          (item) => !tempSelection.find((val) => val.tId == item.tId)
+    /** 查询列表 */
+    getList(queryParams) {
+      if (!this.tableItemForm.tableName) return;
+      let data = {
+        databaseName: this.databaseName,
+        databaseType: this.databaseType,
+        tableName: this.tableItemForm.tableName,
+      };
+      
+      // 获取当前表单结构信息
+      getListName(data).then((res) => {
+        this.tableFieldList = res.map((item, index) => {
+          return {
+            id: this.tableItemForm.tableName + "_" + item.fieldName,
+            fieldName: item.fieldName,
+            fieldDescription: item.fieldDescription,
+            relationTable: "",
+            relationFieldName: "",
+            relaFieldNameList: [],
+            disableRelaFieldName: false,
+            relationType: "",
+            relationShowField: [],
+            relationShowFiledList: [],
+            disableRelaType: false,
+            isShow: true,
+            isSearch: false,
+            isExport: true,
+            relationTableList: this.relationTableList,
+            tableName: this.tableItemForm.tableName,
+            relationFieldList: [],
+          };
+        });
+      });
+
+    },
+     // 获取所有表格
+    async getAllTable() {
+      let data = {
+        databaseName: this.databaseName,
+        databaseType: this.databaseType,
+      };
+      let res = await getFormName(data);
+
+      const baseTable = await this.getDicts("base_table");
+
+      this.tableList = res.data.filter((item) => {
+        return !baseTable.data.some(
+          (value) =>
+            value.dictValue.toLowerCase() == item.tableName.toLowerCase()
         );
-        this.tableList = [...tempSelection, ...response.rows];
-        this.total = response.total;
-        this.loading = false;
-        if (tempSelection.length) {
-          this.$nextTick(() => {
-            tempSelection.forEach((item) => {
-              this.$refs.tableRef.toggleRowSelection(item);
-            });
-          });
-        }
       });
     },
+    // 确认添加一个表格
+    confirmAddHandler() {
+      console.log(this.tableItemForm);
+      if(this.tableItemForm.title == ''){
+        this.$message.error("字段不能为空");
+        return
+      }
+      if(this.relateTitle){
+        this.tableItemForm.rowId = Date.now();
+        this.tableDataList.push(this.tableItemForm);
+      } else {
+        this.tableDataList.forEach((item, index) => {
+          if(item.rowId == this.tableItemForm){
+            this.tableDataList[index] = this.tableItemForm
+          }
+        })
+      }
+      
+      this.isShowForm = false;
+      this.tableItemForm = {}
+    },
+    // 修改一个表格数据
+    relateOne(row){
+      console.log(row);
+      this.relateTitle = false
+      this.isShowForm = true;
+      this.tableItemForm = row
+    },
+    // 新增动态表格组
+    addTableGroup(){
+        let tableKey = this.tableDataList[0].tableName
+        this.tableGroupList.push({
+          rowId: Date.now(),
+          tableDataList: this.tableDataList,
+          contentList: this.tableDataList.splice(1),
+          groupname: this.groupname,
+          groupdescribe: this.groupdescribe,
+          groupcount: this.tableDataList.length,
+          tableKey: this.tableDataList[0].tableName
+        })
+      
+      this.isShowTable = false
+      this.tableDataList = []
+      this.groupname = ''
+      this.groupdescribe = ''
+    },
+    /** 新增按钮操作 */
+    handleAdd() {
+      // this.$router.push({
+      //   path: "/system/fromModel/index/relateMange",
+      // });
+      this.groupTitle = true
+      this.isShowTable=true
+    },
+    // 修改动态表格组
+    UpdateTableGroup(row){
+      console.log(row);
+      this.updataGroupRow = row
+      console.log(this.tableGroupList);
+      this.groupname = row.groupname
+      this.groupdescribe = row.groupdescribe
+      this.tableDataList = row.tableDataList
+      this.groupTitle = false
+      this.isShowTable = true 
+    },
     // 取消按钮
     cancel() {
       this.open = false;
@@ -421,10 +597,7 @@ export default {
       this.single = selection.length !== 1;
       this.multiple = !selection.length;
     },
-    /** 新增按钮操作 */
-    handleAdd() {
-      this.isShowTable = true;
-    },
+    
     /** 修改按钮操作 */
     async handleUpdate(row) {
       // 兼容勾选单个的修改
@@ -483,24 +656,6 @@ export default {
           } else {
             return Promise.reject();
           }
-
-          // let promiseArr = [];
-          // for (let i = 0; i < menuIdList.length; i++) {
-          //   console.log(menuIdList[i]);
-          //   promiseArr.push(
-          //     new Promise((resolve, reject) => {
-          //       delMenu(menuIdList[i]).then(
-          //         (val) => {
-          //           resolve(val);
-          //         },
-          //         (res) => {
-          //           reject(res);
-          //         }
-          //       );
-          //     })
-          //   );
-          // }
-          // let result = await Promise.all(promiseArr);
         })
         .then(() => {
           this.getList();
@@ -527,27 +682,23 @@ export default {
     },
     // 新增一个联动表格
     addOneTable() {
+      this.relateTitle = true
+      this.getAllTable()
       // 注意校验最后一条数据是否合法
-
       this.isShowForm = true;
     },
-    // 确认添加一个表格
-    confirmAddHandler() {
-      this.tableDataList.push(this.tableItemForm);
-      this.tableItemFormReset();
-      this.isShowForm = false;
-    },
+
     // 重置表单
-    tableItemFormReset() {
-      Object.assign(this.tableItemForm, {
-        title: "",
-        tableId: "",
-        tableName: "",
-        showFields: [],
-        theRelateField: "",
-        executeOptions: [],
-      });
-    },
+    // tableItemFormReset() {
+    //   Object.assign(this.tableItemForm, {
+    //     title: "",
+    //     tableId: "",
+    //     tableName: "",
+    //     showFields: [],
+    //     theRelateField: "",
+    //     executeOptions: [],
+    //   });
+    // },
     handlePreview() {
       this.$router.push({
         path: "/system/fromModel/index/relateTableEdit",
@@ -557,6 +708,26 @@ export default {
 };
 </script>
 <style scoped lang="scss">
+.ipt {
+  height: 36px;
+  line-height: 36px;
+  font-size: 14px;
+  width: 100%;
+  outline: none;
+  text-align: center;
+  background-color: #fff;
+  border: 1px solid #dcdfe6;
+  color: #606266;
+  display: inline-block;
+  border-radius: 4px;
+}
+.isNullDesc {
+  border-color: #ff4949 !important;
+}
+
+.ipt:focus {
+  border-color: #1890ff;
+}
 .formWrap {
   display: flex;
   justify-content: center;

+ 1685 - 0
ruoyi-ui/src/views/relateTable/relateMange.vue

@@ -0,0 +1,1685 @@
+<template>
+  <div class="app-container">
+    <el-row :gutter="20">
+      <el-col :span="18" :class="{ edit: menudata }">
+        <el-card shadow="always" :body-style="{ padding: '20px' }">
+          <template #header>
+            <div>
+              <span>字段编辑</span>
+            </div>
+          </template>
+          <!-- <Queryfrom
+            :form-vals="checkedWhere"
+            @getList="getList"
+            ref="mychild"
+          /> -->
+          <el-select
+            v-model="tableName"
+            placeholder="请选择数据表"
+            filterable
+            @change="getList"
+            class="mb10"
+          >
+            <el-option
+              v-for="item in tableList"
+              :key="item.tableName"
+              :label="item.tableComment"
+              :value="item.tableName"
+            >
+              <span style="float: left">{{ item.tableComment }}</span>
+              <span style="float: right; color: #8492a6; font-size: 13px">{{
+                item.tableName
+              }}</span>
+            </el-option>
+          </el-select>
+          <el-table
+            :data="tableFieldList"
+            border
+            ref="dragTable"
+            row-key="id"
+            max-height="500px"
+          >
+            
+            <el-table-column
+              type="index"
+              label="序号"
+              width="50"
+              class-name="allowDrag"
+            >
+            </el-table-column>
+            <el-table-column prop="fieldName" label="数据字段">
+            </el-table-column>
+            <el-table-column prop="fieldDescription" label="字段描述">
+              <template slot-scope="scope">
+                <input
+                  :class="{
+                    isNullDesc:
+                      scope.row.fieldDescription == '' &&
+                      scope.row.isShow &&
+                      isInputInvalid
+                        ? true
+                        : false,
+                    ipt: true,
+                  }"
+                  v-model="scope.row.fieldDescription"
+                />
+              </template>
+            </el-table-column>
+            <el-table-column prop="relationTable" label="关联表">
+              <template slot-scope="scope">
+                <el-select
+                  v-model="scope.row.relationTable"
+                  :disabled="
+                    !scope.row.relationTableList ||
+                    !scope.row.relationTableList.length
+                  "
+                  placeholder="请选择关联的表"
+                  clearable
+                  filterable
+                  @change="ralationTableChange(scope.row)"
+                >
+                  <el-option
+                    v-for="item in scope.row.relationTableList"
+                    :key="item.tableName"
+                    :label="item.tableComment"
+                    :value="item.tableName"
+                  >
+                    <span style="float: left">{{ item.tableComment }}</span>
+                    <span
+                      style="float: right; color: #8492a6; font-size: 13px"
+                      >{{ item.tableName }}</span
+                    >
+                  </el-option>
+                </el-select>
+              </template>
+            </el-table-column>
+            <el-table-column prop="relationFieldName" label="关联条件字段">
+              <template slot-scope="scope">
+                <el-select
+                  v-model="scope.row.relationFieldName"
+                  @change="relationFieldChange(scope.row)"
+                  :disabled="!scope.row.disableRelaFieldName"
+                  placeholder="关联字段"
+                  filterable
+                >
+                  <el-option
+                    v-for="item in scope.row.relaFieldNameList"
+                    :key="item.fieldName"
+                    :label="item.fieldDescription"
+                    :value="item.fieldName"
+                  >
+                  </el-option>
+                </el-select>
+              </template>
+            </el-table-column>
+            <el-table-column prop="isShow" label="是否显示">
+              <template slot-scope="scope">
+                <el-switch v-model="scope.row.isShow"> </el-switch>
+              </template>
+            </el-table-column>
+          </el-table>
+        </el-card>
+      </el-col>
+      <el-col :span="6" :class="{ menudata: menudata }">
+        <el-tabs v-model="activeName" @tab-click="tabhandleClick">
+          <el-tab-pane label="菜单编辑" name="menuedit">
+            <el-card shadow="always" :body-style="{ padding: '10px' }">
+              <!-- <template #header>
+                <div>
+                  <span>菜单编辑</span>
+                </div>
+              </template> -->
+              <el-form
+                ref="formData"
+                :model="formData"
+                label-width="100px"
+                :rules="rules"
+              >
+                <el-form-item label="菜单名称" prop="menuName">
+                  <el-input v-model="formData.menuName"></el-input>
+                </el-form-item>
+                <el-form-item label="菜单路由" prop="routePath">
+                  <!-- <el-select v-model="formData.routePath" placeholder="请选择路由">
+                    <el-option label="区域一" value="shanghai"></el-option>
+                    <el-option label="区域二" value="beijing"></el-option>
+                  </el-select> -->
+                  <treeselect
+                    :append-to-body="true"
+                    v-model="formData.routePath"
+                    :options="menus"
+                    :normalizer="normalizer"
+                    @change="treeSelectChange"
+                    :show-count="true"
+                    placeholder="请选择父级路由"
+                  />
+                </el-form-item>
+                <el-form-item label="是否显示列表" v-if="false">
+                  <el-switch v-model="formData.isShowList"></el-switch>
+                </el-form-item>
+                <el-form-item label="时间格式" prop="timeFormate">
+                  <el-select
+                    v-model="formData.timeFormate"
+                    placeholder="请选择时间格式"
+                  >
+                    <el-option
+                      v-for="val in dict.type.sys_time_format"
+                      :key="val.value"
+                      :label="val.label"
+                      :value="val.value"
+                    ></el-option>
+                  </el-select>
+                </el-form-item>
+                <el-form-item label="表格主键" prop="primaryKey">
+                  <el-select
+                    v-model="formData.primaryKey"
+                    placeholder="请选择表格主键"
+                  >
+                    <el-option
+                      v-for="val in primaryKeyList"
+                      :key="val.fieldName"
+                      :label="val.fieldDescription"
+                      :value="val.fieldName"
+                    ></el-option>
+                  </el-select>
+                </el-form-item>
+                <el-form-item label="排序依赖字段">
+                  <el-select
+                    v-model="formData.orderByColumn"
+                    placeholder="请选择排序依赖"
+                  >
+                    <el-option
+                      v-for="val in orderByFieldList"
+                      :key="val.fieldName"
+                      :label="val.fieldDescription"
+                      :value="val.tableName + '.' + val.fieldName"
+                    ></el-option>
+                  </el-select>
+                </el-form-item>
+                <el-form-item label="排序方式" v-show="formData.orderByColumn">
+                  <el-radio v-model="formData.isAsc" :label="false"
+                    >升序</el-radio
+                  >
+                  <el-radio v-model="formData.isAsc" :label="true"
+                    >降序</el-radio
+                  >
+                </el-form-item>
+                <el-form-item>
+                  <el-button size="mini" @click="previewHandle">预览</el-button>
+                  <el-button size="mini" type="primary" @click="createHandle">{{
+                    tId ? "确认修改" : "确认创建"
+                  }}</el-button>
+                </el-form-item>
+              </el-form>
+            </el-card>
+          </el-tab-pane>
+        </el-tabs>
+      </el-col>
+    </el-row>
+
+    <el-dialog title="效果预览" :visible.sync="isShowPreview" width="50%">
+      <div class="cardBox">
+        <el-card
+          shadow="hover"
+          :body-style="{ padding: '20px' }"
+          class="card"
+          v-for="(item, index) in deepragTableStatisticList"
+          :key="index"
+        >
+          <el-tooltip
+            class="item"
+            effect="dark"
+            :content="item.statisticTitle"
+            placement="top-start"
+          >
+            <div class="title">{{ item.statisticTitle ? item.statisticTitle : item.statisticDescription}}</div>
+          </el-tooltip>
+
+          <!-- <el-tooltip
+            class="item"
+            effect="dark"
+            :content="item.statisticDescription"
+            placement="top-start"
+          >
+            <div class="description">{{ item.statisticDescription }}</div>
+          </el-tooltip> -->
+
+          <div class="type">
+            <!-- <div class="statisticType">{{ item.statisticType }}</div> -->
+            <div class="count">统计结果</div>
+          </div>
+        </el-card>
+      </div>
+
+      <el-row :gutter="10" class="mb8">
+        <el-col :span="18">
+          <el-input placeholder="请输入" clearable />
+        </el-col>
+
+        <el-col :span="6" class="previewbtn">
+          <el-button
+            type="primary"
+            icon="el-icon-search"
+            size="small"
+            @click="() => {}"
+            >搜索</el-button
+          >
+          <el-button icon="el-icon-refresh" size="small" @click="() => {}"
+            >重置</el-button
+          >
+        </el-col>
+      </el-row>
+
+      <el-row :gutter="10" class="mb8">
+        <el-col :span="1.5">
+          <el-button
+            type="primary"
+            plain
+            icon="el-icon-plus"
+            size="mini"
+            @click="() => {}"
+            >新增
+          </el-button>
+        </el-col>
+        <el-col :span="1.5">
+          <el-button
+            type="success"
+            plain
+            icon="el-icon-edit"
+            size="mini"
+            :disabled="false"
+            @click="() => {}"
+            >修改
+          </el-button>
+        </el-col>
+        <el-col :span="1.5">
+          <el-button
+            type="danger"
+            plain
+            icon="el-icon-delete"
+            size="mini"
+            :disabled="false"
+            @click="() => {}"
+            >删除
+          </el-button>
+        </el-col>
+        <el-col :span="1.5">
+          <el-button plain icon="el-icon-upload2" size="mini" @click="() => {}"
+            >导入
+          </el-button>
+        </el-col>
+        <el-col :span="1.5">
+          <el-button
+            type="warning"
+            plain
+            icon="el-icon-download"
+            size="mini"
+            @click="() => {}"
+            >导出
+          </el-button>
+        </el-col>
+        <!-- <right-toolbar
+          showSearch.sync="true"
+          @queryTable="() => {}"
+        ></right-toolbar> -->
+      </el-row>
+      <el-table :data="tableDataList" @selection-change="() => {}">
+        <el-table-column
+          type="selection"
+          width="55"
+          align="center"
+        ></el-table-column>
+        <!-- <span v-for="(key, val) in columns" :key="key">
+          <el-table-column :label="key" align="center" :prop="val" />
+        </span> -->
+        <el-table-column
+          v-for="item in columns"
+          :key="item.key + item.value"
+          :label="item.value"
+          align="center"
+          :prop="toUpperCase(item.key)"
+        />
+        <el-table-column
+          label="操作"
+          align="center"
+          class-name="small-padding fixed-width"
+        >
+          <!-- <template slot-scope="scope"> -->
+          <template>
+            <!-- <el-button
+              size="mini"
+              type="text"
+              icon="el-icon-edit"
+              @click="() => {}"
+              >修改
+            </el-button>
+            <el-button
+              size="mini"
+              type="text"
+              icon="el-icon-delete"
+              @click="() => {}"
+              >删除
+            </el-button> -->
+            <el-dropdown>
+              <el-button type="warning" plain size="small">
+                处理<i class="el-icon-arrow-down el-icon--right"></i>
+              </el-button>
+              <el-dropdown-menu slot="dropdown">
+                <el-dropdown-item
+                  ><el-button
+                    size="mini"
+                    type="text"
+                    icon="el-icon-edit"
+                    @click="() => {}"
+                    >修改</el-button
+                  ></el-dropdown-item
+                >
+                <el-dropdown-item
+                  ><el-button
+                    size="mini"
+                    type="text"
+                    icon="el-icon-delete"
+                    @click="() => {}"
+                    >删除</el-button
+                  >
+                </el-dropdown-item>
+              </el-dropdown-menu>
+            </el-dropdown>
+          </template>
+        </el-table-column>
+      </el-table>
+      <pagination
+        v-show="total > 0"
+        :total="total"
+        :page.sync="queryParams.pageNum"
+        :limit.sync="queryParams.pageSize"
+        @pagination="pageList"
+      />
+      <template #footer>
+        <span>
+          <el-button @click="isShowPreview = false">关闭</el-button>
+          <el-button type="primary" @click="createHandle">{{
+            tId ? "确认修改" : "确认创建"
+          }}</el-button>
+        </span>
+      </template>
+    </el-dialog>
+
+    <!-- 添加数据统计对话框 -->
+    <el-dialog
+      :title="staictitle"
+      :visible.sync="isShowAddData"
+      width="30%">
+      
+      <el-form 
+      label-width="100px" 
+      :model="dataCountFormData">
+        <el-form-item label="统计标题" prop="statisticTitle">
+          <el-input v-model="dataCountFormData.statisticTitle"></el-input>
+        </el-form-item>
+
+        <el-form-item label="统计数据">
+          <el-select
+            v-model="dataCountFormData.statisticField"
+            placeholder="请选择统计字段"
+          >
+            <el-option
+              v-for="item in dataArr"
+              :key="item.id"
+              :label="item.fieldName"
+              :value="item.tableName + '.'  + item.fieldName"
+            >
+            <span style="float: left;margin-right: 5px">{{ item.tableName }}  </span>
+            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.fieldName }}</span>
+            </el-option>
+          </el-select>
+        </el-form-item>
+        <!-- <el-form-item label="类型">
+          <el-select v-model="dataCountFormData.type" placeholder="请选择类型">
+            <el-option label="数量" value="num"></el-option>
+            <el-option label="状态" value="status"></el-option> -->
+        <el-form-item label="统计类型">
+          <el-select 
+          v-model="dataCountFormData.statisticType" 
+          placeholder="请选择统计类型">
+            <el-option v-for="item in dataType" :key="item.dictCode" :label="item.dictLabel" :value="item.dictValue"></el-option>
+            <!-- <el-option label="状态" value="status"></el-option> -->
+          </el-select>
+        </el-form-item>
+
+        <el-form-item label="统计描述" prop="statisticDescription">
+          <el-input v-model="dataCountFormData.statisticDescription"></el-input>
+        </el-form-item>
+        <el-form-item label="统计对象" prop="statisticObject">
+          <el-input v-model="dataCountFormData.statisticObject"></el-input>
+        </el-form-item>
+      </el-form>
+      <span slot="footer" class="dialog-footer">
+        <el-button @click="closeAddDialog">取 消</el-button>
+        <el-button v-if="staictitle == '修改统计数据字段'" type="primary" @click="upadtaData">确 定</el-button>
+
+        <el-button v-else type="primary" @click="addData">确 定</el-button>
+      </span>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import {
+  delTableData,
+  dragTableInfo,
+  listTable,
+  unionListTableData,
+  getInfoBySqlKey,
+  addTableData,
+  addStatistic,
+  updateStatistic
+} from "@/api/tablelist/commonTable";
+import { getDicts } from "@/api/system/dict/data";
+import {
+  getFormName,
+  getListName,
+  dragTablePreview,
+} from "@/api/dragform/form.js";
+import { getTableInfo, editTable } from "@/api/system/table.js";
+import { addDragTable } from "@/api/tablelist/commonTable.js";
+import { getParticMenu, updateMenu } from "@/api/system/menu.js";
+import { getMenuList, addMenu } from "@/api/menu.js";
+import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
+import { mapState } from "vuex";
+import Sortable from "sortablejs";
+import Treeselect from "@riophae/vue-treeselect";
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
+import { v4 as uuidv4 } from "uuid";
+export default {
+  name: "tableMange",
+  dicts: ["sys_time_format", "table_statistic_type"],
+  props: [],
+  components: { Queryfrom, Treeselect },
+  data() {
+    return {
+      staictitle: '添加统计数据字段',
+      isInputInvalid: false,
+      // 修改表格时的menuId
+      menuId: "",
+      // 修改表格的id
+      tId: "",
+      // 当前模板信息
+      templateInfo: {},
+      // 排序方式 默认降序
+      sortState: true,
+      // 列信息
+      columns: {},
+      // 查询条件
+      queryFromWhere: {},
+      // 当前table唯一标识
+      sqlKey: "",
+      // 动态数据sqlkey
+      staticSqlKey: '',
+      // 表格的高度
+      tableKey: "",
+      // tableHeight: document.documentElement.scrollHeight - 245 + "px",
+      tableList: [], //所有表格列表
+      tableFieldList: [], // 当前表格字段数据
+      tableName: "", // 当前表名称
+
+      relationTableList: [], //关联表格列表
+      relationFieldList: [], //关联字段列表
+      relationTypeList: [], //关联方式列表
+      total: 0, //表格数据总数
+      relaTypeList: [
+        {
+          label: "等值连接",
+          value: "INNER JOIN",
+        },
+        {
+          label: "左连接",
+          value: "LEFT JOIN",
+        },
+        {
+          label: "右连接",
+          value: "RIGHT JOIN",
+        },
+      ],
+      headerList: [
+        {
+          prop: "fieldName",
+          label: "数据字段",
+        },
+        {
+          prop: "fieldDescription",
+          label: "字段描述",
+        },
+        {
+          prop: "relationTable",
+          label: "关联表",
+        },
+        {
+          prop: "relationFieldName",
+          label: "关联字段",
+        },
+        {
+          prop: "relationType",
+          label: "关联方式",
+        },
+        {
+          prop: "isShow",
+          label: "是否显示",
+        },
+        {
+          prop: "isSearch",
+          label: "是否包含查询",
+        },
+        {
+          prop: "isExport",
+          label: "是否导出",
+        },
+        {
+          prop: "isCount",
+          label: "是否统计",
+        },
+      ], //表头列表
+
+      // 右侧筛选条件勾选数据
+      // checkedList: [], //勾选的查询框
+      // checkedWhere:[],//需要渲染的查询表单
+
+      // 右侧表单编辑
+      formData: {
+        menuName: "",
+        routePath: undefined,
+        isShowList: true,
+        timeFormate: "",
+        orderByColumn: "",
+        isAsc: false,
+        primaryKey: "",
+      },
+      rules: {
+        menuName: [
+          { required: true, message: "请输入菜单名称", trigger: "blur" },
+        ],
+        routePath: [
+          { required: true, message: "请选择路由", trigger: "change" },
+        ],
+        timeFormate: [
+          { required: true, message: "请选择时间格式", trigger: "change" },
+        ],
+        primaryKey: [
+          { required: true, message: "请选择表格主键", trigger: "blur" },
+        ],
+        fieldDescription: [
+          { required: true, message: "请输入字段描述", trigger: "blur" },
+        ],
+      },
+      menus: [], //路由列表数据
+
+      // 预览弹窗相关
+      isShowPreview: false, //弹窗显示与隐藏
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        orderByColumn: "",
+        isAsc: false,
+        basicMap: {
+          sql: "",
+        },
+      },
+      loading: false, //表格加载
+      tableDataList: [], //数据
+      editData: {},
+      menuOrderNum: 0,
+      // tab动态切换
+      activeName: "menuedit",
+      // 数据统计对象
+      dataCountFormData: {},
+      // 添加数据统计表格
+      dragTableStatisticList: [],
+      deepragTableStatisticList:[],
+      tableSqlList: [],
+      searchFieldList: [],
+      // 是否切换到数据统计
+      menudata: false,
+      // 显示添加字段对话框
+      isShowAddData: false,
+      dataType : [],
+      uuid: '',
+    };
+  },
+  computed: {
+    // 数据字段
+    dataArr() {
+      return this.tableFieldList.filter((item) => item.isShow);
+    },
+    ...mapState({
+      databaseName: (state) => state.user.dataSource.databaseName,
+      databaseType: (state) => state.user.dataSource.databaseType,
+      username: (state) => state.user.dataSource.username,
+    }),
+    searchArr() {
+      if (!this.templateInfo?.where?.length) return [];
+      return this.templateInfo.where.map((item) => item.conditionName);
+    },
+    checkedWhere() {
+      if (!this.templateInfo?.where?.length) return [];
+      return this.templateInfo?.where.filter((item) => {
+        return this.checkedList.includes(item.conditionName);
+      });
+    },
+    orderByFieldList() {
+      // return this.tableFieldList.filter((item) => item.isShow);
+      return this.tableFieldList;
+    },
+    primaryKeyList() {
+      return this.tableFieldList.filter((item) => !item.isChildren);
+    },
+    // menuOrderNum() {
+    //   if (!this.formData.routePath) return 0;
+    //   let targetMenu = this.getTargetMenu(this.menus);
+    //   console.log(targetMenu);
+    //   if (targetMenu.children?.length) {
+    //     return targetMenu.children.length;
+    //   } else {
+    //     return 0;
+    //   }
+    // },
+  },
+  watch: {
+    tableName: function (val) {
+      if (val) {
+        this.relationTableList = this.tableList
+          .filter((item) => item.tableName != val)
+          .map((item) => {
+            return {
+              tableName: item.tableName,
+              tableComment: item.tableComment,
+            };
+          });
+      } else {
+        this.relationTableList = [];
+      }
+    },
+    "formData.routePath"(nval, oval) {
+      let targetMenu = this.getTargetMenu(this.menus);
+      this.menuOrderNum = targetMenu.children ? targetMenu.children.length : 0;
+    },
+  },
+  methods: {
+    // 字段描述验证规则
+    // blurval(value){
+    //   this.isInputInvalid = value == '' ?  true : false;
+    // },
+    // 树形控件change回调
+    treeSelectChange(val) {
+      //没有change事件
+      console.log("val", val);
+    },
+    // 获取目标menu
+    getTargetMenu(menus) {
+      for (let i = 0; i < menus.length; i++) {
+        if (menus[i].menuId == this.formData.routePath) {
+          return menus[i];
+        } else if (menus.children?.length) {
+          return this.getTargetMenu(menus.children);
+        }
+      }
+      return false;
+    },
+
+    /** 查询列表 */
+    getList(queryParams) {
+      if (!this.tableName) return;
+      let data = {
+        databaseName: this.databaseName,
+        databaseType: this.databaseType,
+        tableName: this.tableName,
+      };
+      console.log(data);
+      // 获取当前表单结构信息
+      getListName(data).then((res) => {
+        // console.log(res);
+        this.tableFieldList = res.map((item, index) => {
+          return {
+            id: this.tableName + "_" + item.fieldName,
+            fieldName: item.fieldName,
+            fieldDescription: item.fieldDescription,
+            relationTable: "",
+            relationFieldName: "",
+            relaFieldNameList: [],
+            disableRelaFieldName: false,
+            relationType: "",
+            relationShowField: [],
+            relationShowFiledList: [],
+            disableRelaType: false,
+            isShow: true,
+            isSearch: false,
+            isExport: true,
+            relationTableList: this.relationTableList,
+            tableName: this.tableName,
+            relationFieldList: [],
+          };
+        });
+        // console.log(this.tableFieldList);
+      });
+    },
+    // 关联表变化回调
+    async ralationTableChange(row) {
+      this.tableFieldList = this.tableFieldList.filter((item) => {
+        return !row.relationFieldList.some((val) => {
+          return val.id == item.id;
+        });
+      });
+      row.relationFieldName = "";
+      row.relationType = "";
+      row.disableRelaFieldName = false;
+      row.disableRelaType = false;
+      row.relationFieldList = [];
+      if (!row.relationTable) {
+        return;
+      }
+      // 获取关联表的字段
+      let data = {
+        databaseName: this.databaseName,
+        databaseType: this.databaseType,
+        tableName: row.relationTable,
+      };
+      let res = await getListName(data);
+      // 关联字段下拉列表数据
+      row.relaFieldNameList = res.map((item) => {
+        return {
+          fieldName: item.fieldName,
+          fieldDescription: item.fieldDescription,
+        };
+      });
+      let relationTableList = row.relationTableList.filter(
+        (item) => row.relationTable != item.tableName
+      );
+      row.relationFieldList = row.relaFieldNameList.map((item, index) => {
+        return {
+          id: row.relationTable + "_" + item.fieldName,
+          fieldName: item.fieldName,
+          fieldDescription: item.fieldDescription,
+          relationTable: "",
+          relationFieldName: "",
+          relaFieldNameList: [],
+          disableRelaFieldName: false,
+          relationType: "",
+          relationShowField: [],
+          relationShowFiledList: [],
+          disableRelaType: false,
+          isShow: true,
+          isSearch: false,
+          isExport: true,
+          relationTableList,
+          tableName: row.relationTable,
+          relationFieldList: [],
+          isChildren: true,
+        };
+      });
+      // this.tableFieldList = [...this.tableFieldList, ...row.relationFieldList];
+      row.disableRelaFieldName = true;
+    },
+    // 关联类型变化回调
+    relationTypeChangeHandler(row) {
+      let tempRelationFieldList = row.relationFieldList.filter((item) => {
+        return !this.tableFieldList.find((val) => val.id === item.id);
+      });
+      this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
+    },
+    // 关联字段回调
+    relationFieldChange(row) {
+      if (!row.relationFieldName) {
+        row.relationType = "";
+        row.disableRelaType = false;
+        row.relaFieldNameList = [];
+        return;
+      }
+      row.disableRelaType = true;
+    },
+
+    // 勾选框回调
+    handleSelectionChange(selection) {
+      this.ids = selection.map((item) => item.id);
+      // this.single = selection.length != 1;
+      this.multiple = !selection.length;
+    },
+    // 分页查询
+    pageList(row) {
+      this.$refs.mychild.pageList(
+        row == undefined
+          ? {
+              limit: this.queryParams.pageSize,
+              page: this.queryParams.pageNum,
+            }
+          : row
+      );
+    },
+    // 多选框改变回调
+    checkedChangeHandle(val) {},
+    // 获取所有表格
+    async getAllTable() {
+      let data = {
+        databaseName: this.databaseName,
+        databaseType: this.databaseType,
+      };
+      let res = await getFormName(data);
+
+      const baseTable = await this.getDicts("base_table");
+
+      this.tableList = res.data.filter((item) => {
+        return !baseTable.data.some(
+          (value) =>
+            value.dictValue.toLowerCase() == item.tableName.toLowerCase()
+        );
+      });
+    },
+    //处理表格行拖拽
+    initDragTable() {
+      const el = this.$refs.dragTable.$el.querySelectorAll(
+        ".el-table__body-wrapper > table > tbody"
+      )[0];
+      const sortable = Sortable.create(el, {
+        handle: ".allowDrag",
+        onEnd: (evt) => {
+          const targetRow = this.tableFieldList.splice(evt.oldIndex, 1)[0];
+          this.tableFieldList.splice(evt.newIndex, 0, targetRow);
+          for (let index in this.tableFieldList) {
+            this.tableFieldList[index].sort = parseInt(index) + 1;
+          }
+        },
+      });
+    },
+    /** 转换菜单数据结构 */
+    normalizer(node) {
+      if (node.children && !node.children.length) {
+        delete node.children;
+      }
+      return {
+        id: node.menuId,
+        label: node.menuName,
+        children: node.children,
+      };
+    },
+    // 获取路由表单数据
+    async getMenuList() {
+      let res = await getMenuList();
+      this.menus = this.handleTree(res.data, "menuId");
+    },
+    // 校验字段合法性(递归版)
+    validateField(tableFieldList, validateParams) {
+      if (!tableFieldList.length) {
+        return;
+      }
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (!temp.fieldDescription?.trim() && temp.isShow) {
+          //描述字段不能为空
+          validateParams.isFieldDescrib = true;
+        }
+        if (
+          temp.relationTable &&
+          (!temp.relationFieldName || !temp.relationType)
+        ) {
+          // 关联条件不足
+          validateParams.isRelationFieldAll = true;
+        }
+        if (temp.relationFieldList.length) {
+          this.validateField(temp.relationFieldList, validateParams);
+        }
+      }
+    },
+    // 校验字段合法性(非递归版)
+    validateTableData(tableFieldList) {
+      if (!tableFieldList.length) {
+        return {
+          val: false,
+          meg: "字段个数不能为空",
+        };
+      }
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (!temp.fieldDescription?.trim() && temp.isShow) {
+          return {
+            val: false,
+            msg: "显示的字段,字段描述不能为空",
+          };
+        }
+        if (
+          temp.relationTable &&
+          (!temp.relationFieldName || !temp.relationType)
+        ) {
+          return {
+            val: false,
+            msg: "关联条件不足,请完善关联条件",
+          };
+        }
+      }
+      if (tableFieldList.filter((item) => item.isShow).length == 0) {
+        return {
+          val: false,
+          msg: "显示的字段数不能为空",
+        };
+      }
+      if (
+        tableFieldList.filter((item) => item.isExport && !item.isChildren)
+          .length == 0
+      ) {
+        return {
+          val: false,
+          msg: "导出字段中至少应有一个主表字段",
+        };
+      }
+      // 导出的字段的描述不能重复
+      let describeArr = tableFieldList
+        .filter((item) => item.isExport)
+        .map((item) => item.fieldDescription);
+      let isRepeat = false;
+      describeArr.map((item) => {
+        if (describeArr.indexOf(item) != describeArr.lastIndexOf(item)) {
+          isRepeat = true;
+        }
+      });
+      if (isRepeat) {
+        return {
+          val: false,
+          msg: "导出的字段描述不能重复",
+        };
+      }
+
+      return {
+        val: true,
+        msg: "",
+      };
+    },
+    // 递归拼接查询语句
+    getSQLString(tableFieldList, fieldArr, tableArr, sqlType = "mysql") {
+      let prefix = "{DBNAME}.";
+      let asOrSpace = sqlType == "oracle" ? " " : " AS ";
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        if (temp.isShow) {
+          let tempArr = prefix + temp.tableName + "." + temp.fieldName;
+          if (temp.isChildren) {
+            tempArr += asOrSpace + temp.tableName + "_" + temp.fieldName;
+          }
+          fieldArr.push(tempArr);
+        }
+        if (temp.relationTable && temp.relationFieldName && temp.relationType) {
+          // fieldArr.push(temp.relationTable + "." + temp.relationFieldName);
+          let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
+          tableArr.push(
+            temp.relationType +
+              " " +
+              isNeedUsername +
+              prefix +
+              temp.relationTable +
+              asOrSpace +
+              temp.relationTable +
+              " ON " +
+              prefix +
+              temp.relationTable +
+              "." +
+              temp.relationFieldName +
+              " = " +
+              prefix +
+              temp.tableName +
+              "." +
+              temp.fieldName
+          );
+        }
+        // if (temp.relationFieldList.length) {
+        //   this.getSQLString(temp.relationFieldList, fieldArr, tableArr);
+        // }
+      }
+      // 如果主键不包含显示,则添加至sql语句中
+      let isNotInclude = this.primaryKeyList.find(
+        (val) => !val.isShow && val.fieldName == this.formData.primaryKey
+      );
+      if (isNotInclude) {
+        fieldArr.push(
+          prefix + isNotInclude.tableName + "." + isNotInclude.fieldName
+        );
+      }
+    },
+
+    // 拼接查询sql语句
+    getSQLStr() {
+      let prefix = "{DBNAME}.";
+      let sqlType = this.databaseType; //数据库类型
+      // let sqlType = "oracle";
+      let sql = "";
+      // mysql
+      sql += "SELECT ";
+      let fieldNameArr = [],
+        relaTypeArr = [];
+      this.getSQLString(
+        this.tableFieldList,
+        fieldNameArr,
+        relaTypeArr,
+        sqlType
+      );
+      // if (discriISEmpty) {
+      //   return false;
+      // }
+      let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
+      let asOrSpace = sqlType == "oracle" ? " " : " AS ";
+      sql +=
+        fieldNameArr.join(",") +
+        " FROM " +
+        isNeedUsername +
+        prefix +
+        this.tableName +
+        asOrSpace +
+        this.tableName;
+      if (relaTypeArr.length) {
+        sql += " " + relaTypeArr.join(" ");
+      }
+      return sql;
+    },
+    getStaticSQL(key) {
+      // let prefix = "{DBNAME}.";
+      let sqlType = this.databaseType; //数据库类型
+      // let sqlType = "oracle";
+      let sql = "";
+      // mysql
+      sql += "SELECT ";
+      let fieldNameArr = [],
+        relaTypeArr = [];
+      this.getSQLString(
+        this.tableFieldList,
+        fieldNameArr,
+        relaTypeArr,
+        sqlType
+      );
+      let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
+      let asOrSpace = sqlType == "oracle" ? " " : " AS ";
+
+      sql +=
+        key + 
+        " FROM " +
+        isNeedUsername +
+        // prefix +
+        this.tableName +
+        asOrSpace +
+        this.tableName;
+      if (relaTypeArr.length) {
+        sql += " " + relaTypeArr.join(" ");
+      }
+      return sql;
+    },
+    // 处理列表信息
+    columnsHandler(columns) {
+      let resArr = [];
+      columns.forEach((item) => {
+        for (const key in item) {
+          let tempObj = {};
+          tempObj.key = key;
+          tempObj.value = item[key];
+          resArr.push(tempObj);
+        }
+      });
+      return resArr;
+    },
+    // 下划线命名转驼峰命名
+    toUpperCase(str) {
+      let nstr = str.replace(/(?:_)+([^_])/g, function ($0, $1) {
+        return $1.toUpperCase();
+      });
+      nstr = nstr.replace(nstr[0], nstr[0].toLowerCase());
+      return nstr;
+    },
+
+    // 递归获取列表信息
+    getCol(
+      tableFieldList,
+      columns,
+      searchFieldList = [],
+      tableExportField = {}
+    ) {
+      if (!tableFieldList.length) return;
+      for (let i = 0; i < tableFieldList.length; i++) {
+        let temp = tableFieldList[i];
+        let tempFieldName = "",
+          exportFieldName = "";
+        if (temp.isChildren) {
+          tempFieldName = temp.tableName + "_" + temp.fieldName;
+          exportFieldName = temp.tableName + "@" + temp.fieldName;
+        } else {
+          tempFieldName = temp.fieldName;
+          exportFieldName = temp.fieldName;
+        }
+        if (temp.isShow) {
+          let tempObj = {};
+          // if (temp.isChildren) {
+          //   tempObj[temp.tableName + "_" + temp.fieldName] =
+          //     temp.fieldDescription;
+          // } else {
+          //   tempObj[temp.fieldName] = temp.fieldDescription;
+          // }
+          tempObj[tempFieldName] = temp.fieldDescription;
+          columns.push(tempObj);
+        }
+        if (temp.isSearch) {
+          searchFieldList.push(temp.tableName + "." + temp.fieldName);
+        }
+
+        if (temp.isExport) {
+          tableExportField[exportFieldName] = temp.fieldDescription;
+        }
+        // 递归
+        // if (temp.relationFieldList) {
+        //   this.getCol(
+        //     temp.relationFieldList,
+        //     columns,
+        //     searchFieldList,
+        //     tableExportField
+        //   );
+        // }
+      }
+    },
+    // 更新路由
+    reloadRouter() {
+      this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
+        this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
+      });
+    },
+
+    // 预览结果回调
+    async previewHandle() {
+      this.$refs.formData.validate(async (valid) => {
+        // 至少包含一个查询项
+        if (valid) {
+          if (!this.tableName) {
+            this.$message.error("请选择数据表");
+            return;
+          }
+          // 检验表单合法性
+          let validRes = this.validateTableData(this.tableFieldList);
+          if (!validRes.val) {
+            this.$message.error(validRes.msg);
+            return;
+          }
+          // let validateParams = {
+          //   isFieldDescrib: false,
+          //   isRelationFieldAll: false,
+          // };
+          // this.validateField(this.tableFieldList, validateParams);
+          // console.log(validateParams);
+          // if (validateParams.isFieldDescrib) {
+          //   this.$message.error("需要显示的字段描述不能为空");
+          //   return;
+          // }
+          // if (validateParams.isRelationFieldAll) {
+          //   this.$message.error("请补全关联条件");
+          //   return;
+          // }
+          // 拼接预览的sql查询语句
+          this.queryParams.basicMap.sql = this.getSQLStr();
+          // 获取表头信息
+          let tempColumns = [],
+            searchFieldList = [];
+          this.getCol(this.tableFieldList, tempColumns, searchFieldList);
+          if (!searchFieldList.length) {
+            this.$message.warning("请至少选择一个包含查询字段");
+            return false;
+          }
+          const dataType = await this.getDicts("table_statistic_type")
+          this.deepragTableStatisticList = JSON.parse(JSON.stringify(this.dragTableStatisticList))
+          this.deepragTableStatisticList.forEach(item => {
+            dataType.data.forEach(val => {
+              if(val.dictValue ==  item.statisticType){
+                item.statisticType = val.dictLabel
+              }
+            })
+          })
+          this.columns = this.columnsHandler(tempColumns);
+          this.queryParams.isAsc = this.formData.isAsc;
+          // 发送请求获取预览数据
+          let res = await dragTablePreview(this.queryParams);
+          this.tableDataList = [];
+          res.rows.forEach((item) => {
+            this.tableDataList.push(item.resultMap);
+          });
+          this.total = res.total;
+          this.isShowPreview = true;
+        } else {
+          this.$message.warning("请完善表单");
+          return false;
+        }
+      });
+
+      // this.$refs.tableForm.validate((val) => {
+      //   if (val) {
+
+      //   } else {
+      //     this.$message.warning("请完善表单");
+      //     return false;
+      //   }
+      // });
+    },
+    // 创建回调
+    async createHandle() {
+      // console.log(123);
+      // this.sqlKey = uuidv4();
+      this.isInputInvalid = true
+      this.$refs.formData.validate(async (valid) => {
+        if (valid) {
+          // 检验表单合法性
+          let validRes = this.validateTableData(this.tableFieldList);
+          if (!validRes.val) {
+            this.$message.error(validRes.msg);
+            return;
+          }
+          let columns = [],
+            searchFieldList = [],
+            tableExportField = {};
+          this.getCol(
+            this.tableFieldList,
+            columns,
+            searchFieldList,
+            tableExportField
+          );
+
+          let echoData = {
+            tableName: this.tableName,
+            tableFieldData: this.tableFieldList,
+            formData: this.formData,
+          };
+          if (!searchFieldList.length) {
+            this.$message.warning("请至少选择一个包含查询字段");
+            return false;
+          }
+          // let validateParams = {
+          //   isFieldDescrib: false,
+          //   isRelationFieldAll: false,
+          // };
+          // this.validateField(this.tableFieldList, validateParams);
+          // console.log(validateParams);
+          // if (validateParams.isFieldDescrib) {
+          //   this.$message.error("需要显示的字段描述不能为空");
+          //   return;
+          // }
+          // if (validateParams.isRelationFieldAll) {
+          //   this.$message.error("请补全关联条件");
+          //   return;
+          // }
+          this.uuid = uuidv4();
+          this.tableKey = uuidv4();
+          // 表单
+          let result;
+          if (this.tId) {
+            let payLoad = {
+              menuId: this.menuId,
+              menuName: this.formData.menuName,
+              parentId: this.formData.routePath,
+              component: "tablelist/commonTable/listInfo",
+              icon: "",
+              isCache: "0",
+              isFrame: "1",
+              menuType: "C",
+              orderNum: this.menuOrderNum,
+              status: "0",
+              visible: "0",
+            };
+            result = await updateMenu(payLoad);
+          } else {
+            let sqlKeyObj = {
+              sqlkey: this.uuid,
+            };
+            let payLoad = {
+              component: "tablelist/commonTable/listInfo",
+              icon: "",
+              isCache: "0",
+              isFrame: "1",
+              menuName: this.formData.menuName,
+              menuType: "C",
+              orderNum: this.menuOrderNum,
+              parentId: this.formData.routePath,
+              path: this.uuid,
+              query: JSON.stringify(sqlKeyObj),
+              status: "0",
+              visible: "0",
+            };
+            result = await addMenu(payLoad);
+          }
+
+          if (result.code == 200) {
+            // 更新路由
+            this.reloadRouter();
+
+            // let isAsc = this.formData.isAsc == "ASC" ? 0 : 1;
+            let data = {
+              tId: this.tId,
+              dtName: this.formData.menuName,
+              // menuId: this.formData.routePath,
+              tableKey: this.tableKey, //  暂定
+              dtTableName: this.tableName,
+              primaryKey: this.formData.primaryKey,
+              orderByColumn: this.formData.orderByColumn,
+              sortOrder: this.formData.isAsc,
+              sqlKey: this.uuid,
+              dtColumnName: columns, //列字段标题名称(存储显示字段信息
+              // dtColumnName: JSON.stringify(columns).replace(/"/g, "'"), //列字段标题名称(存储显示字段信息
+              timeFormat: this.formData.timeFormate,
+              searchFieldList: searchFieldList, //搜索字段数组
+              tableSql: this.getSQLStr(), //  暂定
+              tableExportField: tableExportField, //导出字段名及列名
+              echoData: JSON.stringify(echoData),
+            };
+            // this.tableFieldList.forEach((item) => {
+            //   if (item.isShow) {
+            //     let tempObj = {};
+            //     tempObj[item.fieldName] = item.fieldDescription;
+            //     data.dtColumnName.push(tempObj);
+            //     if (item.children.length) {
+            //       item.children.map((child) => {
+            //         let tempObj = {};
+            //         tempObj[child.fieldName] = child.fieldDescription;
+            //         data.dtColumnName.push(tempObj);
+            //       });
+            //     }
+            //   }
+            //   if (item.isSearch) {
+            //     data.searchFieldList.push(item.fieldName);
+            //   }
+            //   if (item.isExport) {
+            //     data.tableExportField[item.fieldName] = item.fieldDescription;
+            //   }
+            // });
+
+            let res;
+            if (this.tId) {
+              data.menuId = this.menuId;
+              data.sqlKey = this.editData.sqlKey;
+              res = await editTable(data);
+            } else {
+              data.menuId = result.data;
+              res = await addDragTable(data);
+            }
+            this.dragTableStatisticList?.forEach(item => {
+              this.staticSqlKey = uuidv4()
+              // console.log(item)
+              let key = item.statisticType + '(' + item.statisticField + ')'+ ' as result'
+              this.tableSqlList.push({
+                tableSql: this.getStaticSQL(key), 
+                sqlKey: this.staticSqlKey, 
+              })
+              this.searchFieldList = searchFieldList
+              item.sqlKey = this.staticSqlKey
+              item.tableKey = this.tableKey
+            })
+
+            if(res.code == 200 && this.dragTableStatisticList.length !== 0){
+              this.countHandle()
+            }
+            // 关闭当前页面
+            if (this.tId) {
+              if (res.code == 200) {
+                this.$message.success("修改成功");
+              } else {
+                this.$message.warning("修改失败");
+              }
+              this.$tab.closePage();
+              this.$router.push({
+                path: "/system/fromModel/index/tablelist",
+              });
+            } else {
+              if (res.code == 200) {
+                this.$message.success("创建成功");
+              } else {
+                this.$message.warning("创建失败");
+              }
+              this.isShowPreview = false;
+            }
+          }
+        } else {
+          this.$message.warning("请完善表单");
+          return false;
+        }
+      });
+    },
+    // 修改表格回显数据
+    async initTableData(tId) {
+      let res = await getTableInfo(tId);
+      if (res.code == 200) {
+        this.dragTableStatisticList = res.data.dragTableStatisticList
+        let echoData = JSON.parse(res.data.echoData);
+        this.tableName = echoData.tableName;
+        this.tableFieldList = echoData.tableFieldData;
+        let {
+          isShowList,
+          timeFormate,
+          orderByColumn,
+          isAsc,
+          primaryKey,
+          menuName,
+        } = echoData.formData;
+        Object.assign(this.formData, {
+          menuName,
+          isShowList,
+          timeFormate,
+          orderByColumn,
+          isAsc,
+          primaryKey,
+        });
+        this.formData.routePath = this.getParentMenuId(
+          res.data.menuId,
+          this.menus,
+          {}
+        );
+
+        if (!this.formData.routePath) {
+          this.$message.warning("该表格菜单路由已经删除,请重新配置");
+        }
+        // this.formData.routePath
+        this.editData = res.data;
+        let val = await getParticMenu(res.data.sqlKey);
+        if (val.code == 200) {
+          this.menuId = val.data.menuId;
+        }
+      } else {
+        this.$message.error("数据回显失败");
+      }
+    },
+    // 获取父级menuId
+    getParentMenuId(menuId, menus) {
+      let res;
+      for (let i = 0; i < menus.length; i++) {
+        let item = menus[i];
+        if (item.menuId == menuId) {
+          res = item.parentId;
+          break;
+        } else if (item.children?.length) {
+          if (
+            this.getParentMenuId(
+              menuId,
+              JSON.parse(JSON.stringify(item.children))
+            )
+          ) {
+            res = this.getParentMenuId(
+              menuId,
+              JSON.parse(JSON.stringify(item.children))
+            );
+          }
+        }
+      }
+      return res;
+    },
+    // tab切换
+    tabhandleClick() {
+      this.menudata = this.activeName === "datacount" ? true : false;
+    },
+    // 添加数据字段对话框
+    async addDataDialog() {
+      this.staictitle = '添加统计数据字段'
+      this.isShowAddData = true;
+      this.dataType = await this.getDicts("table_statistic_type");
+      this.dataType = this.dataType.data;
+      // console.log(this.dataType)
+    },
+    async updataDialog() {
+      
+      // console.log(this.dataType)
+    },
+    // 修改数据字段
+    upadtaData(){
+      this.dragTableStatisticList.forEach((item, index) => {
+        // console.log(this.dataCountFormData);
+        if(item.id !== undefined && item.id == this.dataCountFormData.id){
+          this.dragTableStatisticList[index] = this.dataCountFormData
+        }else if(item.xid == this.dataCountFormData.xid){
+          this.dragTableStatisticList[index] = this.dataCountFormData
+        }
+      })
+      this.isShowAddData = false
+      // console.log(this.dragTableStatisticList)
+      this.dataCountFormData = {}
+    },
+    // 添加数据字段
+    addData(){
+      // console.log(this.dataCountFormData);
+      this.dataCountFormData.xid = Date.now()
+      this.dataCountFormData.tableKey = this.tableKey
+      this.dragTableStatisticList.push(this.dataCountFormData)
+      this.isShowAddData = false
+      this.dataCountFormData = {}
+    },
+    // 关闭添加数据字段
+    closeAddDialog() {
+      this.isShowAddData = false;
+      this.dataCountFormData = {};
+    },
+    // 确定统计
+    countHandle(){
+      addStatistic({
+        dragTableStatisticList: this.dragTableStatisticList,
+        tableSqlList: this.tableSqlList,
+        searchFieldList: this.searchFieldList,
+        dtTableName: this.tableName
+      }).then(res=> {
+        // console.log(res)
+      })
+    },
+    // 修改统计信息
+    async handleUpdateStat(row){
+      // console.log(row);
+      this.dataCountFormData = row
+      this.dataCountFormData.xid = Date.now()
+      this.staictitle = '修改统计数据字段'
+      this.dataType = await this.getDicts("table_statistic_type");
+      this.dataType = this.dataType.data;
+      this.isShowAddData = true
+      // console.log(this.dataCountFormData)
+      // console.log(this.dragTableStatisticList);
+    },
+    // 删除统计信息
+    handleDeleteStat(row){
+      this.dragTableStatisticList.forEach((item, index) => {
+        // console.log(item);
+        if(item.id == row.id){
+          this.dragTableStatisticList.splice(index, 1);
+        }
+      })
+    },
+  },
+  created() {},
+    async mounted() {
+      this.getAllTable();
+      this.initDragTable();
+      await this.getMenuList();
+      if (this.$route.query.tId) {
+        this.tId = this.$route.query.tId;
+        this.initTableData(this.tId);
+      }
+  },
+};
+</script>
+
+<style scoped lang="scss">
+.ipt {
+  height: 36px;
+  line-height: 36px;
+  font-size: 14px;
+  width: 100%;
+  outline: none;
+  text-align: center;
+  background-color: #fff;
+  border: 1px solid #dcdfe6;
+  color: #606266;
+  display: inline-block;
+  border-radius: 4px;
+}
+.isNullDesc {
+  border-color: #ff4949 !important;
+}
+
+.ipt:focus {
+  border-color: #1890ff;
+}
+::v-deep .right_card {
+  min-height: 500px !important;
+}
+::v-deep .vue-treeselect--has-value .vue-treeselect__input {
+  vertical-align: middle !important;
+}
+.menudata {
+  width: 30% !important;
+}
+.edit {
+  width: 70% !important;
+}
+.mb10 {
+  margin-top: 10px;
+}
+.cardBox {
+  display: flex;
+  align-content: space-between;
+  flex-wrap: wrap;
+  align-content: flex-start;
+}
+.card {
+  /* width:15%; */
+  height:150px;
+  flex-basis: 15%;
+  margin-bottom: 10px;
+  margin-right: 15px;
+  min-width: 180px;
+  .title {
+    /* width:20%; */
+    font-size: 18px;
+    margin-bottom: 5px;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+  }
+  .description {
+    width: 70%;
+    font-size: 13px;
+    color: #9699a2;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    display: -webkit-box;
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 3;
+    word-break: break-all;
+    float: left;
+  }
+  .type {
+    float: right;
+    margin-top: 40px;
+    .statisticType{
+      font-size: 18px;
+    }
+  }
+  .count {
+    font-size: 25px;
+  }
+}
+.mb8{
+  ::v-deep .el-col-18{
+    width: 30% !important;
+    min-width: 220px !important;
+  }
+  ::v-deep .previewbtn{
+    min-width: 190px !important;
+  }
+}
+</style>

+ 49 - 37
ruoyi-ui/src/views/tableMange/index.vue

@@ -1555,52 +1555,65 @@ export default {
               tableExportField: tableExportField, //导出字段名及列名
               echoData: JSON.stringify(echoData),
             };
-            // this.tableFieldList.forEach((item) => {
-            //   if (item.isShow) {
-            //     let tempObj = {};
-            //     tempObj[item.fieldName] = item.fieldDescription;
-            //     data.dtColumnName.push(tempObj);
-            //     if (item.children.length) {
-            //       item.children.map((child) => {
-            //         let tempObj = {};
-            //         tempObj[child.fieldName] = child.fieldDescription;
-            //         data.dtColumnName.push(tempObj);
-            //       });
-            //     }
-            //   }
-            //   if (item.isSearch) {
-            //     data.searchFieldList.push(item.fieldName);
-            //   }
-            //   if (item.isExport) {
-            //     data.tableExportField[item.fieldName] = item.fieldDescription;
-            //   }
-            // });
-
-            let res;
-            if (this.tId) {
-              data.menuId = this.menuId;
-              data.sqlKey = this.editData.sqlKey;
-              res = await editTable(data);
-            } else {
-              data.menuId = result.data;
-              res = await addDragTable(data);
-            }
+          
             this.dragTableStatisticList?.forEach(item => {
-              this.staticSqlKey = uuidv4()
-              // console.log(item)
+              if(this.tId == ''){
+                item.tableKey = this.tableKey
+                this.staticSqlKey = uuidv4()
+                item.sqlKey = this.staticSqlKey
+              }
+              if(item.sqlKey){
+                this.staticSqlKey = item.sqlKey
+              } else {
+                this.staticSqlKey = uuidv4()
+                item.sqlKey = this.staticSqlKey
+              }
+              
               let key = item.statisticType + '(' + item.statisticField + ')'+ ' as result'
+              
               this.tableSqlList.push({
                 tableSql: this.getStaticSQL(key), 
                 sqlKey: this.staticSqlKey, 
               })
               this.searchFieldList = searchFieldList
-              item.sqlKey = this.staticSqlKey
-              item.tableKey = this.tableKey
             })
+            let res;
+            let res1;
+            if (this.tId) {
+              data.menuId = this.menuId;
+              data.sqlKey = this.editData.sqlKey;
+              data.tableKey = this.editData.tableKey;
+              res = await editTable(data);
+              this.dragTableStatisticList.forEach(item => {
+                item.tableKey = this.editData.tableKey
+              })
+              res1 = await updateStatistic({
+                  tableKey: this.editData.tableKey,
+                  dragTableStatisticList: this.dragTableStatisticList,
+                  tableSqlList: this.tableSqlList,
+                  searchFieldList: this.searchFieldList,
+                  dtTableName: this.tableName
+              })
 
-            if(res.code == 200 && this.dragTableStatisticList.length !== 0){
-              this.countHandle()
+            } else {
+              data.menuId = result.data;
+              res = await addDragTable(data);
+
+              this.dragTableStatisticList.forEach(item => {
+                item.tableKey = this.tableKey
+              })
+              if(res.code == 200 && this.dragTableStatisticList.length !== 0){
+                // 新增统计数据
+                res1 = addStatistic({
+                  tableKey: this.tableKey,
+                  dragTableStatisticList: this.dragTableStatisticList,
+                  tableSqlList: this.tableSqlList,
+                  searchFieldList: this.searchFieldList,
+                  dtTableName: this.tableName
+                })
+              }
             }
+            
             // 关闭当前页面
             if (this.tId) {
               if (res.code == 200) {
@@ -1764,7 +1777,6 @@ export default {
     // 删除统计信息
     handleDeleteStat(row){
       this.dragTableStatisticList.forEach((item, index) => {
-        // console.log(item);
         if(item.id == row.id){
           this.dragTableStatisticList.splice(index, 1);
         }