From 0e7b76d5ed95e06aec9277fc41901319843093bc Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Sun, 23 Mar 2025 14:31:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E5=8B=BE=E9=80=89=E6=9D=83=E9=99=90=E7=BB=84=E4=BB=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E9=94=99=E8=AF=AF=E7=94=A8=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../src/components/tree/src/helper.tsx | 49 +++++++++++++++++++ .../components/tree/src/menu-select-table.vue | 3 +- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac3ea9ad..096232e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ **FEATURES** - 增加`环境变量`打包配置demo -> build:antd:test +- 角色管理 勾选权限组件添加对错误用法的校验提示 **REFACTOR** diff --git a/apps/web-antd/src/components/tree/src/helper.tsx b/apps/web-antd/src/components/tree/src/helper.tsx index 9ce64a21..8a4c4327 100644 --- a/apps/web-antd/src/components/tree/src/helper.tsx +++ b/apps/web-antd/src/components/tree/src/helper.tsx @@ -5,6 +5,7 @@ import type { MenuOption } from '#/api/system/menu/model'; import { eachTree, treeToList } from '@vben/utils'; +import { notification } from 'ant-design-vue'; import { difference, isEmpty, isUndefined } from 'lodash-es'; /** @@ -48,6 +49,7 @@ export function rowAndChildrenChecked( */ export function menusWithPermissions(menus: MenuOption[]) { eachTree(menus, (item: MenuPermissionOption) => { + validateMenuTree(item); if (item.children && item.children.length > 0) { /** * 所有为按钮的节点提取出来 @@ -131,3 +133,50 @@ export function setTableChecked( tableApi.grid.setCheckboxRow(emptyRows, false); } } + +/** + * 校验是否符合规范 给出warning提示 + * + * 不符合规范 + * 比如: 菜单下放目录 菜单下放菜单 + * 比如: 按钮下放目录 按钮下放菜单 按钮下放按钮 + * @param menu menu + */ +function validateMenuTree(menu: MenuOption) { + /** + * C: { icon: markRaw(MenuIcon), value: '菜单' }, + F: { icon: markRaw(OkButtonIcon), value: '按钮' }, + M: { icon: markRaw(FolderIcon), value: '目录' }, + */ + // 菜单下不能放目录/菜单 + if (menu.menuType === 'C') { + menu.children?.forEach?.((item) => { + if (['C', 'M'].includes(item.menuType)) { + const description = `错误用法: [${menu.label} - 菜单]下不能放 目录/菜单 -> [${item.label}]`; + console.warn(description); + notification.warning({ + message: '提示', + description, + duration: 0, + }); + } + }); + } + // 按钮为最末级 不能再放置 + if (menu.menuType === 'F') { + /** + * 其实可以直接判断length 这里为了更准确知道label 采用遍历的形式 + */ + menu.children?.forEach?.((item) => { + if (['C', 'F', 'M'].includes(item.menuType)) { + const description = `错误用法: [${menu.label} - 按钮]下不能放置'目录/菜单/按钮' -> [${item.label}]`; + console.warn(description); + notification.warning({ + message: '提示', + description, + duration: 0, + }); + } + }); + } +} diff --git a/apps/web-antd/src/components/tree/src/menu-select-table.vue b/apps/web-antd/src/components/tree/src/menu-select-table.vue index cccf08dd..d1dbc52f 100644 --- a/apps/web-antd/src/components/tree/src/menu-select-table.vue +++ b/apps/web-antd/src/components/tree/src/menu-select-table.vue @@ -55,8 +55,7 @@ const props = withDefaults( /** * 是否节点关联 */ -const association = defineModel('association', { - type: Boolean, +const association = defineModel('association', { default: true, });