Bläddra i källkod

切换表单按钮

duy 1 vecka sedan
förälder
incheckning
5b9f8bd684
2 ändrade filer med 365 tillägg och 33 borttagningar
  1. 9 0
      src/api/manager/wbstree.js
  2. 356 33
      src/views/manager/projectinfo/tree.vue

+ 9 - 0
src/api/manager/wbstree.js

@@ -377,4 +377,13 @@ export const getQueryValueByNodeType = (params) => {
         method: 'get',
         params
     })
+}
+//获取表单类型树
+//查询当前节点的同级节点
+export const getTreeByType = (params) => {
+    return request({
+        url: '/api/blade-manager/wbsPrivate/tab-Type-lazy-tree-project',
+        method: 'get',
+        params
+    })
 }

+ 356 - 33
src/views/manager/projectinfo/tree.vue

@@ -72,12 +72,32 @@
       <el-row :gutter="20" class="h-100p" style="padding: 10px">
         <el-col :span="8" style="height: 85%">
           <div class="h-100p flex flex-d-c">
-            <p style="margin-top: 2px">工程节点信息</p>
+               <p style="margin-top: 2px">
+              工程节点信息
+                <el-button
+                v-if="isNodeType"
+                style="margin-right: 10px"
+                size="medium"
+                icon="el-icon-set-up"
+                @click="changeType(false)"
+                type="primary"
+                >切换表单
+              </el-button>
+              <el-button
+              v-else
+                style="margin-right: 10px"
+                size="medium"
+                icon="el-icon-set-up"
+                @click="changeType(true)"
+                type="warning"
+                >切换节点
+              </el-button>
+            </p>
             <div
               class="flex"
               style="align-items: center; justify-content: space-between"
             >
-            <div>
+            <div v-if="isNodeType">
                <div>
                  <el-radio v-model="searchType" label="1">节点</el-radio>
                </div>
@@ -86,6 +106,7 @@
                 </div>
             </div>
               <el-input
+              v-if="isNodeType"
                 placeholder="输入关键字进行过滤"
                 v-model="filterText"
                 clearable
@@ -93,15 +114,26 @@
                 @clear="clearSearch"
               ></el-input>
              
-              <el-button type="primary" @click="searchTreeClick"
+              <el-button type="primary" @click="searchTreeClick" v-if="isNodeType"
                 >搜索</el-button
               >
+               <el-input
+               v-if="!isNodeType"
+                placeholder="输入关键字进行过滤"
+                v-model="filterText1"
+                clearable
+                style="width: 65%; margin-right: 15px"
+                @clear="clearSearch1"
+              ></el-input>
              
+              <el-button type="primary" @click="searchTreeClick1"  v-if="!isNodeType"
+                >搜索</el-button
+              >
               <el-tooltip content="查询工序节点无内业资料类型" placement="top">
-                <el-button type="success" @click="filterSearchClick" >过滤</el-button>
+                <el-button type="success" @click="filterSearchClick"  v-if="isNodeType">过滤</el-button>
               </el-tooltip>
             </div>
-            <div class="flex1 ov-hidden">
+            <div class="flex1 ov-hidden" v-if=isNodeType>
               <el-scrollbar class="h-100p" v-if="isShowTree">
                 <div v-loading="treeLoad">
                   <el-tree
@@ -218,12 +250,40 @@
                 </div>
               </el-scrollbar>
             </div>
+            <div v-else>        
+              <el-scrollbar class="h-100p" >
+              
+              <el-tree
+             
+                :default-expanded-keys="defaultExpandedKeysType"
+                ref="treeByType"
+                class="filter-tree"
+                lazy
+                :load="loadNodeByType"
+                :props="defaultPropsByType"
+                :expand-on-click-node="false"
+                highlight-current
+                node-key="id"
+                @node-click="getNodeDetailByType"
+                @node-expand="handleNodeExpand"
+                @node-collapse="handleNodeCollapse"
+              >
+                <span class="custom-tree-node" slot-scope="{ node, data }">
+                  <div class="pd-r-20">
+                    {{ node.label }}
+                  </div>
+                </span>
+              </el-tree>
+              
+              
+              </el-scrollbar>
+            </div>
           </div>
         </el-col>
         <el-col :span="16" class="h-100p flex flex-d-c">
           <template v-if="leftType == 5">
-            <div class="mg-b-10">节点信息</div>
-            <div>
+            <div class="mg-b-10" v-if='isNodeType'>节点信息</div>
+            <div v-if='isNodeType'>
               <el-table :data="tableData" border style="width: 100%">
                 <el-table-column
                   align="center"
@@ -265,6 +325,7 @@
                 <span>当前项目信息表</span>
           
                 <el-button
+               
                   type="text"
                   style="margin-left: 10px"
                   icon="el-icon-edit-outline"
