ChangePasswordDialog.vue
1.85 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
<template>
<div class="dialog-container">
<ElDialog
v-el-drag-dialog
:visible="show"
:close-on-click-modal="false"
title="修改密码"
width="40%"
@close="onCancel"
>
<ChangePasswordForm
ref="passwordForm"
:data="data"
:loading="submitLoading"
/>
<div
slot="footer"
class="footer-container"
>
<ElButton @click="onCancel">
取 消
</ElButton>
<ElButton
type="primary"
:loading="submitLoading"
@click="onSubmit"
>
保 存
</ElButton>
</div>
</ElDialog>
</div>
</template>
<script>
import ElDragDialog from '@/directives/el-drag-dialog'
import ChangePasswordForm from '../form/ChangePasswordForm'
import consumerApi from '@/api/consumer'
export default {
components: {
ChangePasswordForm
},
directives: {
ElDragDialog
},
data() {
return {
show: false,
data: null,
submitLoading: false
}
},
methods: {
open(data) {
this.show = true
this.data = data
},
onCancel() {
this.show = false
this.$refs.passwordForm.reset()
},
async onSubmit() {
try {
let data = {}
const valid = await this.$refs.passwordForm.onSubmit()
if (valid) {
data = this.$refs.passwordForm.form
} else {
return false
}
this.submitLoading = true
await consumerApi.updatePassword(data.userid, data)
this.$message.success('修改成功')
this.$refs.passwordForm.reset()
this.show = false
} catch (error) {
return error?.response?.data
} finally {
this.submitLoading = false
}
}
}
}
</script>
<style
scoped
lang="scss"
>
.footer-container {
text-align: center;
}
</style>