login.ts
2.05 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
import router from '@/router';
import { logout } from '@/api/user/login';
import { ElMessage } from "element-plus";
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[],
}
const id: string = 'login'
const state: Function = () => ({
token: '',
organizationId: null,
id: null,
userName: '',
organizationType: null,
organizationName: '',
organizationLogo: '',
menuList: []
})
const getters = {
getToken() {
// 记录登录状态的标识
return this.token
},
getOid() {
// 当前登录人的组织id
return this.organizationId
},
getId() {
// 当前登录人的id
return this.id
},
getUserName() {
// 当前登录人的用户名
return this.userName
},
getOtype () {
// 1 物业管理员,2 公益管理员
return this.organizationType
},
getOname () {
// 当前登录的组织名称
return this.organizationName
},
getOlogo () {
// 当前登陆的组织logo
return this.organizationLogo
},
getMenuList () {
return this.menuList
}
}
const 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(msg: string | null) {
logout()
this.token = ''
window.localStorage.clear()
setTimeout(() => {
router.replace('/login')
}, 500)
}
}
export default {
namespace: true,
actions,
getters,
state,
id
}