Browse Source

权限管理自动选中隐藏的条目

gr 2 years ago
parent
commit
c35fa65c04
1 changed files with 23 additions and 0 deletions
  1. 23 0
      src/views/userManage/AuthManageEdit.vue

+ 23 - 0
src/views/userManage/AuthManageEdit.vue

@@ -25,6 +25,7 @@
               :default-expanded-keys="defaultExpand[index]"
               :ref="'tree-'+index"
               :filter-node-method="filterNode"
+              @check-change="(node, isCheck, isChildCheck) => handleCheckChange(index ,node, isCheck, isChildCheck)"
               show-checkbox>
             </el-tree>
           </el-col>
@@ -63,6 +64,28 @@
       }
     },
     methods: {
+      handleCheckChange(index, node, isCheck, isChildCheck) {
+        if(node.data) { return }
+        let parent = this.$refs[`tree-${index}`][0].getNode(node.parentId)
+        if(isCheck) {
+          parent.childNodes.forEach(i => {
+            if(i.data.isShow == 0) {
+              this.$refs[`tree-${index}`][0].setChecked(i.data.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
+            }
+          })
+          if(flag) {
+            this.$refs[`tree-${index}`][0].setChecked(node.parentId, false, true)
+          }
+        }
+      },
       filterNode(value, data, node) {   // 隐藏 isShow=0 的节点
         return +data.isShow===1
       },