index.ts
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { defineStore } from 'pinia';
import { clearToken } from '@/utils/auth';
import useAuthApi from '@/api/auth';
// eslint-disable-next-line import/no-cycle
import { useAppStore } from '@/store';
import { AuthorizedState } from './type';
const useAuthorizedStore = defineStore('authorized', {
state: (): AuthorizedState => ({
id: undefined,
nick_name: undefined,
real_name: undefined,
avatar: undefined,
email: undefined,
phone: undefined,
permissions: [],
}),
getters: {
authorizedInfo(state: AuthorizedState): AuthorizedState {
return { ...state };
},
},
actions: {
setInfo(partial: Partial<AuthorizedState>) {
this.$patch(partial);
},
async syncInfo() {
const { user, permissions, menus } = await useAuthApi.info();
this.setInfo({ ...user, permissions });
useAppStore().setPermissions(menus);
},
async logout() {
this.$reset();
clearToken();
},
async syncToken() {
// const { data } = await refreshToken();
// setToken(data.access_token);
},
},
});
export default useAuthorizedStore;