mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-21 22:53:56 +08:00
update:移动端忘记密码页面的前后端对接
This commit is contained in:
@@ -123,3 +123,21 @@ export function register(data: RegisterData) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 忘记密码数据类型
|
||||||
|
export interface ForgotPasswordData {
|
||||||
|
phone: string
|
||||||
|
code: string
|
||||||
|
password: string
|
||||||
|
captchaId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 忘记密码(找回密码)
|
||||||
|
export function retrievePassword(data: ForgotPasswordData) {
|
||||||
|
return http.Put('/user/retrieve-password', data, {
|
||||||
|
meta: {
|
||||||
|
ignoreAuth: true,
|
||||||
|
toast: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import { getEnvBaseUrl, sm2Encrypt } from "@/utils";
|
|||||||
import { toast } from "@/utils/toast";
|
import { toast } from "@/utils/toast";
|
||||||
// 导入国际化相关功能
|
// 导入国际化相关功能
|
||||||
import { t, initI18n } from "@/i18n";
|
import { t, initI18n } from "@/i18n";
|
||||||
|
// 导入API接口
|
||||||
|
import { retrievePassword, sendSmsCode } from "@/api/auth";
|
||||||
|
|
||||||
// 获取屏幕边界到安全区域距离
|
// 获取屏幕边界到安全区域距离
|
||||||
let safeAreaInsets;
|
let safeAreaInsets;
|
||||||
@@ -129,7 +131,7 @@ async function refreshCaptcha() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 发送短信验证码
|
// 发送短信验证码
|
||||||
async function sendSmsCode() {
|
async function handleSendSmsCode() {
|
||||||
// 手机号格式验证
|
// 手机号格式验证
|
||||||
const phoneRegex = /^1[3-9]\d{9}$/;
|
const phoneRegex = /^1[3-9]\d{9}$/;
|
||||||
if (!phoneRegex.test(formData.value.mobile)) {
|
if (!phoneRegex.test(formData.value.mobile)) {
|
||||||
@@ -144,12 +146,14 @@ async function sendSmsCode() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
smsLoading.value = true;
|
smsLoading.value = true;
|
||||||
// TODO: 调用发送短信验证码API
|
// 将手机号转换为国际格式
|
||||||
// await sendSmsCode({
|
const internationalPhone = formData.value.areaCode + formData.value.mobile;
|
||||||
// mobile: formData.value.mobile,
|
// 调用发送短信验证码API
|
||||||
// captcha: formData.value.captcha,
|
await sendSmsCode({
|
||||||
// captchaId: formData.value.captchaId
|
phone: internationalPhone,
|
||||||
// })
|
captcha: formData.value.captcha,
|
||||||
|
captchaId: formData.value.captchaId
|
||||||
|
})
|
||||||
|
|
||||||
toast.success(t("retrievePassword.captchaSendSuccess"));
|
toast.success(t("retrievePassword.captchaSendSuccess"));
|
||||||
|
|
||||||
@@ -188,6 +192,9 @@ async function handleResetPassword() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将手机号转换为国际格式
|
||||||
|
const internationalPhone = formData.value.areaCode + formData.value.mobile;
|
||||||
|
|
||||||
if (!formData.value.captcha) {
|
if (!formData.value.captcha) {
|
||||||
toast.warning(t("retrievePassword.captchaRequired"));
|
toast.warning(t("retrievePassword.captchaRequired"));
|
||||||
return;
|
return;
|
||||||
@@ -218,7 +225,7 @@ async function handleResetPassword() {
|
|||||||
|
|
||||||
// 检查SM2公钥是否配置
|
// 检查SM2公钥是否配置
|
||||||
if (!sm2PublicKey.value) {
|
if (!sm2PublicKey.value) {
|
||||||
toast.warning(t('sm2.publicKeyNotConfigured'));
|
toast.warning(t("sm2.publicKeyNotConfigured"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,17 +237,17 @@ async function handleResetPassword() {
|
|||||||
encryptedPassword = sm2Encrypt(sm2PublicKey.value, captchaAndPassword);
|
encryptedPassword = sm2Encrypt(sm2PublicKey.value, captchaAndPassword);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("密码加密失败:", error);
|
console.error("密码加密失败:", error);
|
||||||
toast.warning(t('sm2.encryptionFailed'));
|
toast.warning(t("sm2.encryptionFailed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 调用重置密码API
|
// 调用重置密码API
|
||||||
// await resetPassword({
|
await retrievePassword({
|
||||||
// mobile: formData.value.mobile,
|
phone: internationalPhone,
|
||||||
// mobileCaptcha: formData.value.mobileCaptcha,
|
code: formData.value.mobileCaptcha,
|
||||||
// password: encryptedPassword,
|
password: encryptedPassword,
|
||||||
// captchaId: formData.value.captchaId
|
captchaId: formData.value.captchaId
|
||||||
// })
|
})
|
||||||
|
|
||||||
toast.success(t("retrievePassword.passwordUpdateSuccess"));
|
toast.success(t("retrievePassword.passwordUpdateSuccess"));
|
||||||
|
|
||||||
@@ -358,11 +365,11 @@ onMounted(async () => {
|
|||||||
:placeholder="t('retrievePassword.mobileCaptchaPlaceholder')"
|
:placeholder="t('retrievePassword.mobileCaptchaPlaceholder')"
|
||||||
:maxlength="6"
|
:maxlength="6"
|
||||||
/>
|
/>
|
||||||
<view class="sms-button" @click="sendSmsCode">
|
<view class="sms-button" @click="handleSendSmsCode">
|
||||||
<text class="sms-text">
|
<text class="sms-text">
|
||||||
{{
|
{{
|
||||||
smsCountdown > 0
|
smsCountdown > 0
|
||||||
? `${smsCountdown}${t("register.secondsLater")}`
|
? `${smsCountdown}s`
|
||||||
: t("retrievePassword.getMobileCaptcha")
|
: t("retrievePassword.getMobileCaptcha")
|
||||||
}}
|
}}
|
||||||
</text>
|
</text>
|
||||||
@@ -446,7 +453,7 @@ onMounted(async () => {
|
|||||||
custom-class="confirm-btn"
|
custom-class="confirm-btn"
|
||||||
@click="closeAreaCodeSheet"
|
@click="closeAreaCodeSheet"
|
||||||
>
|
>
|
||||||
{{ t('login.confirm') }}
|
{{ t("login.confirm") }}
|
||||||
</wd-button>
|
</wd-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
Reference in New Issue
Block a user