From 1460ebcdbbd978b62103008bf27cf27c3b433961 Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Wed, 22 Feb 2023 15:51:13 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 1 - src/store/menu.ts | 64 ++++++++++++++++++++++----------------------- src/utils/comm.ts | 28 +------------------- src/utils/menu.ts | 2 +- 4 files changed, 33 insertions(+), 62 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index d4060c2a..9290694b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -24,7 +24,6 @@ router.beforeEach((to, from, next) => { const userInfo = useUserInfo() const system = useSystem() const menu = useMenuStore() - if (!menu.siderMenus.length) { userInfo.getUserInfo().then(() => { system.getSystemVersion().then((menuData: any[]) => { diff --git a/src/store/menu.ts b/src/store/menu.ts index cd22033f..87937da4 100644 --- a/src/store/menu.ts +++ b/src/store/menu.ts @@ -36,54 +36,52 @@ type MenuStateType = { siderMenus: MenuItem[] } -// export const useMenusStore = defineStore('menu', () => { -// const state = reactive({ -// menus: {}, -// siderMenus: [] -// }) -// -// const hasPermission = (code: string | string[]) => { -// if (!code || !(code as string[]).length) { -// console.warn(`function hasPermission: 没有传入${code}`) -// return false -// } -// -// } -// -// const queryMenuTree = (): Promise => { -// -// } -// -// return { -// state, -// hasPermission, -// queryMenuTree -// } -// }) export const useMenuStore = defineStore({ id: 'menu', - state: () => ({ + state: (): MenuStateType => ({ menus: {}, siderMenus: [] }), getters: { hasPermission(state) { - return (menuCode: string | string[]) => { - if (!menuCode) { + return (code: string | string[]) => { + if (!code) { return true } if (!!Object.keys(state.menus).length) { - if (typeof menuCode === 'string') { - return !!this.menus[menuCode].buttons + let codes: string[] = [] + + if (typeof code === 'string') { + codes.push(code) + } else { + codes = code } - return menuCode.some(code => !!this.menus[code]) + + return codes.some(_c => { + const menu_code = _c.split(':') + if (menu_code.length > 1) { + return !!this.menus[menu_code[0]]?.buttons?.includes(menu_code[1]) + } + return false + }) } return false } } }, actions: { + hasMenu(code: string) { + return this.menus[code]?.path + }, + jumpPage(code: string, params: Record, query: Record) { + const path = this.menus[code]?.path + if (path) { + router.push({ + path, params, query + }) + } + }, queryMenuTree(isCommunity = false): Promise { return new Promise(async (res) => { //过滤非集成的菜单 @@ -94,11 +92,11 @@ export const useMenuStore = defineStore({ const handleMenuItem = (menu: any) => { if (isArray(menu)) { menu.forEach(menuItem => { - this.menus[menuItem.code] = { + this.menus[menuItem.name] = { path: menuItem.path, - buttons: menuItem.buttons + buttons: menuItem.meta.buttons } - if (menuItem.children && menuItem.length) { + if (menuItem.children && menuItem.children.length) { handleMenuItem(menuItem.children) } }) diff --git a/src/utils/comm.ts b/src/utils/comm.ts index 37552e9b..26d09dd9 100644 --- a/src/utils/comm.ts +++ b/src/utils/comm.ts @@ -95,30 +95,4 @@ export const modifySearchColumnValue = (e: any, column: object) => { }); }); return e; -}; - -// /** -// * 根据code返回对应的菜单path -// * @param code 菜单code -// */ -// export const getMenu = (code: string): string | undefined => { -// const menuStore = useMenuStore() -// return menuStore.menus[code]?.path -// } -// -// /** -// * 根据菜单code跳转对应路由 -// * @param code 菜单code -// * @param params 路由params参数 -// * @param query 路由query参数 -// */ -// export const jumpPath = (code: string, params?: any, query?: any) => { -// const path = getMenu(code) -// if (path) { -// router.push({ -// path, params, query -// }) -// } else { -// console.warn(`menus中没有${code}`) -// } -// } \ No newline at end of file +}; \ No newline at end of file diff --git a/src/utils/menu.ts b/src/utils/menu.ts index d84be2d0..98332b79 100644 --- a/src/utils/menu.ts +++ b/src/utils/menu.ts @@ -178,7 +178,7 @@ const findDetailRouteItem = (code: string, url: string): Partial | nul const detailComponent = resolveComponent(`${code}/Detail`) if (detailComponent) { return { - url: `${url}/Detail/:id`, + url: `${url}/detail/:id`, code: `${code}/Detail`, component: detailComponent, name: '详情信息',