ForgetPasswordForm.vue
4.02 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
<template>
<template v-if="getShow">
<LoginFormTitle class="enter-x" />
<Form class="p-4 enter-x" :model="formData" :rules="getFormRules" ref="formRef">
<!-- <FormItem name="account" class="enter-x">
<Input
size="large"
v-model:value="formData.account"
:placeholder="t('sys.login.userName')"
/>
</FormItem> -->
<FormItem name="phone" class="enter-x">
<Input size="large" v-model:value="formData.phone" :placeholder="t('sys.login.mobile')" />
</FormItem>
<FormItem name="password" class="enter-x">
<Input
size="large"
visibilityToggle
v-model:value="formData.password"
placeholder="请输入密码"
/>
</FormItem>
<FormItem name="confirmPassword" class="enter-x">
<Input
size="large"
visibilityToggle
v-model:value="formData.confirmPassword"
placeholder="请输入确认密码"
/>
</FormItem>
<FormItem name="imgCaptchaCode" class="enter-x">
<div className="flex">
<img :src="imgCaptcha" class="cursor-pointer" @click="getImgCaptcha" />
<Input
size="large"
visibilityToggle
v-model:value="imgCaptchaCode"
placeholder="请输入图片验证码"
/>
</div>
</FormItem>
<FormItem name="smsCaptchaCode" class="enter-x">
<CountdownInput
size="large"
v-model:value="formData.smsCaptchaCode"
:sendCodeApi="handleSendMsg"
:placeholder="t('sys.login.smsCode')"
/>
</FormItem>
<FormItem class="enter-x">
<Button type="primary" size="large" block @click="handleReset" :loading="loading">
{{ t('common.resetText') }}
</Button>
<Button size="large" block class="mt-4" @click="handleBackLogin">
{{ t('sys.login.backSignIn') }}
</Button>
</FormItem>
</Form>
</template>
</template>
<script lang="ts" setup>
import { reactive, ref, computed, unref, onMounted } from 'vue';
import LoginFormTitle from './LoginFormTitle.vue';
import { Form, Input, Button, message } from 'ant-design-vue';
import { CountdownInput } from '/@/components/CountDown';
import { useI18n } from '/@/hooks/web/useI18n';
import { useLoginState, useFormRules, LoginStateEnum } from './useLogin';
import { forgetPassword, getSms } from '/@/api/sys/user';
import { useUserStore } from '/@/store/modules/user';
const FormItem = Form.Item;
const { t } = useI18n();
const { handleBackLogin, getLoginState } = useLoginState();
const { getFormRules } = useFormRules();
const formRef = ref();
const loading = ref(false);
const formData = reactive({
phone: '',
smsCaptchaCode: '',
password: '',
confirmPassword: '',
});
const imgCaptchaCode = ref('');
const imgCaptcha = ref('');
const imgCaptchaUuid = ref('');
const userStore = useUserStore();
onMounted(async () => {
getImgCaptcha();
});
const getImgCaptcha = async () => {
const data = await userStore.getImageCaptcha();
imgCaptcha.value = data?.img;
imgCaptchaUuid.value = data?.uuid;
};
const handleSendMsg = async () => {
if (!formData.phone) {
message.error('请输入手机号');
return false;
}
if (!imgCaptchaCode.value) {
message.error('请输入验证码');
return false;
}
if (formData.password !== formData.confirmPassword) {
message.error('密码和确认密码不一样');
return false;
}
return await getSms({
phone: formData.phone,
imgCaptchaCode: imgCaptchaCode.value,
imgCaptchaUuid: imgCaptchaUuid.value,
});
};
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.RESET_PASSWORD);
async function handleReset() {
try {
await formRef.value.validate();
const form = unref(formRef);
if (!form) return;
await forgetPassword({ ...formData });
handleBackLogin();
} catch (error) {}
}
</script>