Quellcode durchsuchen

fix(manager): 修复关联清表功能并优化代码结构

duy vor 5 Tagen
Ursprung
Commit
35cc9f4e7d
1 geänderte Dateien mit 71 neuen und 66 gelöschten Zeilen
  1. 71 66
      src/views/manager/projectinfo/tree.vue

+ 71 - 66
src/views/manager/projectinfo/tree.vue

@@ -4143,7 +4143,8 @@ clearSearch1() {
       this.GLExcelFrom.excelId = scope.row.excelId;
       this.GLExcelFrom.ids = scope.row.id;
       this.GLExcelFrom.initTableName = scope.row.initTableName;
-      console.log(this.GLExcelFrom, "this.GLExcelFrom");
+      this.GLExcelFrom.pkeyId = scope.row.pkeyId;
+  
     },
     changetherr() {
       //清表类型选择框change事件
@@ -4169,75 +4170,79 @@ clearSearch1() {
         this.$refs.tree.setCheckedKeys([data.id]);
       }
     },
-    async saveLinkTab() {
-      //保存按钮
-      let checkNodes = this.$refs.tree.getCheckedNodes();
-      if (checkNodes.length > 0) {
-        let node = checkNodes[checkNodes.length - 1];
-        if (node.fileType != 3) {
-          this.$message({
-            type: "warning",
-            message: "请先上传Excel表",
-          });
-          return;
-        }
-        const { data: res } = await saveLinkTab({
-          exceTabId: node.id,
-          tabId: this.GLExcelFrom.id,
-        });
-        console.log(res);
-        if (res.code === 200) {
-          this.$message({
-            type: "success",
-            message: "关联清表成功",
-          });
-          // selectByNodeTable刷新表单列表
-            // await this.updateNodeTable()
-          if(this.isNodeType){
-              selectByNodeTable( this.curTreeData.id, this.projectid, this.id).then(
-                (res) => {
-                 
-                  if (res.data.data && res.data.data.length) {
-                    this.formData = res.data.data;
-                          this.GLExcel = false;
-                            this.formData.forEach((ele) => {
-                              if(ele.excelId = this.GLExcelFrom.excelId){
-                                this.GLExcelFrom.initTableId=ele.initTableId 
-                              }
-                            })
-                            console.log( this.GLExcelFrom,' this.GLExcelFrom');
-                            
-                            
-                              this.rightClick(
-                                this.GLExcelFrom.id,
-                                this.GLExcelFrom.excelId,
-                                this.GLExcelFrom.ids,
-                                this.GLExcelFrom.initTableName,
-                                this.GLExcelFrom.initTableId
-                              );
-                  
-                                
-                  } else {
-                    this.formData = [];
-                  }
-                }
-              ).finally(() => {
-                this.GLExcel = false;
-              })
-          }else{
-            this.reloadEntireTree();
-             this.GLExcel = false;
-          }
-           
+async saveLinkTab() {
+  // 保存按钮
+  let checkNodes = this.$refs.tree.getCheckedNodes();
+  if (checkNodes.length > 0) {
+    let node = checkNodes[checkNodes.length - 1];
+    if (node.fileType != 3) {
+      this.$message({
+        type: "warning",
+        message: "请先上传Excel表",
+      });
+      return;
+    }
+    
+    try {
+      const { data: res } = await saveLinkTab({
+        exceTabId: node.id,
+        tabId: this.GLExcelFrom.id,
+      });
       
-        }
-      } else {
+      if (res.code === 200) {
         this.$message({
-          type: "warning",
-          message: "请先设置清表",
+          type: "success",
+          message: "关联清表成功",
         });
+        
+        // 保存原始的pkeyId
+        const originalPkeyId = this.GLExcelFrom.pkeyId;
+        
+        if (this.isNodeType) {
+          // 加载节点类型的数据
+          const response = await selectByNodeTable(this.curTreeData.id, this.projectid, this.id);
+          
+          if (response.data.data && response.data.data.length) {
+            this.formData = response.data.data;
+            // 查找并更新initTableId
+            const matchedItem = this.formData.find(ele => ele.pkeyId === originalPkeyId);
+            if (matchedItem) {
+              this.GLExcelFrom.initTableId = matchedItem.initTableId;
+        
+            }
+            
+            // 调用rightClick方法
+            this.rightClick(
+              this.GLExcelFrom.id,
+              this.GLExcelFrom.excelId,
+              this.GLExcelFrom.ids,
+              this.GLExcelFrom.initTableName,
+              this.GLExcelFrom.initTableId
+            );
+          } else {
+            this.formData = [];
+          }
+        } else {
+          // 非节点类型,重新加载整个树
+          await this.reloadEntireTree();
+        }
+        
+        this.GLExcel = false;
       }
-    },
+    } catch (error) {
+      console.error("关联清表失败:", error);
+      this.$message({
+        type: "error",
+        message: "关联清表失败",
+      });
+    }
+  } else {
+    this.$message({
+      type: "warning",
+      message: "请先设置清表",
+    });
+  }
+},
     getReturnNode2(node, _array, value) {
       let isPass =
         node.data && node.data.name && node.data.name.indexOf(value) !== -1;