Explorar o código

转换回显列表刷新

liujiejie hai 1 ano
pai
achega
6a2da394b7

+ 2 - 2
src/components/map/index.vue

@@ -197,8 +197,8 @@ export default {
         new TileLayer({
           source: new XYZ({
             // url: "http://127.0.0.1:8010/tiles/{z}/{x}/{y}.png", //本地
-            url: "http://192.168.50.235/tiles/{z}/{x}/{y}.png", //内网
-            // url: "http://106.120.102.238:18000/tiles/{z}/{x}/{y}.png", //外网
+            // url: "http://192.168.50.235/tiles/{z}/{x}/{y}.png", //内网
+            url: "http://106.120.102.238:18000/tiles/{z}/{x}/{y}.png", //外网
           }),
         }),
         new VectorLayer({

+ 73 - 69
src/views/dataAdministration/index.vue

@@ -63,6 +63,8 @@
         lazy
         :load="load"
         :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
+        ref="table"
+        @expand-change="handleExpandChange"
       >
         <!-- Table Columns -->
         <el-table-column prop="fieldName" label="风场名称" min-width="200">
@@ -552,6 +554,7 @@ export default {
       intervalId: null,
       startTime: null,
       maxPollingTime: 5 * 60 * 1000, //轮询最大时间
+      expandedKeys: new Set(), // 用于存储展开行的唯一标识
       loading: false,
       forPltFrom: {},
       editTransferStateForm: {
@@ -630,10 +633,19 @@ export default {
     };
   },
   created() {
-    this.getTableList();
+    this.fetchData();
     this.getBatchCodeList();
   },
   methods: {
+    // 处理行展开和收起事件
+    handleExpandChange(row, expandedRows) {
+      console.log("row", row);
+      if (expandedRows) {
+        this.expandedKeys.add(row.uniqueCode); // 添加到展开列表
+      } else {
+        this.expandedKeys.delete(row.uniqueCode); // 从展开列表中删除
+      }
+    },
     load(tree, treeNode, resolve) {
       console.log(tree, "tree");
       const { batchCode } = tree; // 假设每行都有唯一的 id
@@ -648,6 +660,59 @@ export default {
           resolve([]); // 确保 resolve 被调用
         });
     },
+    async fetchData() {
+      try {
+        const result = await queryDataTransferGroup({
+          ...this.formInline,
+          totalSize: undefined,
+        });
+        this.tableData = result.data.list.map((item) => {
+          return {
+            ...item,
+            hasChildren: true,
+            uniqueCode: item.batchCode + item.fieldCode,
+            children: [],
+          };
+        });
+        this.formInline.totalSize = result.data.totalSize;
+        // 恢复展开状态
+        console.log(this.expandedKeys, "this.expandedKeys");
+        this.$nextTick(() => {
+          this.tableData.forEach((row) => {
+            if (this.expandedKeys.has(row.uniqueCode)) {
+              this.$refs.table.toggleRowExpansion(row, true);
+              // 手动触发子节点加载
+              this.load(row, {}, (children) => {
+                row.children = children;
+              });
+            }
+          });
+        });
+      } catch (error) {
+        this.$message({
+          type: "error",
+          message: "请检查是否连接网络",
+        });
+      }
+    },
+
+    stopPolling() {
+      if (this.intervalId) {
+        clearInterval(this.intervalId);
+        this.intervalId = null;
+      }
+    },
+    startPolling() {
+      this.startTime = new Date().getTime();
+      this.intervalId = setInterval(() => {
+        const currentTime = new Date().getTime();
+        if (currentTime - this.startTime >= this.maxPollingTime) {
+          this.stopPolling();
+        } else {
+          this.fetchData();
+        }
+      }, 10000); // 每10秒调用一次
+    },
     handleCloses(done) {
       this.$confirm("确认关闭?")
         .then((_) => {
@@ -716,7 +781,7 @@ export default {
                           type: "success",
                         });
                         this.$refs.forPltRef.reset("fromPlt");
-                        this.getTableList();
+                        this.fetchData();
                         this.editstateCancel();
                       })
                       .catch((error) => {
@@ -783,7 +848,7 @@ export default {
       this.editNuedialog = false;
       this.loadingViewEdit = false;
       if (!name) {
-        this.getTableList();
+        this.fetchData();
       }
       this.getBatchCodeList();
     },
@@ -861,12 +926,12 @@ export default {
     },
     // 查询
     onSubmit() {
-      this.getTableList();
+      this.fetchData();
     },
     // 重置
     reset(formName) {
       this.$refs[formName].resetFields();
-      this.getTableList();
+      this.fetchData();
     },
     // 新增
     newly(formName) {
@@ -879,7 +944,7 @@ export default {
                 message: "新增成功",
                 type: "success",
               });
-              this.getTableList();
+              this.fetchData();
               this.cancel();
               this.loadingView = false;
             })
@@ -907,33 +972,11 @@ export default {
         alert("弹出窗口已被阻止!请允许弹出式窗口访问本网站。");
       }
     },
-    async getTableList() {
-      try {
-        this.loading = true;
-        const result = await queryDataTransferGroup({
-          ...this.formInline,
-          totalSize: undefined,
-        });
-        this.tableData = result.data.list.map((item) => {
-          return {
-            ...item,
-            hasChildren: true,
-            children: [],
-          };
-        });
-        this.formInline.totalSize = result.data.totalSize;
-        this.loading = false;
-      } catch (error) {
-        this.$message({
-          type: "error",
-          message: "请检查是否连接网络",
-        });
-      }
-    },
+
     //分页数据切换
     handleCurrentChange(val) {
       this.formInline.pageNum = val;
-      this.getTableList();
+      this.fetchData();
     },
     //新增按钮
     addData() {
@@ -977,45 +1020,6 @@ export default {
         this.loading = false;
       }
     },
-
-    async fetchData() {
-      try {
-        const result = await queryDataTransferGroup({
-          ...this.formInline,
-          totalSize: undefined,
-        });
-        this.tableData = result.data.list.map((item) => {
-          return {
-            ...item,
-            hasChildren: true,
-            children: [],
-          };
-        });
-        this.formInline.totalSize = result.data.totalSize;
-      } catch (error) {
-        this.$message({
-          type: "error",
-          message: "请检查是否连接网络",
-        });
-      }
-    },
-    stopPolling() {
-      if (this.intervalId) {
-        clearInterval(this.intervalId);
-        this.intervalId = null;
-      }
-    },
-    startPolling() {
-      this.startTime = new Date().getTime();
-      this.intervalId = setInterval(() => {
-        const currentTime = new Date().getTime();
-        if (currentTime - this.startTime >= this.maxPollingTime) {
-          this.stopPolling();
-        } else {
-          this.fetchData();
-        }
-      }, 10000); // 每10秒调用一次
-    },
   },
   mounted() {
     this.startPolling();

+ 0 - 1
src/views/ledger/anemometer copy.vue

@@ -203,7 +203,6 @@
         <el-button type="primary" @click="newly" size="small">确 定</el-button>
       </span>
     </el-dialog>
-
     <!-- 测风塔详情 -->
     <el-dialog title="详情" :visible.sync="unusualdialog" width="400px">
       <p>测风塔名称:{{ hightower.anemometerName }}</p>