@@ -272,6 +333,7 @@
                   @click="editEditElementForm()"
                 ></el-button>
                 <el-button
+               v-if="isNodeType"
                   type="text"
                   icon="el-icon-sort"
                   class="text-icon"
@@ -290,7 +352,7 @@
                 <el-table-column
                   align="center"
                   prop="tableName"
-                  label="表单名称"
+                  label="表单名称111"
                 ></el-table-column>
                 <el-table-column
                   align="center"
@@ -305,18 +367,21 @@
                   label="填报率"
                 ></el-table-column>
                 <el-table-column
+               
                   align="center"
                   prop="tableType"
                   :formatter="formatTableType"
                   width="100"
                   label="表单类型"
                 ></el-table-column>
-                <el-table-column width="150"
+                
+                <el-table-column width="150" 
                   align="center"
                   prop="tableOwner"
                   :formatter="formatOwner"
                   label="所属方"
                 ></el-table-column>
+                
                 <el-table-column label="操作"      >
                   <template slot-scope="scope">
                     <el-button
@@ -536,6 +601,7 @@
                     </el-link>
                     <el-link
                       class="mg-l-10"
+                     
                       type="primary"
                       :disabled="
                         scope.row.excelId == -1 || scope.row.excelId == null
@@ -551,6 +617,7 @@
                       "
                       >编辑元素
                     </el-link>
+                 
                     <el-link
                       class="mg-l-10"
                       type="primary"
