ResetPassword.vue
8.55 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<template>
<!-- 密码 -->
<van-popup
v-model="passwordShow"
round
:close-on-click-overlay="false"
:style="{
width: '80vw',
padding: '0.3rem',
}"
class="process-popup"
v-if="passwordShow"
>
<div class="title">修改密码</div>
<van-form @submit="onSubmit" :show-error="false" ref="myform">
<div class="content">
<van-field
v-model="passForm.oldPassword"
name="旧密码"
label="旧密码"
required
:type="oldPassword ? 'text' : 'password'"
placeholder="请输入原密码"
:rules="[
{ required: true, message: '请输入旧密码', trigger: 'onChange' },
]"
@click-right-icon="clickPassword('oldPassword')"
>
<template #right-icon>
<i :class="!oldPassword ? 'icon-yincang' : 'icon-xianshi'"></i>
</template>
</van-field>
<van-field
v-model="passForm.newPassword"
name="新密码"
label="新密码"
required
:type="newPassword ? 'text' : 'password'"
placeholder="请设置新密码"
:rules="[
{
validator: validateNew,
message: errorMessage,
trigger: 'onChange',
},
]"
@click-right-icon="clickPassword('newPassword')"
>
<template #right-icon>
<i :class="!newPassword ? 'icon-yincang' : 'icon-xianshi'"></i>
</template>
</van-field>
<van-field
v-model="passForm.saPassword"
name="确认密码"
label="确认密码"
:type="saPassword ? 'text' : 'password'"
required
placeholder="请再次输入新密码"
:rules="[
{
validator: validateNewReapeat,
message: errorMessageReapeat,
trigger: 'onChange',
},
]"
@click-right-icon="clickPassword('saPassword')"
>
<template #right-icon>
<i :class="!saPassword ? 'icon-yincang' : 'icon-xianshi'"></i>
</template>
</van-field>
</div>
<van-row gutter="20" class="processButton">
<van-col span="12">
<van-button type="default" class="close" @click="passwordClose">
取消
</van-button>
</van-col>
<van-col span="12">
<van-button type="info" native-type="submit">确定</van-button>
</van-col>
</van-row>
</van-form>
</van-popup>
</template>
<script>
import { releaseWakeLock } from '@/utils/index.js'
import { Dialog } from 'vant'
import { encryptWithRsa } from '@/utils/index.js'
export default {
props: {
account: {
type: String,
default: '',
},
loginPage: {
type: Boolean,
default: false,
},
},
components: {
Dialog,
},
data() {
return {
passwordShow: false,
saPassword: false,
newPassword: false,
oldPassword: false,
passForm: {
oldPassword: '',
newPassword: '',
saPassword: '',
},
errorMessage: '',
errorMessageReapeat: '',
}
},
methods: {
validateNewReapeat(value) {
if (value === '') {
this.errorMessageReapeat = '请再次输入新密码'
return false
} else if (value !== this.passForm.newPassword) {
this.errorMessageReapeat = '两次输入的密码不一致'
return false
}
},
validateNew(value) {
if (value == '') {
this.errorMessage = '请输入新密码'
return false
}
let config = this.pwdStrategy
if (config.enable && config.enable == 1) {
let pwdRule = config.pwdRule
let pwdLength = config.pwdLength
if (pwdRule) {
if (value.length < pwdLength) {
this.errorMessage = '新密码长度至少为' + pwdLength
return false
} else if (pwdRule == 2) {
var re = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])')
if (!re.test(value)) {
this.errorMessage = '新密码必须包含数字、字母'
return false
}
} else if (pwdRule == 3) {
var re = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])')
if (!re.test(value)) {
this.errorMessage = '新密码必须包含数字、字母、特殊字符'
return false
}
} else if (pwdRule == 4) {
var re = new RegExp(
'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9])'
)
if (!re.test(value)) {
this.errorMessage = '新密码必须包含数字、大小字母、特殊字符'
return false
}
}
}
} else {
if (value.length < 6) {
this.errorMessage = '新密码长度至少为6'
return false
}
}
}, //修改密码保存
onSubmit(values) {
let self = this
this.$http
.post(`${window.context.uc}/api/user/v1/user/changUserPsd`, {
account: this.account,
oldPwd: encryptWithRsa(this.passForm.oldPassword),
newPwd: encryptWithRsa(this.passForm.newPassword),
})
.then((data) => {
if (data && data.state) {
self.$refs['myform'].resetValidation()
Dialog.alert({
title: '提示',
message: '修改密码成功, 请使用新密码重新登录。',
}).then(() => {
self.exit()
self.passwordShow = false
self.$emit('close')
})
} else {
self.$toast.fail(data.message)
}
})
}, //修改密码关闭
passwordClose() {
this.passForm = {}
this.$refs['myform'].resetValidation()
this.passwordShow = false
},
clickPassword(da) {
this[da] = !this[da]
},
//退出登陆
exit() {
if (!this.loginPage) {
let loginRouthPath =
localStorage.getItem(
this.$store.state.login.currentUser.account + 'loginRoutePath'
) || '/login'
this.$store.dispatch('login/logoutAndCleanUp').then(() => {
this.postMessage()
releaseWakeLock()
this.$router.push(loginRouthPath)
})
}
this.passwordShow = false
},
postMessage() {
window.uni &&
uni.postMessage({
data: {
action: 'logout',
},
})
},
openResetPasswordDialog() {
this.passwordShow = true
this.$store.dispatch('user/getDefPwdStrategy').then((res) => {
this.pwdStrategy = res
})
},
},
}
</script>
<style lang="scss" scoped>
@import '@/styles/matterButton.scss';
@mixin placeholder {
color: #cccccc;
font-weight: 400;
font-size: 14px;
}
::v-deep .van-field__label {
width: 70px;
}
::v-deep {
input::-webkit-input-placeholder {
/* 使用webkit内核的浏览器 */
@include placeholder;
}
input:-moz-placeholder {
/* Firefox版本4-18 */
@include placeholder;
}
input::-moz-placeholder {
/* Firefox版本19+ */
@include placeholder;
}
input:-ms-input-placeholder {
/* IE浏览器 */
@include placeholder;
}
.van-cell {
padding: 12px 12px !important;
margin: 0 !important;
}
.van-field__right-icon {
font-size: 16px;
}
}
.process-popup {
padding: 24px 16px !important;
.title {
text-align: center;
font-size: 17px;
font-weight: 800;
color: #1a1a1a;
}
.content {
margin: 16px 0 24px 0;
}
.van-cell::after {
border-bottom: 0.02667rem solid #ebedf0 !important;
display: block !important;
}
.processButton {
// position: absolute;
width: 100%;
// bottom: 20px;
.van-button {
width: 100%;
border-radius: 8px 8px 8px 8px;
}
}
.van-cell__right-icon {
color: #969799;
display: flex;
justify-content: center;
align-items: center;
}
.van-cell::after {
border: none;
}
.group-All {
.van-cell {
padding-bottom: 2px;
}
}
.van-cell {
padding: 12px 12px;
}
}
</style>