Browse Source

修改SQL工作台页面

乐菲 1 week ago
parent
commit
3b72e027fb

+ 15 - 1
src/views/mes/queryManage/QueryManageForm.vue

@@ -224,6 +224,7 @@ export default {
           masterId: this.formData.id,
           index: item.ordinalPosition + 1,
           ...item,
+          listOperationCondition: false, // 确保在...item之后设置,避免被覆盖,使用布尔值
         }));
         this.$refs.queryManageColumnFormRef.formData = [...list];
       });
@@ -274,10 +275,23 @@ export default {
       console.log("子表校验完成");
       this.formLoading = true;
       try {
+        // 获取子组件数据
+        const subData = this.$refs.queryManageColumnFormRef.getData();
+        console.log("从子组件获取的数据:", subData);
+
+        // 强制转换queryManageColumns中的listOperationCondition为字符串"1"或"0"
+        const processedColumns = subData.map((item) => ({
+          ...item,
+          listOperationCondition: item.listOperationCondition ? "1" : "0",
+        }));
+
         const data = {
           ...this.formData,
-          queryManageColumns: this.$refs.queryManageColumnFormRef.getData(),
+          queryManageColumns: processedColumns,
         };
+
+        console.log("最终提交的数据:", data);
+
         if (data.id) {
           // 修改
           console.log("调用修改接口");

+ 0 - 53
src/views/mes/queryManage/components/DictTag.vue

@@ -1,53 +0,0 @@
-<template>
-  <el-tag
-    v-if="showTag"
-    :type="realColorType"
-    :size="size"
-    :color="realBgColor"
-    style="color: #fff"
-    disable-transitions
-  >
-    {{ dictLabel }}
-  </el-tag>
-</template>
-
-<script>
-import { getDictOptions } from "@/utils/dict";
-
-export default {
-  name: "DictTag",
-  props: {
-    type: { type: String, required: true },
-    value: { type: [String, Number, Boolean], required: true },
-    size: { type: String, default: null },
-  },
-  computed: {
-    showTag() {
-      return (
-        this.type != null && this.value !== undefined && this.value !== null
-      );
-    },
-    dictItem() {
-      const opts = getDictOptions(this.type);
-      return opts.find((d) => d.value === String(this.value)) || {};
-    },
-    realColorType() {
-      const ct = this.dictItem.colorType;
-      return ct === "default" || !ct ? "info" : ct;
-    },
-    realBgColor() {
-      const cls = this.dictItem.cssClass;
-      return cls && this.isHexColor(cls) ? cls : "";
-    },
-    dictLabel() {
-      return this.dictItem.label || "";
-    },
-  },
-  methods: {
-    // 仅保留 isHexColor 实现,内嵌
-    isHexColor(color) {
-      return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color);
-    },
-  },
-};
-</script>

+ 16 - 10
src/views/mes/queryManage/components/QueryManageColumnForm.vue

@@ -139,7 +139,7 @@
             </el-form-item>
           </template>
         </el-table-column>
-        <el-table-column label="查询方式" min-width="100" align="center">
+        <!-- <el-table-column label="查询方式" min-width="100" align="center">
           <template v-slot="{ row, $index }">
             <el-form-item
               :prop="`formData.${$index}.listOperationCondition`"
@@ -160,18 +160,18 @@
               </el-select>
             </el-form-item>
           </template>
-        </el-table-column>
-        <el-table-column label="多选" min-width="50" align="center">
+        </el-table-column> -->
+        <el-table-column label="多选" min-width="100" align="center">
           <template v-slot="{ row, $index }">
             <el-form-item
-              :prop="`formData.${$index}.multiSelect`"
-              :rules="formRules.multiSelect"
+              :prop="`formData.${$index}.listOperationCondition`"
+              :rules="formRules.listOperationCondition"
               class="mb-0px!"
             >
               <el-checkbox
-                v-model="row.multiSelect"
-                :true-value="1"
-                :false-value="0"
+                v-model="row.listOperationCondition"
+                true-value="1"
+                false-value="0"
               />
             </el-form-item>
           </template>
@@ -315,7 +315,12 @@ export default {
           QueryManageApi.getQueryManageColumnListByMasterId(val).then(function (
             res
           ) {
-            that.formData = res.data;
+            // 将后端返回的字符串"1"/"0"转换为布尔值true/false
+            const processedData = res.data.map((item) => ({
+              ...item,
+              listOperationCondition: item.listOperationCondition === "1",
+            }));
+            that.formData = processedData;
           });
         } finally {
           this.formLoading = false;
@@ -350,7 +355,7 @@ export default {
         javaField: undefined,
         dictType: undefined,
         example: undefined,
-        listOperationCondition: undefined,
+        listOperationCondition: false,
         listOperationResult: "false",
         ifHide: "false",
         htmlType: "input",
@@ -381,6 +386,7 @@ export default {
     },
     /** 表单值 */
     getData() {
+      console.log("子组件getData返回的数据:", this.formData);
       return this.formData;
     },
   },

+ 40 - 20
src/views/mes/queryManage/queryNew.vue

@@ -69,6 +69,7 @@
     >
       <el-table-column
         v-if="showMultipleList.length"
+        key="selection-column"
         type="selection"
         width="55"
       />
@@ -199,7 +200,7 @@ import { getQueryManageButtonPage } from "@/api/mes/queryManage/button";
 import { saveAs } from "file-saver";
 import * as XLSX from "xlsx";
 import FilterColumnInQuery from "./components/FilterColumnInQuery.vue";
-import DictTag from "./components/DictTag.vue";
+import DictTag from "@/components/DictTag";
 import ParameterDetail from "./components/ParameterDetail.vue";
 import ReportPrint from "./components/ReportPrint.vue";
 import request from "@/utils/request";
@@ -282,6 +283,7 @@ export default {
         this.showMultipleList = this.queryData.filter(
           (item) => item.listOperationCondition === "1"
         );
+        console.log("showMultipleList长度", this.showMultipleList.length);
         this.queryList = [];
         for (let i = 0; i < this.searchData.length; i++) {
           const { dataType, htmlType, dictType, columnName } =
@@ -651,7 +653,13 @@ export default {
             `${this.title}.xlsx`
           );
         }, 1000);
-      } catch {}
+      } catch (error) {
+        // 忽略取消操作的错误
+        if (error !== "cancel") {
+          console.error("导出失败:", error);
+          this.$message.error("导出失败");
+        }
+      }
     },
 
     async ExportAll() {
@@ -663,6 +671,12 @@ export default {
           paramList: this.queryParamList,
         });
         this.$download.excel(data, this.title + ".xls");