@@ -2170,7 +2237,8 @@ import {
   selectPrivateFormElements,
   syncCurrentFormInProject,
   getQueryValueByType,
-  getQueryValueByNodeType
+  getQueryValueByNodeType,
+   getTreeByType,
 } from "@/api/manager/wbstree";
 import {
   saveElement,
@@ -2180,6 +2248,7 @@ import {
   importWbsElement,
 } from "@/api/manager/wbsformelement";
 import {
+ 
   getLazytree,
   getDetail,
   update,
@@ -2195,7 +2264,7 @@ import {
   tabTypeLazyTree,
   syncContractTabSort,
   linkNodeTree,
-  getLinekNodeTreelist,getNameRule,getTitleRange,saveOrUpdateNameRule,deletedNameRule
+  getLinekNodeTreelist,getNameRule,getTitleRange,saveOrUpdateNameRule,deletedNameRule,delTabInfoAll
 } from "@/api/manager/wbsprivate";
 import { findProjectTree as getAlltree } from "@/api/manager/projectinfo";
 
@@ -2232,6 +2301,12 @@ export default {
     };
 
     return {
+      isNodeType:true,
+      isRestoringSelection: false,
+
+      expandedKeysType: [],
+      defaultExpandedKeysType: [],
+      currentNodeKey: null, // 保存当前选中的节点key
       fromcurNode: {},
       formDatass: [],
       editElementFormTag: false,
@@ -2287,6 +2362,8 @@ export default {
       id: "",
       projectid: "",
       filterText: "",
+      filterText1: "",
+      isShowTree1:true,
       treeData: [],
       searchType: "1",
       isSearch: false,
@@ -2323,6 +2400,13 @@ export default {
           // return !data.hasChildren || (data.isExistForm == 1);
         },
       },
+      defaultPropsByType:{
+        children: 'children',
+          label: 'title',
+           isLeaf:function (data) {
+             return !data.hasChildren
+           }
+      },
       leftType: 5,
       curTreeData: {},
       curTreeNode: {},
@@ -2599,7 +2683,9 @@ export default {
       codeDialog:false,
  
       codeSetRef: null,
-      typeTem:''
+      typeTem:'',
+      isShowTree1:true,
+      cachedNodes: new Map(),      // 缓存已加载的节点数据
       
     };
   },
@@ -2609,10 +2695,27 @@ export default {
   },
   created() {
     this.init();
-    //console.log(this.userInfo)
+
+    
+
+        // 尝试恢复之前选中的节点
+    // // 尝试恢复之前的状态
+    // this.restoreTreeState();
+     // 从本地存储恢复展开的keys
+    // const savedExpandedKeys = JSON.parse(localStorage.getItem('treeExpandedKeys') || '[]');
+    // this.defaultExpandedKeysType = savedExpandedKeys;
   },
   methods: {
     //#region
+    changeType(val){
+      console.log(val,'val');
+      
+      this.isNodeType=val
+      this.formData=[]
+       localStorage.setItem('isNodeType',val);
+        
+
+    },
     init() {
       //this.id = this.$route.query.wbsid;
       //this.projectid = this.$route.query.pid;
@@ -2631,7 +2734,9 @@ export default {
       this.defaultExpandedKeys = getStore({ name: this.expandName });
       this.projectName = this.$route.query.projectName;
     },
+    
     loadNode(node, resolve) {
+      
       let pid = 0;
       if (node.level != 0) {
         pid = node.data.id;
@@ -2648,7 +2753,77 @@ export default {
         return resolve(arr);
       });
     },
-    getNodeDetail(data, node) {
+    // 在 loadNodeByType 中恢复选中状态
+  loadNodeByType(node, resolve) {
+     // 如果有缓存且不是根节点,直接返回缓存
+    if (node.level !== 0 && this.cachedNodes.has(node.data.id)) {
+      return resolve(this.cachedNodes.get(node.data.id));
+    }
+    let pid = 12345678910;
+    if (node.level != 0) {
+      pid = node.data.id;
+    }
+    getTreeByType({
+      parentId: pid,
+      projectId: this.projectid,
+      current: 1,
+      size: 1000,
+      titleName: this.filterText1
+    }).then((res) => {
+      let arr = [];
+      if (Array.isArray(res.data.data['records'])) {
+        arr = res.data.data['records'];
+      }
+      resolve(arr);
+      
+      // 恢复选中状态
+      this.$nextTick(() => {
+        if (this.currentNodeKey) {
+          this.$refs.treeByType.setCurrentKey(this.currentNodeKey);
+        }
+      });
+    }).catch(error => {
+      console.error('加载树节点失败:', error);
+      resolve([]);
+    });
+  },
+
+ saveTreeState() {
+    const tree = this.$refs.treeByType;
+    if (!tree) return;
+    
+    // 保存当前选中节点
+    this.currentNodeKey = tree.getCurrentKey();
+    
+    // 保存所有展开节点
+    this.defaultExpandedKeysType = [];
+    const traverse = (node) => {
+      if (node.expanded && node.data) {
+        this.defaultExpandedKeysType.push(node.data.id);
+      }
+      if (node.childNodes) {
+        node.childNodes.forEach(traverse);
+      }
+    };
+    traverse(tree.store.root);
+  },
+  
+  // 节点展开时保存状态
+  handleNodeExpand(data) {
+    if (!this.defaultExpandedKeysType.includes(data.id)) {
+      this.defaultExpandedKeysType.push(data.id);
+    }
+  },
+  
+  // 节点折叠时更新状态
+  handleNodeCollapse(data) {
+    const index = this.defaultExpandedKeysType.indexOf(data.id);
+    if (index > -1) {
+      this.defaultExpandedKeysType.splice(index, 1);
+    }
+  },
+  
+  getNodeDetail(data, node) {
       console.log("getNodeDetail", data);
       let parentName = "";
       if (node.parent.data) {
@@ -2671,6 +2846,30 @@ export default {
       //获取节点展开路径
       this.getExpandedKeys(node);
     },
+    getNodeDetailByType(data, node) {
+      console.log(data, 'data');
+       // 保存当前选中的节点
+    this.currentNodeKey = data.id;
+      this.curTreeData = data;
+      this.curTreeNode = node;
+      data.tableName = data.title;
+      this.formData = [data];
+      
+          localStorage.setItem('lastSelectedTreeNodeId', data.id);
+          localStorage.setItem('lastSelectedTreeData', JSON.stringify(data));
+          
+          // 只存储node对象中的必要信息,避免循环引用
+          const nodeInfo = {
+            id: node.data.id,
+            label: node.label,
+            level: node.level,
+            isLeaf: node.isLeaf,
+            expanded: node.expanded,
+            // 其他你需要的属性
+          };
+          localStorage.setItem('lastDataNode', JSON.stringify(nodeInfo));
+    },
+  
     saveNode() {
       const type = this.wbsType;
       this.$refs["nodeDetail"].validate((valid) => {
@@ -2849,20 +3048,109 @@ export default {
     },
 
     updateNodeTable() {
-      selectByNodeTable( this.curTreeData.id, this.projectid, this.id).then(
-        (res) => {
-          if (res.data.data && res.data.data.length) {
-            this.formData = res.data.data;
-            this.formData.forEach((ele) => {
-              ele.nodeType = Number(ele.nodeType);
-            });
-          } else {
-            this.formData = [];
-          }
-        }
-      );
+
+      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.formData.forEach((ele) => {
+                  ele.nodeType = Number(ele.nodeType);
+                });
+              } else {
+                this.formData = [];
+              }
+            }
+          );
+      }else{
+        console.log(8888888);
+        this.reloadEntireTree();
+      
+      }
     },
+     // 重新加载整棵树
+  async reloadEntireTree() {
+        // 1. 保存当前状态
+    const currentKey = this.$refs.treeByType.getCurrentKey();
+    this.saveTreeState();
+    
+    // 2. 清空缓存
+    this.cachedNodes.clear();
+    
+    // 3. 获取树组件引用
+    const tree = this.$refs.treeByType;
+    if (!tree) return;
+    
+    // 4. 清空根节点子节点
+    const rootNode = tree.store.root;
+    const rootId = rootNode.childNodes[0].data.id || 'root';
+    
+    await this.$nextTick();
+    tree.updateKeyChildren(rootId, []);
+    
+    // 5. 强制重新加载根节点
+    const root = tree.getNode(rootId);
+    if (root) {
+      root.loaded = false;
+      root.expand(); // 这会触发loadNodeByType
+    }
+      // 6. 等待树重新加载完成
+  await new Promise(resolve => {
+    const checkLoaded = () => {
+      if (root.loaded) {
+        resolve();
+      } else {
+        setTimeout(checkLoaded, 50);
+      }
+    };
+    checkLoaded();
+  });
+    // 7. 恢复选中状态并获取最新数据
+  if (currentKey) {
+    tree.setCurrentKey(currentKey);
+    await this.$nextTick();
+     const highlightedEl = document.querySelector('.el-tree--highlight-current .is-current');
+  
+     
+    // 方法1:直接获取当前节点最新数据(推荐)
+    const currentNode = tree.getNode(currentKey);
+    if (currentNode) {
+      console.log('最新节点数据:', currentNode.data);
+      this.currentNodeData = currentNode.data;
+      // this.currentNodeData.tableName = this.currentNodeData.title
+     
+      
+      if(highlightedEl){
+         this.formData=[{...this.currentNodeData,tableName:this.currentNodeData.title} ]
+      }else{
+        this.formData=[]
+      }
 
+     
+    }else{
+       this.formData=[]
+    }
+    
+
+  }
+    // 6. 恢复状态
+    await this.$nextTick();
+    if (this.currentNodeKey) {
+      tree.setCurrentKey(this.currentNodeKey);
+     // 方法1:使用getNode获取完整节点信息(推荐)
+
+ 
+    
+    }
+    
+    // 确保展开状态恢复
+    this.defaultExpandedKeysType.forEach(key => {
+      const node = tree.getNode(key);
+      if (node && !node.expanded) {
+        node.expand();
+      }
+    });
+  },
     deleNode(data, node) {
       let pid = data.primaryKeyId ? data.primaryKeyId : data.pKeyId;
       this.$confirm(
@@ -2885,6 +3173,7 @@ export default {
         })
         .catch(() => {});
     },
+  // 重新加载整棵树
 
     importHandle() {},
 
@@ -2958,13 +3247,24 @@ export default {
         confirmButtonText: "删除",
         cancelButtonText: "取消",
       }).then(() => {
-        removeTableById(row.id, this.projectid, this.id).then(() => {
-          this.formData.splice(index, 1);
-          this.$message({
-            type: "success",
-            message: "删除成功!",
+       
+        if(this.isNodeType){
+           removeTableById(row.id, this.projectid, this.id).then(() => {
+              this.formData.splice(index, 1);
+              this.$message({
+                type: "success",
+                message: "删除成功!",
+              });
           });
-        });
+        }else{
+             delTabInfoAll(row.pkeyId).then(() => {
+              this.formData.splice(index, 1);
+              this.$message({
+                type: "success",
+                message: "删除成功!",
+              });
+          });
+        }
       });
     },
     async hideMD(row) {
@@ -3132,6 +3432,26 @@ export default {
 
       this.searchtreeLoad = false;
     },
+     searchTreeClick1() {
+      
+        // 强制重新加载整个树结构,从根节点开始
+  // this.$refs.treeByType.load({ level: 0, data: { id: 12345678910 } });
+  const lastDataNode=localStorage.getItem('lastDataNode');
+        this.loadNodeByType(lastDataNode);
+      },
+      
+  // 清空搜索
+clearSearch1() {
+  this.filterText1 = '';
+  // 同样从根节点重新加载
+  // this.$refs.treeByType.load({ level: 0, data: { id: 12345678910 } });
+        const lastDataNode=localStorage.getItem('lastDataNode');
+        this.loadNodeByType(lastDataNode);
+
+},
+// 刷新树数据
+
+
     filterSearchClick(){
     
         this.isSearch = true;
@@ -4645,7 +4965,8 @@ export default {
     },
     getSelectFormElements(id) {
       this.editEleTableloading = true;
-      selectFormElements(this.curEleTable.pkeyId, {
+      let finalId=this.isNodeType?this.curEleTable.pkeyId:this.curEleTable.id
+      selectFormElements(finalId, {
         type: 0,
         search: this.searchinput,
       }).then((res) => {
@@ -4670,6 +4991,8 @@ export default {
 
     saveEles() {
       if (this.editTable.length > 0) {
+        console.log( this.curEleTable,' this.curEleTable');
+        
         this.saveLoading = true;
         updateBatchElements(
           this.editTable,