updatePwd.js
1.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
import {updatePwd} from '@/api/user'
export default {
data() {
return {
form: {
oldPassword: '',
password: '',
rePassword: ''
},
activeName: 'updatePwd',
user: {}
}
},
computed: {
rules() {
return {
password: [
{required: true, message: '密码不能为空', trigger: 'blur'},
{min: 5, max: 100, message: '密码长度不能小于5', trigger: 'blur'}
]
}
}
},
mounted() {
this.init()
},
methods: {
init() {
this.user = this.$store.state.user.profile
},
handleClick(tab, event) {
this.$router.push({path: '/account/' + tab.name})
},
updatePwd() {
this.$refs['form'].validate((valid) => {
if (valid) {
updatePwd({
oldPassword: this.form.oldPassword,
password: this.form.password,
rePassword: this.form.rePassword
}).then(response => {
this.$message({
message: '密码修改成功',
type: 'success'
})
//退出登录,该操作是个异步操作,所以后面跳转到登录页面延迟1s再执行(如果有更好的方法再调整)
this.$store.dispatch('user/logout')
const self = this
setTimeout(function(){
self.$router.push(`/login`)
},1000)
}).catch((err) => {
})
}
})
}
}
}