login.ts
1.71 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
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
}
const id: string = 'login'
const state: Function = () => ({
token: '',
organizationId: null,
id: null,
userName: '',
organizationType: null,
organizationName: '',
organizationLogo: ''
})
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
}
}
const actions = {
setUserInfo(obj: LoginUser) {
this.token = obj.token
this.organizationId = obj.organizationId
this.id = obj.id
this.userName = obj.userName
this.organizationName = obj.organizationName
this.organizationType = obj.organizationType
this.organizationLogo = obj.organizationLogo
},
removeToken(msg: string | null) {
logout()
this.token = ''
window.localStorage.removeItem('store-data')
ElMessage.success(msg || '已退出登录');
setTimeout(() => {
router.replace('/login')
}, 500)
}
}
export default {
namespace: true,
actions,
getters,
state,
id
}