From 344b3c188b059bc857cc594c75ef5527d8a7aeaf Mon Sep 17 00:00:00 2001 From: yinbangzhong <zhongbangyin@126.com> Date: 星期六, 17 八月 2024 20:42:59 +0800 Subject: [PATCH] 添加校验 --- src/views/authority/role/index.vue | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/views/authority/role/index.vue b/src/views/authority/role/index.vue index 48ceba2..ab8fd8a 100644 --- a/src/views/authority/role/index.vue +++ b/src/views/authority/role/index.vue @@ -148,7 +148,6 @@ title: 'menuName', children: 'children', }" - :check-strictly="checkStrictlyMenu" > </a-tree> </a-tab-pane> @@ -214,7 +213,7 @@ 'margin': '1px', }" class="card-demo" - title="鐢ㄦ埛鎵�鏈夋潈闄�" + title="瑙掕壊鎵�鏈夋潈闄�" hoverable > <a-space wrap> @@ -336,18 +335,51 @@ let resourcevisible = ref(false); let selectRole = ref({}); + + const eachChildrenAdd=(node)=>{ + if (node.children?.length > 0) { + node.children.forEach((child) => { + checkStrictlyMenu.value.push({ menuId: child.menuId, menuName: child.menuName }); + eachChildrenAdd(child); + }); + } + } + + const findChild = (node, val): boolean => { + let isExist = false; + if (node.children?.length > 0) { + node.children.forEach((child) => { + if (val.menuId == child.menuId) { + isExist = isExist || true; + } else { + isExist = isExist || findChild(child, val); + } + }); + } + return isExist; + }; + const onCheckMenu = (newCheckedKeys, event) => { let o = { menuId: event.node.menuId, menuName: event.node.menuName }; if (event.checked) { checkStrictlyMenu.value.push(o); + eachChildrenAdd(event.node); + if (event.halfCheckedNodes?.length > 0) { + event.halfCheckedNodes.forEach((child) => { + let e = { menuId: child.menuId, menuName: child.menuName }; + if (checkStrictlyMenu.value.find((item) => item.menuId === e.menuId) == undefined) { + checkStrictlyMenu.value.push(e); + } + }); + } } else { + let menus=[]; checkStrictlyMenu.value.forEach((val, idx, array) => { - // val: 褰撳墠鍊� - if (val.menuId == event.node.menuId) { - checkStrictlyMenu.value.splice(idx, 1); - return true; + if (val.menuId != event.node.menuId && !findChild(event.node, val)) { + menus.push({ menuId: val.menuId, menuName: val.menuName }); } }); + checkStrictlyMenu.value = menus; } }; const onCheckKnowledge = (newCheckedKeys, event) => { @@ -402,9 +434,7 @@ } }; - const handleRemove = (key) => { - checkStrictly.value = checkStrictly.value.filter((tag) => tag !== key); - }; + const handleMenuRemove = (key) => { checkStrictlyMenu.value = checkStrictlyMenu.value.filter( (tag) => tag !== key -- Gitblit v1.8.0