Selaa lähdekoodia

同步listInfo代码

lph 1 vuosi sitten
vanhempi
säilyke
18d4e2a3d4
1 muutettua tiedostoa jossa 232 lisäystä ja 187 poistoa
  1. 232 187
      zkqy-ui/src/views/tablelist/commonTable/listInfo.vue

+ 232 - 187
zkqy-ui/src/views/tablelist/commonTable/listInfo.vue

@@ -86,7 +86,7 @@
           icon="el-icon-delete"
           size="mini"
           :disabled="multiple"
-          @click="handleDelete"
+          @click="handleBatchDelete"
           >删除
         </el-button>
       </el-col>
@@ -121,6 +121,7 @@
       :data="tableList"
       @selection-change="handleSelectionChange"
       row-key="id"
+      ref="tableRef"
       :cell-style="cellStyle"
     >
       <el-table-column
@@ -242,6 +243,7 @@
       >
       </iframe> -->
       <k-form-build
+        v-if="jsonData"
         class="formBuild"
         ref="addFromRef"
         :dynamicData="dynamicData"
@@ -260,16 +262,17 @@
     <el-dialog
       title="提示"
       :visible.sync="btnDialogVisible"
-      :before-close="handleClose">
+      :before-close="handleClose"
+    >
       <DialogTemplate
-       ref="dialogRef"
+        ref="dialogRef"
         :groupKey="groupKey"
         :rowobj="rowobj"
         :subCount="subCount"
         :tableCount="tableCount"
         :subTableName="subTableName"
         @addList="addListHandler"
-        >
+      >
       </DialogTemplate>
       <span slot="footer" class="dialog-footer">
         <el-button @click="btnDialogVisible = false">取 消</el-button>
@@ -277,20 +280,21 @@
       </span>
     </el-dialog>
 
-    <!-- 绑定按钮dialog -->
+    <!-- 自定义弹窗 -->
     <el-dialog
       title="提示"
       :visible.sync="btnDialogVisible"
-      :before-close="handleClose">
+      :before-close="handleClose"
+    >
       <DialogTemplate
-       ref="dialogRef"
+        ref="dialogRef"
         :groupKey="groupKey"
         :rowobj="rowobj"
         :subCount="subCount"
         :tableCount="tableCount"
         :subTableName="subTableName"
         @addList="addListHandler"
-        >
+      >
       </DialogTemplate>
       <span slot="footer" class="dialog-footer">
         <el-button @click="btnDialogVisible = false">取 消</el-button>
@@ -328,7 +332,7 @@ export default {
       // 绑定按钮dialog
       btnDialogVisible: false,
       // 绑定修改dialog
-      groupKey: '',
+      groupKey: "",
       // 遮罩层
       loading: true,
       // 选中数组
@@ -418,13 +422,13 @@ export default {
       // 当前点击按钮的数据
       currentBtnData: {},
       // 修改选中行
-      rowobj:{},
+      rowobj: {},
       // 该行的统计信息
-      subCount:[],
-      tableCount:[],
+      subCount: [],
+      tableCount: [],
       // 弹窗新增数据
-      addLists:[],
-      subTableName: '',
+      addLists: [],
+      subTableName: "",
       // 当前点击行的数据
       currentRow: {},
     };
@@ -434,18 +438,9 @@ export default {
     // 得到当前展示的table的唯一标识
     this.tableKey = this.$route.query.tableKey;
   },
-  watch: {
-    tableList: {
-      handler(val) {
-        // console.log(JSON.parse(JSON.stringify(val)), "tableListChange");
-      },
-      deep: true,
-    },
-  },
+  watch: {},
   computed: {
     isShowExcuteCol() {
-      // console.log(!this.excuteBtnArr?.every((arr) => arr.children.length == 0));
-      // return true;
       return !this.excuteBtnArr?.every((arr) => arr.children.length == 0);
     },
   },
@@ -468,7 +463,6 @@ export default {
           });
           // 获取操作列的按钮数据
           this.excuteBtnArr = res.data.resultMap.button;