+      } catch (error) {
+        // 忽略取消操作的错误
+        if (error !== "cancel") {
+          console.error("导出失败:", error);
+          this.$message.error("导出失败");
+        }
       } finally {
         this.exportLoading = false;
       }
@@ -719,29 +733,35 @@ export default {
     async saveColumnWidth() {
       if (!this.headerWidthChange) return;
       this.headerWidthChange = false;
-      const widthList = [];
-      // 确保queryData是数组
-      if (!Array.isArray(this.queryData)) return;
 
-      const headers = this.$refs.tableRef.$el.querySelectorAll(
-        ".el-table__header-wrapper tr th"
+      const widthList = [];
+      // 1. 所有“逻辑上应该显示”的列
+      const visibleMap = new Map(
+        this.queryData.filter((c) => !c.ifHide).map((c) => [c.columnComment, c]) // 用列名当 key
       );
-      const visibleColumns = this.queryData.filter((item) => !item.ifHide);
-      const validHeaders = [...headers].filter(
+
+      // 2. 真正渲染出来的 th
+      const thList = Array.from(
+        this.$refs.tableRef.$el.querySelectorAll(
+          ".el-table__header-wrapper tr th"
+        )
+      ).filter(
         (th) =>
           !th.classList.contains("el-table-column--selection") &&
-          th.innerText.trim() !== ""
+          !th.classList.contains("el-table-column--index")
       );
-      validHeaders.forEach((header, i) => {
-        const correspondingItem = visibleColumns[i];
-        if (correspondingItem) {
-          widthList.push({
-            id: correspondingItem.id,
-            javaField: header.offsetWidth,
-          });
-        }
+
+      thList.forEach((th) => {
+        const w = th.offsetWidth;
+        if (!w) return; // 虚拟滚动或隐藏时直接跳过
+        const comment = th.innerText.trim();
+        const col = visibleMap.get(comment);
+        if (col) widthList.push({ id: col.id, javaField: w });
       });
-      await QueryManageApi.updateWidth(widthList);
+
+      if (widthList.length) {
+        await QueryManageApi.updateWidth(widthList);
+      }
     },
 
     buildQueryParamFromRoute() {
@@ -814,7 +834,7 @@ export default {
 
 /* ---------- 原来的表格样式 ---------- */
 :deep(.el-table__row) {
-  transition: none;
+  height: 15px !important;
 }
 .el-table--medium .el-table__cell,
 .el-table--small .el-table__cell {