refactor: vue3 axios api ...

This commit is contained in:
xingyu
2022-07-19 22:33:54 +08:00
parent ba96eef51a
commit 9e2e220b69
121 changed files with 1022 additions and 9700 deletions

View File

@ -1,9 +1,10 @@
import { store } from '../index'
import { defineStore } from 'pinia'
import { getInfoApi } from '@/api/login'
import { getAccessToken } from '@/utils/auth'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
interface UserInfoVO {
permissions: []
roles: []
@ -13,7 +14,6 @@ interface UserInfoVO {
nickname: string
}
}
const { wsCache } = useCache()
export const useUserStore = defineStore({
id: 'admin-user',
@ -27,16 +27,15 @@ export const useUserStore = defineStore({
}
}),
actions: {
async getUserInfoAction() {
async getUserInfoAction(userInfo: UserInfoVO) {
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)
this.permissions = userInfo.permissions
this.roles = userInfo.roles
this.user = userInfo.user
wsCache.set('user', userInfo)
},
resetState() {
this.permissions = []