| | |
| | | import { getToken, setToken, removeToken } from '@/utils/auth' |
| | | import { isHttp, isEmpty } from "@/utils/validate" |
| | | import defAva from '@/assets/images/profile.jpg' |
| | | import {userListAll} from '@/api/publicApi/index.js' |
| | | |
| | | const useUserStore = defineStore( |
| | | 'user', |
| | |
| | | nickName: '', |
| | | avatar: '', |
| | | roles: [], |
| | | permissions: [] |
| | | permissions: [], |
| | | userList: [] |
| | | }), |
| | | actions: { |
| | | // 登录 |
| | |
| | | reject(error) |
| | | }) |
| | | }) |
| | | }, |
| | | |
| | | // 获取用户列表(如果已缓存则直接返回,否则重新获取) |
| | | async getUserList () { |
| | | if (Array.isArray(this.userList) && this.userList.length > 0) { |
| | | return this.userList; |
| | | } |
| | | // 为空时重新获取 |
| | | return userListAll().then(res => { |
| | | this.userList = res.data; |
| | | return this.userList; |
| | | }).catch(error => { |
| | | throw error; |
| | | }); |
| | | } |
| | | } |
| | | }) |