feat: add vue3(element-plus)

This commit is contained in:
xingyu
2022-07-18 19:06:37 +08:00
parent c6b58dca52
commit 80a3ae8d74
423 changed files with 41039 additions and 0 deletions

View File

@ -0,0 +1,56 @@
import { store } from '../index'
import { defineStore } from 'pinia'
import { getInfoApi } from '@/api/login'
import { getAccessToken } from '@/utils/auth'
import { useCache } from '@/hooks/web/useCache'
interface UserInfoVO {
permissions: []
roles: []
user: {
avatar: string
id: number
nickname: string
}
}
const { wsCache } = useCache()
export const useUserStore = defineStore({
id: 'admin-user',
state: (): UserInfoVO => ({
permissions: [],
roles: [],
user: {
id: 0,
avatar: '',
nickname: ''
}
}),
actions: {
// TODO 设置store刷新页面就消失
async getUserInfoAction() {
if (!getAccessToken()) {
this.resetState()
return null
}
const res = await getInfoApi()
this.permissions = res.permissions
this.roles = res.roles
this.user = res.user
wsCache.set('user', res)
},
resetState() {
this.permissions = []
this.roles = []
this.user = {
id: 0,
avatar: '',
nickname: ''
}
}
}
})
export const useUserStoreWithOut = () => {
return useUserStore(store)
}