user.js
6.45 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { login, logout, getInfo, loginByPhone } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import defAva from '@/assets/images/profile.jpg'
import { getMyOwnMemberInfo } from '@/api/system/userInfo.js'
import { defineStore } from 'pinia'
import aes from '@/utils/aes'
import { loginDance } from '@/apiPc/login.js'
import { getRemindCount } from '@/api/system/user'
import { ElMessageBox } from 'element-plus'
import * as match from '@/apiPc/match'
const useUserStore = defineStore(
'user',
{
state: () => ({
token: getToken(),
user: null, // uType 1个人账号,2团体账号,3游客登录
group: {}, // type 0普通院校 1专业舞蹈学院 2培训机构/娱乐部 3地方协会 4国家协会
name: '',
nickName: '',
avatar: '',
roles: [],
permissions: [],
memberInfo: {},
authenticationStatus: '', // 是否已认证
deptType: '',
showPrice: false,
perId: '',
personInfo: '',
unit: '',
isExam: '1', // 是否为考点,0:是;1:否,
genFlag: '', // 是否是自动的协会
badge: {},
reLogin: { show: false, query: {}},
visitor: false,
language: 0,
activeName: '5',
nowMatch: ''
}),
actions: {
// 登录
login(userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.data.token)
this.token = res.data.token
resolve()
}).catch(error => {
reject(error)
})
})
},
loginByPhone(userInfo) {
const phonenumber = userInfo.telNo.trim()
const code = userInfo.code
return new Promise((resolve, reject) => {
loginByPhone(phonenumber, code).then(res => {
setToken(res.data.token)
this.token = res.data.token
resolve()
}).catch(error => {
reject(error)
})
})
},
loginPc(userInfo) {
const username = userInfo.username
const password = userInfo.password
const uuid = userInfo.uuid
const code = userInfo.code
return new Promise((resolve, reject) => {
loginDance(username, password, code, uuid).then(res => {
setToken(res.data.token)
this.token = res.data.token
resolve()
}).catch(error => {
reject(error)
})
})
},
// 获取用户信息
getInfo() {
return new Promise((resolve, reject) => {
getInfo().then(res => {
const user = res.data.user
const personInfo = res.data.personInfo
const avatar = (user.avatar == '' || user.avatar == null) ? defAva : user.avatar
if (res.data.roles && res.data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
this.roles = res.data.roles
this.permissions = res.data.permissions
} else {
this.roles = ['ROLE_DEFAULT']
}
this.user = user
this.group = res.data.group
this.name = user.userName
this.nickName = user.nickName
this.deptType = user.dept.deptType
this.genFlag = user.dept.genFlag
this.showPrice = ['1', '2', '3'].indexOf(this.deptType) > -1
this.dept = user.dept
this.avatar = avatar
if (personInfo) {
this.perId = aes.encrypt(personInfo.perId)
this.personInfo = personInfo
}
if (this.user && this.user.utype == 1) {
this.getCheckWDSF()
}
resolve(res.data)
}).catch(error => {
reject(error)
})
})
},
getCheckWDSF() {
match.preCheckForPerson({ type: '1' }).then(res => {
if (res.data == 0) {
const language = localStorage.getItem('language')
ElMessageBox.confirm(
language == 0
? '您绑定的WDSF会员号已过期,请先到WDSF官网激活您的会员号。'
: 'Your bound WDSF Number has expired. Please activate your WDSF Number on the WDSF official website first.'
, language == 0 ? '提示' : 'Tips', {
type: 'warning',
confirmButtonText: language == 0 ? '确定' : 'OK',
cancelButtonText: language == 0 ? '取消' : 'Cancel'
}
)
}
})
},
// 退出系统
logOut() {
return new Promise((resolve, reject) => {
logout(this.token).then(() => {
this.token = ''
this.roles = []
this.permissions = []
this.perId = ''
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
// 获取道馆信息
getMemInfo() {
return getMyOwnMemberInfo().then(res => {
this.authenticationStatus = res.data.authenticationStatus
this.memberInfo = res.data.memberInfo
this.isExam = res.data?.dept?.isExam
})
},
getRemindInfo() {
getRemindCount().then((res) => {
this.badge = res.data
})
},
setVisitor() {
this.visitor = true
setTimeout(() => {
this.visitor = false
}, 1000)
},
setReLogin(query) {
console.log(query)
this.reLogin = { show: true, query: query }
setTimeout(() => {
this.reLogin = { show: false, query: query }
}, 1000)
},
checkAndLogin() {
if (!this.perId) {
ElMessageBox.alert('请先登录账号', '系统提示')
.then(() => {
this.setReLogin()
})
return false
} else {
return true
}
},
updataActiveName(v) {
this.activeName = v
},
updateNowMatch(v) {
this.nowMatch = v
}
}
})
export default useUserStore