mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-11-04 08:06:12 +08:00 
			
		
		
		
	refactor: vue3 axios api ...
This commit is contained in:
		@ -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 = []
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user