wyh 9 місяців тому
батько
коміт
bc38bc927a

+ 11 - 10
src/components/module_interLock/UEquipmentTree/UEquipmentTree.vue

@@ -31,7 +31,7 @@
         tpmTreeData: [], // 树形列表使用数据
         replaceFields: {
           children: 'children',
-          title: 'name',
+          title: 'interlockName',
         },
       }
     },
@@ -41,14 +41,15 @@
     methods: {
       getTpmTreeData(){
         getAction(`/base/interlockBase/lever12`).then(res=>{
-          if (res.success) {
+          // if (res.success) {
+            console.log('11111',res)
             // 防止res.result对tpmListData造成地址赋值的问题
-            this.tpmListData = JSON.parse(JSON.stringify(res.result))
-            this.tpmTreeData = this.handleTree(res.result, "id", "parentid")
+            this.tpmListData = JSON.parse(JSON.stringify(res))
+            this.tpmTreeData = this.handleTree(res, "id", "pid")
             console.log(this.tpmTreeData)
-          } else {
+          // } else {
             
-          }
+          // }
         })
       },
       filterTreeNode(node) {
@@ -65,11 +66,11 @@
         // 筛选后数据
         var filterData = []
         // 筛选符合条件的数据:包含当前搜索的项
-        console.log(this.tpmListData)
-        filterData = this.tpmListData.filter(item => (item.name.indexOf(value) !== -1))
+        console.log('原数据',this.tpmListData)
+        filterData = this.tpmListData.filter(item => (item.interlockName.indexOf(value) !== -1))
         // var data = []
         // filterData.forEach(item => {
-        //   var arr = this.tpmListData.filter(data => item.parentid === data.id)
+        //   var arr = this.tpmListData.filter(data => item.pid === data.id)
         //   console.log('父级', arr)
         //   // filterData = [...filterData, ...arr]
         // })
@@ -79,7 +80,7 @@
         
 
         
-        this.tpmTreeData = this.handleTree(filterData, "id", "parentid")
+        this.tpmTreeData = this.handleTree(filterData, "id", "pid")
         // const expandedKeys = dataList.map(item => {
         //   if (item.name.indexOf(value) > -1) {
         //       // return getParentKey(item.key, gData);

+ 6 - 0
src/main.js

@@ -18,6 +18,8 @@ import Viser from 'viser-vue'
 import 'ant-design-vue/dist/antd.less';  // or 'ant-design-vue/dist/antd.less'
 // 修改框架:新增全新弹窗全局组件
 import UComponents from '@/components/module_interLock/index'
+// 修改框架:新增递归树全局方法
+import { handleTree } from "@/utils/interLock";
 
 import '@/permission' // permission control
 import '@/utils/filter' // base filter
@@ -63,8 +65,12 @@ Vue.use(Print)
 Vue.use(preview)
 Vue.use(vueBus);
 Vue.use(JeecgComponents);
+
 // 修改框架:新增全新弹窗全局组件
 Vue.use(UComponents);
+// 修改框架:全局挂载方法递归树
+Vue.prototype.handleTree = handleTree
+
 Vue.use(VueAreaLinkage);
 
 SSO.init(() => {

+ 50 - 0
src/utils/interLock.js

@@ -0,0 +1,50 @@
+/**
+ * 构造树型结构数据
+ * @param {*} data 数据源
+ * @param {*} id id字段 默认 'id'
+ * @param {*} parentId 父节点字段 默认 'parentId'
+ * @param {*} children 孩子节点字段 默认 'children'
+ */
+export function handleTree(data, id, parentId, children) {
+  let config = {
+    id: id || 'id',
+    parentId: parentId || 'parentId',
+    childrenList: children || 'children'
+  };
+
+  var childrenListMap = {};
+  var nodeIds = {};
+  var tree = [];
+
+  for (let d of data) {
+    let parentId = d[config.parentId];
+    if (childrenListMap[parentId] == null) {
+      childrenListMap[parentId] = [];
+    }
+    nodeIds[d[config.id]] = d;
+    childrenListMap[parentId].push(d);
+  }
+
+  for (let d of data) {
+    let parentId = d[config.parentId];
+    if (nodeIds[parentId] == null) {
+      tree.push(d);
+    }
+  }
+
+  for (let t of tree) {
+    adaptToChildrenList(t);
+  }
+
+  function adaptToChildrenList(o) {
+    if (childrenListMap[o[config.id]] !== null) {
+      o[config.childrenList] = childrenListMap[o[config.id]];
+    }
+    if (o[config.childrenList]) {
+      for (let c of o[config.childrenList]) {
+        adaptToChildrenList(c);
+      }
+    }
+  }
+  return tree;
+}

+ 3 - 3
src/views/module_interLock/InterlockSummary/InterlockSummaryList.vue

@@ -203,9 +203,9 @@
             title:'回路健康级别',
             align:"center",
             dataIndex: 'loopHealthLevel',
-            customRender:function (t,r,index) {
-              return {children: t,attrs: {rowSpan:r.rowSpan3}};
-            },
+            // customRender:function (t,r,index) {
+            //   return {children: t,attrs: {rowSpan:r.rowSpan3}};
+            // },
           },
           {
             title:'旁路状态',