feat: 增加menuStore

This commit is contained in:
wangshuaiswim 2023-01-13 11:54:33 +08:00
parent e01ab75de9
commit badecf9f64
1 changed files with 24 additions and 0 deletions

24
src/store/menu.ts Normal file
View File

@ -0,0 +1,24 @@
import { defineStore } from "pinia";
export const useMenuStore = defineStore({
id: 'menu',
state: () => ({
menus: {} as {[key: string]: string},
}),
getters: {
hasPermission(state) {
return (menuCode: string | string[]) => {
if (!menuCode) {
return true
}
if (!!Object.keys(state.menus).length) {
if (typeof menuCode === 'string') {
return !!this.menus[menuCode]
}
return menuCode.some(code => !!this.menus[code])
}
return false
}
}
}
})