From 10603c02980f6966217c38bcad15b63d5edfe484 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Sat, 30 Nov 2024 16:16:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B3=A8=E5=86=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/business/captcha.ts | 16 +- src/service/api/auth.ts | 22 +- src/store/modules/auth/index.ts | 20 +- src/typings/api.d.ts | 1 + src/views/_builtin/login/modules/register.vue | 385 +++++++++--------- 5 files changed, 231 insertions(+), 213 deletions(-) diff --git a/src/hooks/business/captcha.ts b/src/hooks/business/captcha.ts index 3f27072..3290b3b 100644 --- a/src/hooks/business/captcha.ts +++ b/src/hooks/business/captcha.ts @@ -1,8 +1,8 @@ import { computed } from 'vue'; import { useCountDown, useLoading } from '@sa/hooks'; import { $t } from '@/locales'; -import {REG_EMAIL} from '@/constants/reg'; -import {useAuthStore} from "@/store/modules/auth"; +import { REG_EMAIL } from '@/constants/reg'; +import { useAuthStore } from '@/store/modules/auth'; export function useCaptcha() { const { loading, startLoading, endLoading } = useLoading(); @@ -39,20 +39,17 @@ export function useCaptcha() { return true; } + //获取验证码方法 async function getCaptcha(email: string) { - console.log(email) - //const valid = isPhoneValid(phone); - const valid = isEmailValid(email); + const valid = isEmailValid(email); if (!valid || loading.value) { - return; + return null; } startLoading(); - await authStore.captcha( - email, - ); + const data = await authStore.captcha(email); await new Promise(resolve => { setTimeout(resolve, 500); }); @@ -62,6 +59,7 @@ export function useCaptcha() { start(); endLoading(); + return data; } return { diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index b6a3a89..7159a00 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -13,21 +13,24 @@ export function fetchLogin(body: Api.Auth.LoginBody) { data: body }); } + //邮箱验证码接口 -export function sendCaptcha(body:Api.Auth.EmailCaptcha){ +export function sendCaptcha(body: Api.Auth.EmailCaptcha) { return request({ - url:`/system/email/code?email=${body.email}`, - method:'get', - }) + url: `/code?email=${body.email}`, + method: 'get' + }); } + //验证注册 -export function doCheckUserRepeat(body:Api.Auth.CheckBody){ +export function doCheckUserRepeat(body: Api.Auth.CheckBody) { return request({ - url:'/u/user/checkRepeat', - method:'post', - data:body - }) + url: '/auth/checkRepeat', + method: 'post', + data: body + }); } + //添加注册 export function fetchRegister(body: Api.Auth.RegisterBody) { return request({ @@ -36,6 +39,7 @@ export function fetchRegister(body: Api.Auth.RegisterBody) { data: body }); } + /** logout */ export function doDeleteLogout() { return request>({ diff --git a/src/store/modules/auth/index.ts b/src/store/modules/auth/index.ts index 910a23a..78257dd 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -7,7 +7,7 @@ import { localStg } from '@/utils/storage'; import { $t } from '@/locales'; import { useRouteStore } from '../route'; import { clearAuthStorage, emptyInfo, getToken } from './shared'; -import {doCheckUserRepeat, sendCaptcha} from "@/service/api/auth"; +import { doCheckUserRepeat, sendCaptcha } from '@/service/api/auth'; export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const routeStore = useRouteStore(); @@ -122,12 +122,11 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { } return false; } - //check User /** * 检查用户信息是否已存在 */ - async function checkUserRepeat(checkForm:Api.Auth.CheckBody) { + async function checkUserRepeat(checkForm: Api.Auth.CheckBody) { const { data, error } = await doCheckUserRepeat(checkForm); return { exists: data, error }; } @@ -149,16 +148,13 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { endLoading(); return !error; } - async function captcha(email:string){ + + async function captcha(email: string) { if (!email) { - return; - } - - try { - await sendCaptcha({ email }); // 这里调用后端接口发送验证码 - } catch (error) { - + return null; } + const { data, error } = await sendCaptcha({ email }); // 这里调用后端接口发送验证码 + return { data, error }; } return { @@ -173,6 +169,6 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { refreshUserInfo, register, captcha, - checkUserRepeat, + checkUserRepeat }; }); diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index ebdc1c5..2aa40fe 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -156,6 +156,7 @@ declare namespace Api { username?: string; email?: string; phonenumber?:string; + authType: string; } } diff --git a/src/views/_builtin/login/modules/register.vue b/src/views/_builtin/login/modules/register.vue index 8075f80..c1fe06e 100644 --- a/src/views/_builtin/login/modules/register.vue +++ b/src/views/_builtin/login/modules/register.vue @@ -1,14 +1,14 @@