Browse Source

权限管理自动勾选半选节点隐藏项

gr 2 years ago
parent
commit
7c36a82750
1 changed files with 19 additions and 16 deletions
  1. 19 16
      src/views/userManage/AuthManageEdit.vue

+ 19 - 16
src/views/userManage/AuthManageEdit.vue

@@ -25,7 +25,7 @@
               :default-expanded-keys="defaultExpand[index]"
               :ref="'tree-'+index"
               :filter-node-method="filterNode"
-              @check-change="(node, isCheck, isChildCheck) => handleCheckChange(index ,node, isCheck, isChildCheck)"
+              @check-change="(node, isCheck, isChildCheck) => handleCheckChange(index, isCheck)"
               show-checkbox>
             </el-tree>
           </el-col>
@@ -64,26 +64,29 @@
       }
     },
     methods: {
-      handleCheckChange(index, node, isCheck, isChildCheck) {
-        if(node.data) { return }
-        let parent = this.$refs[`tree-${index}`][0].getNode(node.parentId)
+      handleCheckChange(index, isCheck) {
         if(isCheck) {
-          parent.childNodes.forEach(i => {
-            if(i.data.isShow == 0) {
-              this.$refs[`tree-${index}`][0].setChecked(i.data.authorityId, true)
-            }
+          this.$refs[`tree-${index}`][0].getHalfCheckedNodes().forEach(i => {
+            i.data.forEach(j => {
+              if(j.isShow == 0) {
+                this.$refs[`tree-${index}`][0].setChecked(j.authorityId, true)
+              }
+            })
           })
         }else {
-          let checked = this.$refs[`tree-${index}`][0].getCheckedKeys(true)
-          let flag = true
-          parent.childNodes.forEach(i => {
-            if(i.data.isShow == 1 && checked.indexOf(i.data.authorityId)!== -1) {
-              flag = false
+          let checked = this.$refs[`tree-${index}`][0].getCheckedKeys()
+          checked.push(...this.$refs[`tree-${index}`][0].getHalfCheckedKeys())
+          this.$refs[`tree-${index}`][0].getHalfCheckedNodes().forEach(i => {
+            let flag = true
+            i.data.forEach(j => {
+              if(j.isShow == 1 && checked.indexOf(j.authorityId) != -1) {
+                flag = false
+              }
+            })
+            if(flag) {
+              this.$refs[`tree-${index}`][0].setChecked(i.authorityId, false, true)
             }
           })
-          if(flag) {
-            this.$refs[`tree-${index}`][0].setChecked(node.parentId, false, true)
-          }
         }
       },
       filterNode(value, data, node) {   // 隐藏 isShow=0 的节点