// PC 端 check 事件 onSelectNav(selectedKeys, info) { this.navIds = selectedKeys.checked let data = info.node.dataRef // 判断勾选的状态 let flag = info.checked let { parentId } = data this.currentNavNode = data if (flag) { // 勾选 this.setNavParentId(parentId) this.selectNavAll() } else { // 取消勾选 this.cancelSelectNavAll() } }
1 2 3 4 5 6 7 8 9 10 11 12
// 子节点反选 父节点 setNavParentId(id) { if (!id) return let { totalNavIds } = this this.navIds.push(id) let parentNode = totalNavIds.filter(item => { return item.id === id })[0] if (parentNode) { this.setNavParentId(parentNode.parentId) } }
1 2 3 4 5 6 7 8 9 10
// PC 端 针对某一节点 全选 selectNavAll() { // console.log('selectNavAll=====') let { navIds, currentNavNode } = this let { id, navList } = currentNavNode if (navIds.indexOf(id) < 0) { navIds.push(id) } this.setNavChildId(navList) },
1 2 3 4 5 6 7 8 9 10 11 12
// PC 端 针对某一节点 取消全选 cancelSelectNavAll() { // console.log('cancelSelectNavAll=====') let { navIds, currentNavNode } = this let { id, navList } = currentNavNode let index = navIds.indexOf(id) if (index >= 0) { navIds.splice(index, 1) } // 递归这个节点下面的所有子节点,并且取消选中 this.clearNasChildId(navList) }