Files
front-pc/stores/permissions.ts
2025-08-26 16:25:58 +08:00

61 lines
1.9 KiB
TypeScript

import { defineStore } from 'pinia'
// import { getPermissions } from '~/api/common'
import type { IPermissions } from '~/api/common/types'
// type TPayload = {
// menuId: string
// fullPath: string
// }
export default defineStore('usePermissionStore', {
state() {
return {
// menuPermission 作为Key
permissionKeysMap: new Map<string, IPermissions>(),
// 路由作为Key 用作缓存
permissionRouteMap: new Map<string, IPermissions>(),
// 菜单权限原值
permissions: [],
}
},
actions: {
SET_PERMISSIONS(payload: { list: IPermissions[]; fullPath: string }) {
if (payload && Array.isArray(payload.list) && payload.fullPath) {
const btnsMap = new Map()
const permissionRouteMap = new Map()
payload.list.forEach((item) => {
btnsMap.set(item.menuPermission, item)
})
permissionRouteMap.set(payload.fullPath, payload.list)
this.permissionKeysMap = btnsMap
this.permissionRouteMap = permissionRouteMap
this.permissions = payload.list as never[]
}
},
// fetchPermissions(payload: TPayload) {
// return new Promise(async (resolve) => {
// const permissions: {
// fullPath: string
// menuId: string
// list: IPermissions[]
// } = {
// menuId: '',
// fullPath: payload.fullPath,
// list: [],
// }
// try {
// const res = await getPermissions({
// menuId: payload.menuId,
// })
// if ((res.statusCode === '00000' || res.code === 0) && res.data && Array.isArray(res.data)) {
// permissions.list = res.data
// }
// } catch (error) {
// permissions.list = []
// }
// this.SET_PERMISSIONS(permissions)
// resolve(true)
// })
// },
},
})