-          // console.log('res', this.templateInfo)
           this.queryParams.orderByColumn =
             res.data.resultMap.querySql.orderByColumn;
           this.sortOrder = JSON.parse(res.data.resultMap.querySql.sortOrder);
@@ -491,7 +485,6 @@ export default {
           );
           // 根据sql语句查询当前表数据
           unionListTableData(this.queryParams).then(async (res) => {
-            // console.log('unionListTableData');
             this.tableList = [];
             res.rows.forEach((item) => {
               this.tableList.push(item.resultMap);
@@ -510,6 +503,9 @@ export default {
             // });
             this.tableList = await this.setFieldStyleData(tempTableList);
             this.total = res.total;
+            this.$nextTick(() => {
+              this.$refs.tableRef?.clearSelection();
+            });
             this.loading = false;
           });
 
@@ -520,7 +516,6 @@ export default {
               queryCriteriaValue: this.queryParams.queryMap.queryCriteriaValue,
             },
           }).then((res) => {
-            // console.log('getStatisticList', res);
             this.statisticList = res.data;
           });
         });
@@ -601,7 +596,12 @@ export default {
     // 多选框选中数据
     handleSelectionChange(selection) {
       this.ids = selection.map(
-        (item) => item[camelCase(this.templateInfo.template?.primaryKey)]
+        (item) =>
+          item[
+            camelCase(
+              this.tableName + "_" + this.templateInfo.template?.primaryKey
+            )
+          ]
       );
       this.single = selection.length != 1;
       this.multiple = !selection.length;
@@ -626,7 +626,10 @@ export default {
       this.defaultValue = {};
       getInfoBySqlKey(this.templateInfo.template.sqlKey).then(({ data }) => {
         if (!data || !data.dfVueTemplate) {
+          this.jsonData = false;
           this.$message.error("当前表格未绑定表单!");
+          this.title = "运行";
+          this.open = true;
           return;
         }
         if (data.dfFormSql) {
@@ -659,8 +662,8 @@ export default {
       return strs[0];
     },
     // 绑定dialog对话框关闭
-    handleClose(){
-      this.btnDialogVisible = false
+    handleClose() {
+      this.btnDialogVisible = false;
     },
     getLastUppercaseWord(text) {
       const pattern = /\b[A-Z][a-z]*\b/g;
@@ -674,34 +677,30 @@ export default {
     },
     /** 修改按钮操作 */
     async handleUpdate(row, btnData) {
-      // console.log(this.currentBtnData);
-
-      let nameTable = this.templateInfo.template.dtTableName
-      // console.log(nameTable);
-      // console.log('row', row);
-      this.rowobj = {}
-      let obj = {}
-      for(let key in row) {
-
-        let modifiedTable = key.replace(/[A-Z]/g, (match) => `_${match}`).toLowerCase();
+      let nameTable = this.templateInfo.template.dtTableName;
+      this.rowobj = {};
+      let obj = {};
+      for (let key in row) {
+        let modifiedTable = key
+          .replace(/[A-Z]/g, (match) => `_${match}`)
+          .toLowerCase();
 
         this.rowobj[modifiedTable] = row[key];
 
-        let str = modifiedTable.substring(nameTable.length+1)
+        let str = modifiedTable.substring(nameTable.length + 1);
         obj[str] = row[key];
       }
-      // console.log("row", row);
-    // getInfoBySqlKey(this.templateInfo.template.sqlKey).then(({ data }) => {
-    //   if (!data || !data.dfVueTemplate) {
-    //     this.$message.error("当前表格未绑定表单!");
-    //     return;
-    //   }});
+      // getInfoBySqlKey(this.templateInfo.template.sqlKey).then(({ data }) => {
+      //   if (!data || !data.dfVueTemplate) {
+      //     this.$message.error("当前表格未绑定表单!");
+      //     return;
+      //   }});
 
       // 新的修改请求
       try {
         let payLoad = {
           basicMap: {
-            btnType: 8,
+            btnType: this.currentBtnData.btnType,
             btnKey: this.currentBtnData.btnKey,
             visible: "false",
             sqlKey: this.templateInfo.template.sqlKey,
@@ -718,13 +717,13 @@ export default {
         // 判断是否绑定dialog弹窗
         if (!this.currentBtnData.btnTableFormGroupKey) {
           if (!res.data || !res.data.template) {
-            this.$message.error("当前表格未绑定表单!");
+            this.$message.error("当前按钮未绑定表单!");
             return;
           }
 
           res.data.template.dfFormSql &&
-          (this.dynamicData = JSON.parse(res.data.template.dfFormSql));
-           this.addRealFieldName(res.data.result.resultMap);
+            (this.dynamicData = JSON.parse(res.data.template.dfFormSql));
+          this.addRealFieldName(res.data.result.resultMap);
           let resultMap = res.data.result.resultMap;
 
           Object.assign(this.defaultValue, resultMap);
@@ -735,18 +734,16 @@ export default {
           this.$nextTick(() => {
             this.$refs.addFromRef.setData(res.data.result.resultMap);
           });
-        }else{
-          this.subTableName = res.data.result.dragTables[1].dtTableName
-          this.btnDialogVisible = true
-          this.groupKey = this.currentBtnData.btnTableFormGroupKey
-          this.$nextTick(()=>{
-            let refChild = this.$refs.dialogRef
-
-            // console.log(this.$refs.dialogRef);
-            refChild.getLists(this.groupKey)
-          })
+        } else {
+          this.subTableName = res.data.result.dragTables[1].dtTableName;
+          this.btnDialogVisible = true;
+          this.groupKey = this.currentBtnData.btnTableFormGroupKey;
+          this.$nextTick(() => {
+            let refChild = this.$refs.dialogRef;
+            refChild.getLists(this.groupKey);
+          });
 
-          let tablesubKey = res.data.result.dragTables[1].tableKey
+          let tablesubKey = res.data.result.dragTables[1].tableKey;
 
           // 查询统计信息
           getStatisticList({
@@ -754,26 +751,31 @@ export default {
               tableKey: tablesubKey,
             },
           }).then((res) => {
-            // console.log('统计', res);
-            this.subCount = res.data
+            this.subCount = res.data;
           });
 
-          let prmKey = this.templateInfo.template.primaryKey
-          let pkey = prmKey.replace(/_([a-z])/g, (match, p1) => p1.toUpperCase());
+          let prmKey = this.templateInfo.template.primaryKey;
+          let pkey = prmKey.replace(/_([a-z])/g, (match, p1) =>
+            p1.toUpperCase()
+          );
 
           let data = {
-            queryMap:{
-              tableKey:res.data.result.dragTables[2].tableKey,
-            }
-          }
+            queryMap: {
+              tableKey: res.data.result.dragTables[2].tableKey,
+            },
+          };
 
-          let key = '#{' + this.templateInfo.template.dtTableName + '.' + this.templateInfo.template.primaryKey
+          let key =
+            "#{" +
+            this.templateInfo.template.dtTableName +
+            "." +
+            this.templateInfo.template.primaryKey;
 
-          data.queryMap[key] = "'" + obj[this.templateInfo.template.primaryKey] + "'";
+          data.queryMap[key] =
+            "'" + obj[this.templateInfo.template.primaryKey] + "'";
 
           getStatisticList(data).then((res) => {
-            // console.log('统计', res);
-            this.tableCount = res.data
+            this.tableCount = res.data;
           });
         }
 
@@ -784,7 +786,6 @@ export default {
         //   realField = realField[0].toLocaleLowerCase() + realField.substring(1);
         //   resultMap[realField] = resultMap[field];
         // });
-
       } catch (error) {
         this.$message.error("网络异常,请稍后再试");
         console.log(error);
@@ -829,7 +830,8 @@ export default {
     // 添加真正的字段名
     addRealFieldName(row) {
       let fieldList = Object.keys(row);
-      let tableName = this.longestCommonSubstring(fieldList);
+      // let tableName = this.longestCommonSubstring(fieldList);
+      let tableName = camelCase(this.tableName);
       fieldList.forEach((field) => {
         let realField = field.replace(tableName, "");
         realField = realField[0].toLocaleLowerCase() + realField.substring(1);
@@ -871,7 +873,7 @@ export default {
       }
       let data = {
         basicMap: {
-          btnType: 9,
+          btnType: btnData.btnType,
           btnKey: btnData.btnKey,
           tableName: this.tableName,
         },
@@ -904,6 +906,46 @@ export default {
         })
         .catch(() => {});
     },
+    // 批量删除接口
+    handleBatchDelete() {
+      let delIds = this.ids;
+      let primary = camelCase(this.templateInfo.template?.primaryKey);
+      // if (row && row[primary] != undefined && row[primary] != null) {
+      //   delIds = [];
+      //   delIds.push(row[primary]);
+      // }
+      let data = {
+        basicMap: {
+          tableName: this.tableName,
+        },
+        conditionMap: {
+          // id: delIds,
+        },
+      };
+      // if (this.currentBtnData.btnParams) {
+      //   let btnParams = JSON.parse(this.currentBtnData.btnParams);
+      //   btnParams.forEach((item) => {
+      //     data.btnParametersMap[
+      //       this.formatField(item.fieldName, camelCase(this.tableName))
+      //     ] = item.fieldValue
+      //       ? item.fieldValue
+      //       : this.currentRow[item.fieldName];
+      //   });
+      // }
+      data.conditionMap[this.templateInfo.template?.primaryKey] = delIds;
+      this.$modal
+        .confirm('是否确认删除"' + delIds + '"的数据项?')
+        .then(function () {
+          return delTableData(data);
+          // return btnCommonApi(data);
+        })
+        .then(() => {
+          // 调用子组件查询方法 目的是携带上子组件中的查询参数
+          this.$refs.mychild.pageList();
+          this.$modal.msgSuccess("删除成功");
+        })
+        .catch(() => {});
+    },
     /** 导出按钮操作 */
     handleExport() {
       let primary = camelCase(this.templateInfo.template?.primaryKey);
@@ -977,12 +1019,11 @@ export default {
       this.$refs.upload.submit();
     },
     // 弹窗新增的数
-    addListHandler(val){
-      this.addLists.push(...val)
-      // console.log(this.addLists);
+    addListHandler(val) {
+      this.addLists.push(...val);
     },
     // 绑定弹窗Dialog确定按钮
-    btnComfirm(){
+    btnComfirm() {
       // let data = {
       //   addListMap:[],
       //   basicMap:{
@@ -1000,108 +1041,109 @@ export default {
     },
     // 去掉表名 开头字母小写
     formatField(field = "", tableName) {
-      // console.log(field, tableName);
       let temp = field.replace(tableName, "");
       return toUnderline(temp[0].toLowerCase() + temp.slice(1));
     },
     //提交编辑结果按钮回调
-    editConfirmHandler() {
-      this.$refs.addFromRef
-        .getData()
-        .then(async (values) => {
-          let data = {
-            basicMap: {
-              tableName: this.tableName,
-              // btnKey: btnData.btnKey,
-              btnKey: this.currentBtnData.btnKey,
-            },
-            addListMap: [values],
-            conditionMap: {},
-            commMap: {},
-            btnParametersMap: {},
-          };
-          if (this.currentBtnData.btnParams) {
-            console.log(this.currentBtnData.btnParams)
-            let btnParams = JSON.parse(this.currentBtnData.btnParams);
-            btnParams.forEach((item) => {
-              data.btnParametersMap[
-                this.formatField(item.fieldName, camelCase(this.tableName))
-              ] = item.fieldValue
-                ? item.fieldValue
-                : this.currentRow[item.fieldName];
-            });
-          }
-          console.log(data)
-          if (Object.keys(this.defaultValue).length) {
-            //修改
-            // 后台接收需要是表中字段真实的名称,无所谓驼峰。
-            data.conditionMap[this.templateInfo.template?.primaryKey] =
-              this.defaultValue[
-                camelCase(this.templateInfo.template?.primaryKey)
-              ];
-            Object.keys(values).map((k) => {
-              data.commMap[k] = values[k];
-            });
-            data.basicMap.btnType = 8;
-            data.basicMap.visible = true;
-          } else {
-            data.basicMap.btnType = 10;
-            data.basicMap.visible = true;
-          }
-          try {
-            let res = await btnCommonApi(data);
-            if (res.code == 200) {
-              this.$message.success("操作成功");
+    async editConfirmHandler() {
+      if (this.$refs.addFromRef) {
+        this.$refs.addFromRef
+          .getData()
+          .then(async (values) => {
+            let data = {
+              basicMap: {
+                tableName: this.tableName,
+                // btnKey: btnData.btnKey,
+                btnKey: this.currentBtnData.btnKey,
+              },
+              addListMap: [values],
+              conditionMap: {},
+              commMap: {},
+              btnParametersMap: {},
+            };
+            if (this.currentBtnData.btnParams) {
+              let btnParams = JSON.parse(this.currentBtnData.btnParams);
+              btnParams.forEach((item) => {
+                data.btnParametersMap[
+                  this.formatField(item.fieldName, camelCase(this.tableName))
+                ] = item.fieldValue
+                  ? item.fieldValue
+                  : this.currentRow[item.fieldName];
+              });
+            }
+            if (Object.keys(this.defaultValue).length) {
+              data.conditionMap[this.templateInfo.template?.primaryKey] =
+                this.defaultValue[this.templateInfo.template?.primaryKey];
+              Object.keys(values).map((k) => {
+                data.commMap[k] = values[k];
+              });
+              data.basicMap.btnType = this.currentBtnData.btnType;
+              data.basicMap.visible = true;
             } else {
+              data.basicMap.btnType = "INSERT";
+              data.basicMap.visible = true;
+            }
+            try {
+              let res = await btnCommonApi(data);
+              if (res.code == 200) {
+                this.$message.success("操作成功");
+              } else {
+                this.$message.error("网络异常,请稍后再试");
+              }
+            } catch (error) {
+              console.log(error);
               this.$message.error("网络异常,请稍后再试");
             }
-          } catch (error) {
-            console.log(error);
+            this.getList();
+            this.defaultValue = {};
+            this.open = false;
+          })
+          .catch((res) => {
+            console.log(res);
+            this.$modal.msgError("表单校验失败,请规范填写数据");
+          });
+      } else {
+        // 没有绑定表单
+        let data = {
+          basicMap: {
+            tableName: this.tableName,
+            // btnKey: btnData.btnKey,
+            btnKey: this.currentBtnData.btnKey,
+            btnType: this.currentBtnData.btnType,
+            visible: true,
+          },
+          addListMap: [],
+          conditionMap: {},
+          commMap: {},
+          btnParametersMap: {},
+        };
+        if (this.currentBtnData.btnParams) {
+          let btnParams = JSON.parse(this.currentBtnData.btnParams);
+          btnParams.forEach((item) => {
+            data.btnParametersMap[
+              this.formatField(item.fieldName, camelCase(this.tableName))
+            ] = item.fieldValue
+              ? item.fieldValue
+              : this.currentRow[item.fieldName];
+          });
+        }
+        // data.basicMap.btnType = this.currentBtnData.btnType;
+        // data.basicMap.visible = true;
+        try {
+          let res = await btnCommonApi(data);
+          if (res.code == 200) {
+            this.$message.success("操作成功");
+          } else {
             this.$message.error("网络异常,请稍后再试");
           }
-          // if (Object.keys(this.defaultValue).length) {
-          //   let updateData = {
-          //     // 基本参数
-          //     basicMap: {
-          //       // 表名
-          //       tableName: this.tableName,
-          //     },
-          //     conditionMap: {},
-          //     commMap: {},
-          //   };
-
-          //   // 后台接收需要是表中字段真实的名称,无所谓驼峰。
-          //   updateData.conditionMap[this.templateInfo.template?.primaryKey] =
-          //     this.defaultValue[
-          //       camelCase(this.templateInfo.template?.primaryKey)
-          //     ];
-          //   Object.keys(values).map((k) => {
-          //     updateData.commMap[k] = values[k];
-          //   });
-          //   let res = await batchEdit(updateData);
-          //   if (res.code == 200) {
-          //     this.$modal.msgSuccess("修改成功");
-          //   } else {
-          //     this.$modal.msgError("修改失败");
-          //   }
-          //   this.getList();
-          // } else {
-          //   let res = await addTableData(data);
-          //   if (res.code == 200) {
-          //     this.$modal.msgSuccess("添加成功");
-          //   } else {
-          //     this.$modal.msgError("添加失败");
-          //   }
-          //   this.getList();
-          // }
-          this.getList();
-          this.defaultValue = {};
-          this.open = false;
-        })
-        .catch((res) => {
-          console.log(res);
-          this.$modal.msgError("表单校验失败,请规范填写数据");
-        });
+        } catch (error) {
+          console.log(error);
+          this.$message.error("网络异常,请稍后再试");
+        }
+        this.getList();
+        this.defaultValue = {};
+        this.open = false;
+      }
     },
     // 使用提交数据类型的按钮获取数据
     tempSubBtn(getData) {
@@ -1161,9 +1203,7 @@ export default {
       );
       if (!fieldConditionList.length) return tableList;
       let res = await this.setDictStyleData();
-      // console.log(res);
       this.dictStyleObj = res;
-      // console.log(JSON.parse(JSON.stringify(this.dictStyleObj)));
       tableList.forEach((row) => {
         // if (!row.styleFieldObj) row.styleFieldObj = {};
         for (let i = 0; i < fieldConditionList.length; i++) {
@@ -1248,7 +1288,7 @@ export default {
         url += "?" + tempArr.join("&");
       }
       // let link = btnData.btnParams;
-      if (type == "3") {
+      if (type == "INNERLINK") {
         this.$router.push(url);
       } else {
         window.open("http://" + url, "_blank");
@@ -1257,22 +1297,27 @@ export default {
 
     // 操作列回调
     excuteHandler(btnData, row) {
+      console.log(btnData, row);
       let { btnType, btnParams } = btnData;
       this.currentBtnData = btnData;
       this.currentRow = JSON.parse(JSON.stringify(row));
-      switch (
-        btnType //3:内链  6:目录  7:外链  8:修改  9:删除
-      ) {
-        case "3":
+      switch (btnType) {
+        case "INNERLINK":
           this.routerHandler(btnData, btnType);
           break;
-        case "7":
+        case "OUTLINK":
           this.routerHandler(btnData, btnType);
           break;
-        case "8":
+        case "UPDATE":
+          this.handleUpdate(row, btnData);
+          break;
+        case "EXECUTE":
+          this.handleUpdate(row, btnData);
+          break;
+        case "INITIATED":
           this.handleUpdate(row, btnData);
           break;
-        case "9":
+        case "DELETE":
           this.handleDelete(row, btnData);
           break;
         default:
@@ -1289,7 +1334,7 @@ export default {
 </script>
 
 <style scoped lang="scss">
-  ::v-deep .el-dialog:not(.is-fullscreen){
-    min-width: 610px !important;
-  }
+::v-deep .el-dialog:not(.is-fullscreen) {
+  min-width: 610px !important;
+}
 </style>