security-settings.vue
3.37 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
<template>
<a-spin style="width: 100%;height: 100%" :loading="loading">
<a-form
ref="formRef"
:model="formData"
class="form"
:label-col-props="{ span: 8 }"
:wrapper-col-props="{ span: 16 }"
>
<!--旧密码-->
<a-form-item
field="oldPassword"
label="旧密码"
:rules="[
{
required: true,
message: '请输入旧密码',
}]"
>
<a-input-password
v-model="formData.oldPassword"
placeholder="请输入旧密码"
autocomplete="off"
/>
</a-form-item>
<!--新密码-->
<a-form-item
field="newPassword"
label="新密码"
:rules="[
{
required: true,
message: '请输入新密码',
},{
minLength: 5,
maxLength: 20,
message: '密码长度必须介于 5 和 20 之间'
}
]"
>
<a-input-password
v-model="formData.newPassword"
placeholder="请输入新密码"
autocomplete="off"
/>
</a-form-item>
<!--确认密码-->
<a-form-item
field="rawPassword"
label="确认密码"
:rules="[
{
required: true,
message: '请确认新密码',
},{
minLength: 5,
maxLength: 20,
message: '密码长度必须介于 5 和 20 之间'
}]"
>
<a-input-password
v-model="formData.rawPassword"
placeholder="请确认新密码"
autocomplete="off"
/>
</a-form-item>
<a-form-item>
<a-space size="large">
<a-button type="primary" @click="validate">
保存
</a-button>
<a-button type="secondary" @click="reset">
重置
</a-button>
</a-space>
</a-form-item>
</a-form>
</a-spin>
</template>
<script lang="ts" setup>
import {ref} from 'vue';
import {FormInstance} from '@arco-design/web-vue/es/form';
import {updateUserPwd} from '@/api/user/user-center';
import {useUserStore} from "@/store";
import {Notification} from "@arco-design/web-vue";
import useLoading from "@/hooks/loading";
import {notification} from "@/hooks/my-design";
const userStore: any = useUserStore();
//加载中
const {loading, setLoading} = useLoading(false);
const formRef = ref<FormInstance>();
const formConfig = () => {
return {
oldPassword: '',
newPassword: '',
rawPassword: ''
}
}
const formData = ref<any>(formConfig());
const validate = async () => {
const res = await formRef.value?.validate();
if (!res) {
if (formData.value.newPassword !== formData.value.rawPassword) {
Notification.info({
title: '提示',
content: '登录密码不一致',
duration: 2000,
});
return false;
}
try {
setLoading(true);
const res = await updateUserPwd(formData.value);
if (res.code == 200) {
formData.value = formConfig();
await userStore.info();
}
notification(res);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
// do some thing
// you also can use html-type to submit
}
};
const reset = async () => {
await formRef.value?.resetFields();
};
</script>
<style scoped lang="less">
.form {
width: 70%;
}
</style>