Przeglądaj źródła

Merge branch 'master' of http://120.26.64.82:3000/BFFE/Foshan4A4.0

zhaoke 3 lat temu
rodzic
commit
28d3dda028

+ 6 - 0
src/store/modules/user.js

@@ -111,6 +111,12 @@ const actions = {
         sessionStorage.removeItem("User_Id");
         sessionStorage.removeItem("token");
         sessionStorage.removeItem("userAuthList");
+        sessionStorage.removeItem('authExpandedKeys')
+        sessionStorage.removeItem('authCurrentKey')
+        sessionStorage.removeItem('accountGroupExpandedKeys')
+        sessionStorage.removeItem('accountGroupCurrentKey')
+        sessionStorage.removeItem('orgExpandedKeys')
+        sessionStorage.removeItem('orgCurrentKey')
         removeToken(); // must remove  token  first
         removeToken('codeToken');
         removeToken('systemSet');

+ 2 - 2
src/utils/validate.js

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-12-13 09:43:22
- * @LastEditTime: 2022-03-17 09:41:18
+ * @LastEditTime: 2022-03-23 10:05:02
  * @LastEditors: your name
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: \Foshan4A2.0\src\utils\validate.js
@@ -321,5 +321,5 @@ export function lengthValidator(rule, value, callback) {
 export const regular = {
   integer: /^[0-9]*$/,
   name: /^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$/,
-  nameMessage: '只能包含中文、英文、数字和下划线不能以下划线开头'
+  nameMessage: '只能包含中文、英文、数字和下划线不能以下划线开头'
 }

+ 96 - 78
src/views/accountGroupManagement/components/accountGroupHome.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2022-01-08 09:27:43
- * @LastEditTime: 2022-03-21 03:17:37
+ * @LastEditTime: 2022-03-23 16:00:26
  * @LastEditors: your name
  * @Description: 用户组管理
  * @FilePath: \Foshan4A2.0\src\views\accountGroupManagement\components\home.vue
@@ -21,7 +21,7 @@
           <div class="grid-content">
             <div class="title">{{ accountGroupType }}树</div>
             <div class="contentTree">
-              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="GroupId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" :current-node-key="currentKey" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
+              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="GroupId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
               </el-tree>
             </div>
           </div>
@@ -91,7 +91,7 @@
               <el-empty :image-size="150" v-if="childrenData.length < 1"></el-empty>
               <el-row :gutter="24">
                 <el-col :span="6" v-for="(data, index) in childrenData" :key="data.GroupId">
-                  <div v-is="['grouptree_btn_del_group']" class="info-close" @click="onNodeClick(data, index)">
+                  <div v-is="['grouptree_btn_del_group']" class="info-close" @click="onNodeClick(data)">
                     <i class="el-icon-close"></i>
                   </div>
                   <div class="itemBox" @click.stop="childrenClick(data)">
@@ -202,6 +202,7 @@ export default {
       title: '', // 弹框title
       flag: false, // 弹框开关
       dataId: null, // tree数据id
+      dataUpId: null,
       defaultProps: {
         children: 'children',
         label: 'GroupName'
@@ -209,14 +210,14 @@ export default {
       currDataArr: [],
       childrenData: [],
       dataListTree: [],
-      currentKey: -1,
+      currentKey: null,
       expandedKeys: [-1],
-      delIndex: 0
+      initCurrentKeyStep: [false, false]
     }
   },
   created () {
     let keyWords = ''
-    const treeEx = sessionStorage.getItem('accountTreeDatas');
+    const treeEx = sessionStorage.getItem('accountGroupExpandedKeys');
     if (this.$route.query.keyWords) {
       keyWords = this.$route.query.keyWords
     }
@@ -226,9 +227,7 @@ export default {
     this.getGroupTree(keyWords)
   },
   mounted () {
-    setTimeout(() => {
-      this.$refs.tree.setCurrentKey(this.expandedKeys[this.expandedKeys.length - 1]);
-    }, 500);
+    this.initCurrentKeyStep.splice(1, 1, true)
   },
   watch: {
     dataList: {
@@ -240,13 +239,66 @@ export default {
     },
     currentKey: {
       handler (val) {
+        if (typeof val !== 'number') {
+          return
+        }
         this.$nextTick(() => {
           this.$refs.tree.setCurrentKey(val)
+          sessionStorage.setItem('accountGroupCurrentKey', val)
+          this.setCards()
         })
       }
+    },
+    expandedKeys: {
+      handler(arr) {
+        sessionStorage.setItem('accountGroupExpandedKeys', JSON.stringify(arr))
+      },
+      deep: true
+    },
+    initCurrentKeyStep: {
+      handler(arr) {
+        if (arr.every(item => item)) {
+          this.currentKey = parseInt(sessionStorage.getItem('accountGroupCurrentKey') ?? -1)
+        }
+      },
+      deep: true
     }
   },
   methods: {
+    // 树点击
+    handleNodeClick (data) {
+      this.currentKey = data.GroupId
+    },
+    // 下级卡片点击
+    childrenClick (data) {
+      this.currentKey = data.GroupId
+      if (!this.expandedKeys.includes(this.currentKey)) {
+        this.expandedKeys.push(this.currentKey)
+      }
+    },
+    // 根据选中节点获取卡片
+    setCards() {
+      this.currDataArr = this.decompose(this.dataArr, "GroupId", this.currentKey);
+      this.childrenData = this.decompose(this.dataArr, "GroupUpid", this.currentKey);
+    },
+    // 节点展开
+    handleExpand (obj) {
+      this.expandedKeys.push(obj.GroupId)
+    },
+    // 节点收起
+    handleCollapse (obj) {
+      const { GroupId, children } = obj
+      children.length && this.collapseChilren(children)
+      this.expandedKeys = this.expandedKeys.filter(key => key !== GroupId)
+    },
+    // 收起子节点
+    collapseChilren (children) {
+      children.forEach(child => {
+        const { GroupId, children } = child
+        children.length && this.collapseChilren(children)
+        this.expandedKeys = this.expandedKeys.filter(key => key !== GroupId)
+      })
+    },
     filterNode (value, data) {
       if (!value) return true
       return data.GroupName.indexOf(value) !== -1
@@ -271,12 +323,14 @@ export default {
     },
     // 切换状态
     renderChange (data) {
-      const { GroupId, flag } = data
+      const { GroupId, flag, GroupUpid } = data
+      this.dataUpId = GroupUpid
       this.handleChange(GroupId, flag)
     },
     // 下级切换状态
-    async childrenRenderChange (data, index) {
-      const { GroupId, flag } = data
+    childrenRenderChange (data, index) {
+      const { GroupId, flag, GroupUpid } = data
+      this.dataUpId = GroupUpid
       const isChildren = true
       this.handleChange(GroupId, flag, index, isChildren)
       // try {
@@ -334,10 +388,10 @@ export default {
       this.getGroupTree()
     },
     // 节点关闭按钮点击
-    onNodeClick (data, index) {
-      this.delIndex = index
+    onNodeClick (data) {
       this.flag = true
       this.dataId = data.GroupId
+      this.dataUpId = data.GroupUpid
       this.title = data.GroupName
     },
     // 获取指定数据
@@ -372,25 +426,28 @@ export default {
         })
         if (res.code === 0) {
           this.$message.success(res.message)
-          if (!isChildren) {
-            this.currDataArr[0].Status = Status
-          } else {
-            this.childrenData[index].Status = Status
-          }
-          this.dataArr.find(data => {
-            if (data.GroupId === id) {
-              data.Status = Status
-              data.flag = flag
-              return true
-            }
-          })
-          if (!isChildren) {
-            this.childrenData.forEach(data => {
-              data.Status = Status
-              data.flag = flag
-            })
-          }
-          this.setChildrenStatus(id, flag)
+          // if (!isChildren) {
+          //   this.currDataArr[0].Status = Status
+          // } else {
+          //   this.childrenData[index].Status = Status
+          // }
+          // this.dataArr.find(data => {
+          //   if (data.GroupId === id) {
+          //     data.Status = Status
+          //     data.flag = flag
+          //     return true
+          //   }
+          // })
+          // if (!isChildren) {
+          //   this.childrenData.forEach(data => {
+          //     data.Status = Status
+          //     data.flag = flag
+          //   })
+          // }
+          // this.setChildrenStatus(id, flag)
+          this.initCurrentKeyStep.splice(0, 1, false)
+          this.currentKey = null
+          this.getGroupTree()
         } else {
           this.$message.error(res.message)
           if (!isChildren) {
@@ -407,9 +464,6 @@ export default {
           this.childrenData[index].flag = !flag
         }
       }
-      this.$nextTick(() => {
-        this.$refs.tree.setCurrentKey(this.currentKey)
-      })
     },
     // 删除
     async deleteOrg (id) {
@@ -420,8 +474,13 @@ export default {
         if (res.code === 0) {
           this.$message.success(res.message)
           this.flag = false
+          this.initCurrentKeyStep.splice(0, 1, false)
+          if (this.currentKey === id) {
+            sessionStorage.setItem('accountGroupCurrentKey', this.dataUpId)
+          } else {
+            this.currentKey = null
+          }
           this.getGroupTree()
-          this.childrenData.splice(this.delIndex, 1)
         } else {
           this.flag = false
           this.$message.error(res.message)
@@ -431,47 +490,6 @@ export default {
         console.log('DeleteGroup')
         console.log('error')
       }
-    },
-    // 树点击
-    handleNodeClick (data) {
-      const dataNew = _.cloneDeep(data)
-      this.currentKey = dataNew.GroupId
-      this.currDataArr = []
-      this.childrenData = []
-      this.currDataArr = this.decompose(this.dataArr, 'GroupId', this.currentKey)
-      this.childrenData = this.decompose(this.dataArr, 'GroupUpid', this.currentKey)
-    },
-    // 下级卡片点击
-    childrenClick (data) {
-      const dataNew = _.cloneDeep(data)
-      this.currentKey = dataNew.GroupId
-      this.currDataArr = []
-      this.childrenData = []
-      this.currDataArr = this.decompose(this.dataArr, 'GroupId', this.currentKey)
-      this.childrenData = this.decompose(this.dataArr, 'GroupUpid', this.currentKey)
-      if (!this.expandedKeys.includes(this.currentKey)) {
-        this.expandedKeys.push(this.currentKey)
-      }
-    },
-    // 节点展开
-    handleExpand (obj) {
-      this.expandedKeys.push(obj.GroupId)
-      sessionStorage.setItem('accountTreeDatas', JSON.stringify(this.expandedKeys))
-    },
-    // 节点收起
-    handleCollapse (obj) {
-      const { GroupId, children } = obj
-      children.length && this.collapseChilren(children)
-      this.expandedKeys = this.expandedKeys.filter(key => key !== GroupId)
-      sessionStorage.setItem('accountTreeDatas', JSON.stringify(this.expandedKeys))
-    },
-    // 收起子节点
-    collapseChilren (children) {
-      children.forEach(child => {
-        const { GroupId, children } = child
-        children.length && this.collapseChilren(children)
-        this.expandedKeys = this.expandedKeys.filter(key => key !== GroupId)
-      })
     }
   }
 }

+ 6 - 10
src/views/accountGroupManagement/mixins/treeData.js

@@ -1,10 +1,9 @@
 /*
  * @Author: your name
  * @Date: 2021-12-22 17:00:22
- * @LastEditTime: 2022-03-21 03:27:01
+ * @LastEditTime: 2022-03-23 15:22:31
  * @LastEditors: your name
- * @Description: 获取权限树
- * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\treeData.js
+ * @Description: 获取用户组树
  */
 import { translateDataToTreeAll } from '@/utils/validate'
 import { GetGroupTree } from '@/api/AccountGroup'
@@ -72,17 +71,14 @@ export default {
           }
           this.dataList = obj
           this.dataArr.push(obj)
+          typeof this.currentKey !== 'undefined' && sessionStorage.setItem('accountGroupCurrentKey', -1)
         }
-        this.currDataArr = this.decompose(this.dataArr, 'GroupId', this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, 'GroupUpid', this.currentKey)
+        this.initCurrentKeyStep?.splice(0, 1, true)
       } catch (error) {
         console.log('出错了', error)
-        this.currDataArr = this.decompose(this.dataArr, 'GroupId', this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, 'GroupUpid', this.currentKey)
+        typeof this.currentKey !== 'undefined' && sessionStorage.setItem('accountGroupCurrentKey', -1)
+        this.initCurrentKeyStep?.splice(0, 1, true)
       }
-      this.$nextTick(() => {
-        this.$refs.tree?.setCurrentKey(this.currentKey)
-      })
     }
   }
 }

+ 83 - 56
src/views/authorityManagement/components/authorityHome.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-11-29 09:27:43
- * @LastEditTime: 2022-03-21 03:21:52
+ * @LastEditTime: 2022-03-23 15:59:27
  * @LastEditors: your name
  * @Description: 权限管理
  * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\home.vue
@@ -27,7 +27,7 @@
           <div class="grid-content">
             <div class="title">权限树</div>
             <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" class="contentTree">
-              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="AuthId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" :current-node-key="currentKey" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
+              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="AuthId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
               </el-tree>
             </div>
           </div>
@@ -38,7 +38,7 @@
             <div class="content">
               <template v-if="currDataArr.length">
                 <el-row>
-                  <el-col :span="6" v-for="(data,index) in currDataArr" :key="data.AuthId">
+                  <el-col :span="6" v-for="data in currDataArr" :key="data.AuthId">
                     <div class="account-left-content-teams">
                       <div class="team">
                         <div class="bg" :class="data.Type == 1 || data.Type == 0 ? 'status1' : 'status2'"></div>
@@ -66,7 +66,7 @@
                           <div v-if="data.Type > 0" class="flex details">
                             <div class="details-msg">状态:<span :class="data.Status === 1 ? 'success' : 'error'">{{data.Status === 1 ? '启用' : '禁用'}}</span></div>
                             <div v-is="['authtree_btn_state_swatch']" class="details-info">
-                              <el-switch v-model="data.flag" @change="renderChange(data,index)" active-color="#6F81BC">
+                              <el-switch v-model="data.flag" @change="renderChange(data)" active-color="#6F81BC">
                               </el-switch>
                             </div>
                           </div>
@@ -178,6 +178,7 @@ export default {
       title: '', //弹框title
       flag: false, //弹框开关
       dataId: null, //tree数据id
+      dataUpId: null,
       currDataArr: [],
       childrenData: [],
       dataListTree: [],
@@ -185,13 +186,14 @@ export default {
         children: "children",
         label: "AuthName",
       },
-      currentKey: -1,
-      expandedKeys: [-1]
+      currentKey: null,
+      expandedKeys: [-1],
+      initCurrentKeyStep: [false, false]
     }
   },
   created () {
     let keyWords = "";
-    const treeEx = sessionStorage.getItem('authTreeDatas');
+    const treeEx = sessionStorage.getItem('authExpandedKeys');
     if (this.$route.query.keyWords) {
       keyWords = this.$route.query.keyWords;
     }
@@ -201,9 +203,7 @@ export default {
     this.getAuthTree(keyWords);
   },
   mounted () {
-    setTimeout(() => {
-      this.$refs.tree.setCurrentKey(this.expandedKeys[this.expandedKeys.length - 1]);
-    }, 500);
+    this.initCurrentKeyStep.splice(1, 1, true)
   },
   watch: {
     dataList: {
@@ -215,45 +215,58 @@ export default {
     },
     currentKey: {
       handler (val) {
+        if (typeof val !== 'number') {
+          return
+        }
         this.$nextTick(() => {
           this.$refs.tree.setCurrentKey(val)
+          sessionStorage.setItem('authCurrentKey', val)
+          this.setCards()
         })
       }
+    },
+    expandedKeys: {
+      handler(arr) {
+        sessionStorage.setItem('authExpandedKeys', JSON.stringify(arr))
+      },
+      deep: true
+    },
+    initCurrentKeyStep: {
+      handler(arr) {
+        if (arr.every(item => item)) {
+          this.currentKey = parseInt(sessionStorage.getItem('authCurrentKey') ?? -1)
+        }
+      },
+      deep: true
     }
   },
   methods: {
     //树点击
     handleNodeClick (data) {
-      const dataNew = _.cloneDeep(data)
-      this.currentKey = dataNew.AuthId
-      this.currDataArr = [];
-      this.childrenData = [];
-      this.currDataArr = this.decompose(this.dataArr, "AuthId", this.currentKey);
-      this.childrenData = this.decompose(this.dataArr, "UpAuthId", this.currentKey);
+      this.currentKey = data.AuthId
     },
     //下级卡片点击
     childrenClick (data) {
-      const dataNew = _.cloneDeep(data)
-      this.currentKey = dataNew.AuthId
-      this.currDataArr = [];
-      this.childrenData = [];
-      this.currDataArr = this.decompose(this.dataArr, "AuthId", this.currentKey);
-      this.childrenData = this.decompose(this.dataArr, "UpAuthId", this.currentKey);
+      this.currentKey = data.AuthId
       if (!this.expandedKeys.includes(this.currentKey)) {
         this.expandedKeys.push(this.currentKey)
       }
+      // this.setCards()
+    },
+    // 根据选中节点获取卡片
+    setCards() {
+      this.currDataArr = this.decompose(this.dataArr, "AuthId", this.currentKey);
+      this.childrenData = this.decompose(this.dataArr, "UpAuthId", this.currentKey);
     },
     // 节点展开
     handleExpand (obj) {
       this.expandedKeys.push(obj.AuthId)
-      sessionStorage.setItem('authTreeDatas', JSON.stringify(this.expandedKeys))
     },
     // 节点收起
     handleCollapse (obj) {
       const { AuthId, children } = obj
       children.length && this.collapseChilren(children)
       this.expandedKeys = this.expandedKeys.filter(key => key !== AuthId)
-      sessionStorage.setItem('authTreeDatas', JSON.stringify(this.expandedKeys))
     },
     // 收起子节点
     collapseChilren (children) {
@@ -265,7 +278,8 @@ export default {
     },
     //下级切换状态
     childrenRenderChange (data, index) {
-      const { AuthId, flag, Type } = data
+      const { AuthId, flag, Type, UpAuthId } = data
+      this.dataUpId = UpAuthId
       const isChildren = true
       this.handleChange(AuthId, flag, Type, index, isChildren)
     },
@@ -290,9 +304,10 @@ export default {
       this.$router.push({ path: '/authority/addPower', query: { AuthId: data.AuthId, Status: data.Status, UpAuthId: data.UpAuthId } })
     },
     // 关闭开启
-    renderChange (data, index) {
-      const { AuthId, flag, Type } = data
-      this.handleChange(AuthId, flag, Type, index)
+    renderChange (data) {
+      const { AuthId, flag, Type, UpAuthId } = data
+      this.dataUpId = UpAuthId
+      this.handleChange(AuthId, flag, Type)
     },
     //删除
     remove () {
@@ -321,6 +336,7 @@ export default {
     onNodeClick (data) {
       this.flag = true
       this.dataId = data.AuthId
+      this.dataUpId = data.UpAuthId
       this.title = data.AuthName
       this.type = data.Type
     },
@@ -379,7 +395,7 @@ export default {
     // },
     //-----------获取数据------------
     //应用状态变更
-    async handleChange (id, flag, type, index, isChildren = false) {
+    async handleChange (id, flag, type, index = 0, isChildren = false) {
       const Status = flag ? 1 : 0
       try {
         let res = null
@@ -396,32 +412,34 @@ export default {
         }
         if (res.code === 0) {
           this.$message.success(res.message)
-          if (!isChildren) {
-            this.currDataArr[0].Status = Status
-          } else {
-            this.childrenData[index].Status = Status
-          }
-          this.dataArr.find(data => {
-            if (data.AuthId === id) {
-              data.Status = Status
-              data.flag = flag
-              return true
-            }
-          })
-          if (type !== 1) {
-            if (!isChildren) {
-              this.childrenData.forEach(data => {
-                data.Status = Status
-                data.flag = flag
-              })
-            }
-            this.setChildrenStatus(id, flag)
-          }
-          //this.getAuthTree()
+          // if (!isChildren) {
+          //   this.currDataArr[0].Status = Status
+          // } else {
+          //   this.childrenData[index].Status = Status
+          // }
+          // this.dataArr.find(data => {
+          //   if (data.AuthId === id) {
+          //     data.Status = Status
+          //     data.flag = flag
+          //     return true
+          //   }
+          // })
+          // if (type !== 1) {
+          //   if (!isChildren) {
+          //     this.childrenData.forEach(data => {
+          //       data.Status = Status
+          //       data.flag = flag
+          //     })
+          //   }
+          //   this.setChildrenStatus(id, flag)
+          // }
+          this.initCurrentKeyStep.splice(0, 1, false)
+          this.currentKey = null
+          this.getAuthTree()
         } else {
           this.$message.error(res.message)
           if (!isChildren) {
-            this.currDataArr[0].flag = !flag;
+            this.currDataArr[index].flag = !flag;
           } else {
             this.childrenData[index].flag = !flag;
           }
@@ -429,14 +447,11 @@ export default {
       } catch (error) {
         console.log('出错了', error)
         if (!isChildren) {
-          this.currDataArr[0].flag = !flag;
+          this.currDataArr[index].flag = !flag;
         } else {
           this.childrenData[index].flag = !flag;
         }
       }
-      this.$nextTick(() => {
-        this.$refs.tree.setCurrentKey(this.currentKey)
-      })
     },
     //应用删除
     async deleteApp (id) {
@@ -447,6 +462,12 @@ export default {
         if (res.code === 0) {
           this.$message.success(res.message)
           this.flag = false
+          this.initCurrentKeyStep.splice(0, 1, false)
+          if (this.currentKey === id) {
+            sessionStorage.setItem('authCurrentKey', this.dataUpId)
+          } else {
+            this.currentKey = null
+          }
           this.getAuthTree()
         } else {
           this.flag = false
@@ -465,6 +486,12 @@ export default {
         if (res.code === 0) {
           this.$message.success(res.message || '成功')
           this.flag = false
+          this.initCurrentKeyStep.splice(0, 1, false)
+          if (this.currentKey === id) {
+            sessionStorage.setItem('authCurrentKey', this.dataUpId)
+          } else {
+            this.currentKey = null
+          }
           this.getAuthTree()
         } else {
           this.flag = false

+ 8 - 11
src/views/authorityManagement/minixs/treeData.js

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-12-22 17:00:22
- * @LastEditTime: 2022-03-21 03:26:52
+ * @LastEditTime: 2022-03-23 15:19:36
  * @LastEditors: your name
  * @Description: 获取权限树
  * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\treeData.js
@@ -35,7 +35,7 @@ export default {
             AuthName: "所有权限",
             QueryTarget: 0,
             Status: 0,
-            UpAuthId: -1,
+            UpAuthId: -2,
             Type: 0,
             disabled: true,
             children: translateDataToTreeAll(result.returnData, 'UpAuthId', 'AuthId')
@@ -65,7 +65,7 @@ export default {
             children: []
           }
           this.dataList = obj
-          this.dataArr.push({
+          this.dataArr?.push({
             AuthId: -1,
             AuthName: "所有权限",
             QueryTarget: 0,
@@ -75,10 +75,10 @@ export default {
             disabled: true,
             children: []
           })
+          typeof this.currentKey !== 'undefined' && sessionStorage.setItem('authCurrentKey', -1)
         }
-        this.currDataArr = this.decompose(this.dataArr, "AuthId", this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, "UpAuthId", this.currentKey)
         this.loading = false
+        this.initCurrentKeyStep?.splice(0, 1, true)
       } catch (error) {
         const obj = {
           AuthId: -1,
@@ -91,7 +91,7 @@ export default {
           children: []
         }
         this.dataList = obj
-        this.dataArr.push({
+        this.dataArr?.push({
           AuthId: -1,
           AuthName: "所有权限",
           QueryTarget: 0,
@@ -101,13 +101,10 @@ export default {
           disabled: true,
           children: []
         })
-        this.currDataArr = this.decompose(this.dataArr, "AuthId", this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, "UpAuthId", this.currentKey)
+        typeof this.currentKey !== 'undefined' && sessionStorage.setItem('authCurrentKey', -1)
         this.loading = false
+        this.initCurrentKeyStep?.splice(0, 1, true)
       }
-      this.$nextTick(() => {
-        this.$refs.tree?.setCurrentKey(this.currentKey)
-      })
     }
   }
 }

+ 61 - 68
src/views/organizationManagement/components/organizationHome.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-11-29 09:27:43
- * @LastEditTime: 2022-03-21 03:28:09
+ * @LastEditTime: 2022-03-23 16:31:35
  * @LastEditors: your name
  * @Description: 权限管理
  * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\home.vue
@@ -24,7 +24,7 @@
           <div class="grid-content">
             <div class="title">组织树</div>
             <div class="contentTree">
-              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="OrganId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" :current-node-key="currentKey" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
+              <el-tree ref="tree" :data="dataListTree" :props="defaultProps" node-key="OrganId" :filter-node-method="filterNode" highlight-current :default-expanded-keys="expandedKeys" @node-expand="handleExpand" @node-collapse="handleCollapse" @node-click="handleNodeClick">
               </el-tree>
             </div>
           </div>
@@ -110,7 +110,7 @@
               <el-empty :image-size="150" v-if="childrenData.length<1"></el-empty>
               <el-row :gutter="24">
                 <el-col :span="8" v-for="(data, index) in childrenData" :key="data.OrganId">
-                  <div v-is="['organtree_btn_del_organ']" class="info-close" @click="onNodeClick(data,index)">
+                  <div v-is="['organtree_btn_del_organ']" class="info-close" @click="onNodeClick(data)">
                     <i class="el-icon-close"></i>
                   </div>
                   <div class="itemBox" @click.stop="childrenClick(data)">
@@ -216,6 +216,7 @@ export default {
       title: "", //弹框title
       flag: false, //弹框开关
       dataId: null, //tree数据id
+      dataUpId: null,
       defaultProps: {
         children: "children",
         label: "OrganName",
@@ -224,14 +225,14 @@ export default {
       currDataArrId: 0,
       childrenData: [],
       dataListTree: [],
-      currentKey: -1,
+      currentKey: null,
       expandedKeys: [-1],
-      delIndex: 0
+      initCurrentKeyStep: [false, false]
     };
   },
   created () {
     let keyWords = "";
-    const treeEx = sessionStorage.getItem('orgTreeDatas');
+    const treeEx = sessionStorage.getItem('orgExpandedKeys');
     if (this.$route.query.keyWords) {
       keyWords = this.$route.query.keyWords;
     }
@@ -241,9 +242,8 @@ export default {
     this.getOrganTree(keyWords);
   },
   mounted () {
-    setTimeout(() => {
-      this.$refs.tree.setCurrentKey(this.expandedKeys[this.expandedKeys.length - 1]);
-    }, 500);
+    this.initCurrentKeyStep.splice(1, 1, true)
+    
   },
   watch: {
     dataList: {
@@ -255,10 +255,29 @@ export default {
     },
     currentKey: {
       handler (val) {
+        if (typeof val !== 'number') {
+          return
+        }
         this.$nextTick(() => {
           this.$refs.tree.setCurrentKey(val)
+          sessionStorage.setItem('orgCurrentKey', val)
+          this.setCards()
         })
       }
+    },
+    expandedKeys: {
+      handler(arr) {
+        sessionStorage.setItem('orgExpandedKeys', JSON.stringify(arr))
+      },
+      deep: true
+    },
+    initCurrentKeyStep: {
+      handler(arr) {
+        if (arr.every(item => item)) {
+          this.currentKey = parseInt(sessionStorage.getItem('orgCurrentKey') ?? -1)
+        }
+      },
+      deep: true
     }
   },
   methods: {
@@ -303,31 +322,15 @@ export default {
     },
     // 关闭开启
     renderChange (data) {
-      const { OrganId, flag } = data;
+      const { OrganId, flag, OrganUpid } = data;
+      this.dataUpId = OrganUpid
       this.handleChange(OrganId, flag);
     },
     //下级关闭
     childrenRenderChange (data, index) {
-      const { OrganId, flag } = data;
-      const Status = flag ? 1 : 0;
-      try {
-        tissueTreeStart({
-          OrganId: OrganId,
-          Status: Status,
-        }).then((res) => {
-          if (res.code === 0) {
-            this.$message.success(res.message);
-            this.childrenData[index].Status = Status;
-            // this.getOrganTree();
-          } else {
-            this.$message.error(res.message);
-            this.childrenData[index].flag = !flag;
-          }
-        });
-      } catch (error) {
-        console.log("出错了", error);
-        this.childrenData[index].flag = !flag;
-      }
+      const { OrganId, flag, OrganUpid } = data;
+      this.dataUpId = OrganUpid
+      this.handleChange(OrganId, flag, index)
     },
     //删除组织
     remove () {
@@ -348,8 +351,7 @@ export default {
       this.getOrganTree();
     },
     //节点关闭按钮点击
-    onNodeClick (data, index) {
-      this.delIndex = index
+    onNodeClick (data) {
       this.flag = true;
       this.dataId = data.OrganId;
       this.title = data.OrganName;
@@ -369,7 +371,7 @@ export default {
 
     //-----------获取数据------------
     //应用状态变更
-    async handleChange (id, flag) {
+    async handleChange (id, flag, index = 0, isChildren = false) {
       const Status = flag ? 1 : 0
       try {
         const res = await tissueTreeStart({
@@ -378,15 +380,28 @@ export default {
         });
         if (res.code === 0) {
           this.$message.success(res.message);
-          this.currDataArr[0].Status = Status
-          // this.getOrganTree();
+          this.initCurrentKeyStep.splice(0, 1, false)
+          if (this.currentKey === id) {
+            sessionStorage.setItem('orgCurrentKey', this.dataUpId)
+          } else {
+            this.currentKey = null
+          }
+          this.getOrganTree()
         } else {
           this.$message.error(res.message);
-          this.currDataArr[0].flag = !flag;
+          if (!isChildren) {
+            this.currDataArr[index].flag = !flag;
+          } else {
+            this.childrenData[index].flag = !flag
+          }
         }
       } catch (error) {
         console.log("出错了", error);
-        this.currDataArr[0].flag = !flag;
+        if (!isChildren) {
+            this.currDataArr[index].flag = !flag;
+          } else {
+            this.childrenData[index].flag = !flag
+          }
       }
     },
     //组织删除
@@ -398,8 +413,9 @@ export default {
         if (res.code === 0) {
           this.$message.success(res.message);
           this.flag = false;
+          this.initCurrentKeyStep.splice(0, 1, false)
+          this.currentKey = null
           this.getOrganTree();
-          this.childrenData.splice(this.delIndex, 1);
         } else {
           this.flag = false;
           this.$message.error(res.message);
@@ -410,52 +426,29 @@ export default {
     },
     //树点击
     handleNodeClick (data) {
-      const dataNew = _.cloneDeep(data);
-      this.currentKey = dataNew.OrganId;
-      this.currDataArr = [];
-      this.childrenData = [];
-      this.currDataArr = this.decompose(
-        this.dataArr,
-        "OrganId",
-        this.currentKey
-      );
-      this.childrenData = this.decompose(
-        this.dataArr,
-        "OrganUpid",
-        this.currentKey
-      );
+      this.currentKey = data.OrganId;
     },
     //下级卡片点击
     childrenClick (data) {
-      const dataNew = _.cloneDeep(data);
-      this.currentKey = dataNew.OrganId;
-      this.currDataArr = [];
-      this.childrenData = [];
-      this.currDataArr = this.decompose(
-        this.dataArr,
-        "OrganId",
-        this.currentKey
-      );
-      this.childrenData = this.decompose(
-        this.dataArr,
-        "OrganUpid",
-        this.currentKey
-      );
+      this.currentKey = data.OrganId;
       if (!this.expandedKeys.includes(this.currentKey)) {
         this.expandedKeys.push(this.currentKey)
       }
     },
+    // 根据选中节点获取卡片
+    setCards() {
+      this.currDataArr = this.decompose(this.dataArr, "OrganId", this.currentKey);
+      this.childrenData = this.decompose(this.dataArr, "OrganUpid", this.currentKey);
+    },
     // 节点展开
     handleExpand (obj) {
       this.expandedKeys.push(obj.OrganId)
-      sessionStorage.setItem('orgTreeDatas', JSON.stringify(this.expandedKeys))
     },
     // 节点收起
     handleCollapse (obj) {
       const { OrganId, children } = obj
       children.length && this.collapseChilren(children)
       this.expandedKeys = this.expandedKeys.filter(key => key !== OrganId)
-      sessionStorage.setItem('orgTreeDatas', JSON.stringify(this.expandedKeys))
     },
     // 收起子节点
     collapseChilren (children) {

+ 7 - 12
src/views/organizationManagement/minixs/treeData.js

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-12-22 17:00:22
- * @LastEditTime: 2022-03-21 03:29:33
+ * @LastEditTime: 2022-03-23 15:52:22
  * @LastEditors: your name
  * @Description: 获取权限树
  * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\treeData.js
@@ -64,8 +64,7 @@ export default {
             QueryTarget: "0",
             Type: 0,
             disabled: true,
-          }
-          )
+          })
         } else {
           const obj = {
             AuthCount: 0,
@@ -90,19 +89,15 @@ export default {
             QueryTarget: "0",
             Type: 0,
             disabled: true,
-          }
-          )
+          })
+          typeof this.currentKey !== 'undefined' && sessionStorage.setItem('orgCurrentKey', -1)
         }
-        this.currDataArr = this.decompose(this.dataArr, 'OrganId', this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, 'OrganUpid', this.currentKey)
+        this.initCurrentKeyStep?.splice(0, 1, true)
       } catch (error) {
         console.log('出错了', error)
-        this.currDataArr = this.decompose(this.dataArr, 'OrganId', this.currentKey)
-        this.childrenData = this.decompose(this.dataArr, 'OrganUpid', this.currentKey)
+        typeof this.currentKey !== 'undefined' && sessionStorage.setItem('orgCurrentKey', -1)
+        this.initCurrentKeyStep?.splice(0, 1, true)
       }
-      this.$nextTick(() => {
-        this.$refs.tree?.setCurrentKey(this.currentKey)
-      })
     }
   }
 }