Update store paths and add persistence plugin
This commit is contained in:
60
stores/permissions.ts
Normal file
60
stores/permissions.ts
Normal file
@ -0,0 +1,60 @@
|
||||
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)
|
||||
// })
|
||||
// },
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user