login.ts
925 Bytes
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
import router from '@/router'
import { ElMessage } from "element-plus";
interface LoginUser {
token: string,
organizationId: number,
id: number,
userName: string
}
const id: string = 'login'
const state: Function = () => ({
token: '',
organizationId: null,
id: null,
userName: ''
})
const getters = {
getToken() {
return this.token
},
getOid() {
return this.organizationId
},
getId() {
return this.id
},
getUserName() {
return this.userName
}
}
const actions = {
setUserInfo(obj: LoginUser) {
this.token = obj.token
this.organizationId = obj.organizationId
this.id = obj.id
this.userName = obj.userName
},
removeToken(msg: string | null) {
this.token = ''
ElMessage.success(msg || '已退出登录');
setTimeout(() => {
router.replace('/login')
}, 500)
}
}
export default {
namespace: true,
actions,
getters,
state,
id
}