login.ts
2.33 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { defineStore } from 'pinia'
import router from '@/router';
import { logout } from '@/api/user/login';
interface LoginUser {
token: string,
organizationId?: number,
id?: number,
userName: string,
organizationType?: number | null,
organizationName?: string,
organizationLogo?: string,
oId?: number,
oName?: string,
oLogo?: string,
userId?: number,
oType?: number,
menuList?: any[]
}
export const useLoginStore = defineStore({
id: 'login',
state: () => {
return {
token: '',
organizationId: null,
id: null,
userName: '',
organizationType: null,
organizationName: '',
organizationLogo: '',
menuList: []
}
},
actions: {
setUserInfo(obj: LoginUser) {
this.token = obj.token? obj.token: this.token
this.organizationId = obj.organizationId? obj.organizationId: obj.oId
this.id = obj.id? obj.id: obj.userId
this.userName = obj.userName
this.organizationName = obj.organizationName? obj.organizationName: obj.oName
this.organizationType = obj.organizationType? obj.organizationType: obj.oType
this.organizationLogo = obj.organizationLogo? obj.organizationLogo: obj.oLogo
},
setMenuList (data: any[]) {
this.menuList = data
},
removeToken() {
logout()
this.token = ''
let loginPath: string = window.localStorage.getItem('isCnlive') === 'true'? '/enter': '/login'
console.log(loginPath)
window.localStorage.clear()
window.localStorage.removeItem('pinia')
setTimeout(() => {
router.replace(loginPath)
}, 500)
}
},
getters: {
getToken(state) {
// 记录登录状态的标识
return state.token
},
getOid(state) {
// 当前登录人的组织id
return state.organizationId
},
getId(state) {
// 当前登录人的id
return state.id
},
getUserName(state) {
// 当前登录人的用户名
return state.userName
},
getOtype (state) {
// 1 物业管理员,2 公益管理员
return state.organizationType
},
getOname (state) {
// 当前登录的组织名称
return state.organizationName
},
getOlogo (state) {
// 当前登陆的组织logo
return state.organizationLogo
},
getMenuList (state) {
return state.menuList
}
}
})