From 650a180778ef94f19ce6a6f15d1585f8b381945c Mon Sep 17 00:00:00 2001 From: zhongzm Date: Fri, 29 Nov 2024 09:04:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B3=A8=E5=86=8C=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/business/captcha.ts | 24 +-- src/locales/langs/en-us.ts | 4 + src/locales/langs/zh-cn.ts | 4 + src/service/api/auth.ts | 16 ++ src/store/modules/auth/index.ts | 33 +++- src/typings/api.d.ts | 14 ++ src/typings/app.d.ts | 1 + src/typings/auto-imports.d.ts | 3 + src/typings/components.d.ts | 1 + src/views/_builtin/login/modules/register.vue | 155 +++++++++++++++--- 10 files changed, 222 insertions(+), 33 deletions(-) diff --git a/src/hooks/business/captcha.ts b/src/hooks/business/captcha.ts index b041c17..3f27072 100644 --- a/src/hooks/business/captcha.ts +++ b/src/hooks/business/captcha.ts @@ -1,12 +1,13 @@ import { computed } from 'vue'; import { useCountDown, useLoading } from '@sa/hooks'; import { $t } from '@/locales'; -import { REG_PHONE } from '@/constants/reg'; +import {REG_EMAIL} from '@/constants/reg'; +import {useAuthStore} from "@/store/modules/auth"; export function useCaptcha() { const { loading, startLoading, endLoading } = useLoading(); const { count, start, stop, isCounting } = useCountDown(10); - + const authStore = useAuthStore(); const label = computed(() => { let text = $t('page.login.codeLogin.getCode'); @@ -23,14 +24,14 @@ export function useCaptcha() { return text; }); - function isPhoneValid(phone: string) { - if (phone.trim() === '') { + function isEmailValid(email: string) { + if (email.trim() === '') { $message?.error?.($t('form.phone.required')); return false; } - if (!REG_PHONE.test(phone)) { + if (!REG_EMAIL.test(email)) { $message?.error?.($t('form.phone.invalid')); return false; @@ -38,17 +39,20 @@ export function useCaptcha() { return true; } - - async function getCaptcha(phone: string) { - const valid = isPhoneValid(phone); - + //获取验证码方法 + async function getCaptcha(email: string) { + console.log(email) + //const valid = isPhoneValid(phone); + const valid = isEmailValid(email); if (!valid || loading.value) { return; } startLoading(); - // request + await authStore.captcha( + email, + ); await new Promise(resolve => { setTimeout(resolve, 500); }); diff --git a/src/locales/langs/en-us.ts b/src/locales/langs/en-us.ts index 52acd61..2ab7c78 100644 --- a/src/locales/langs/en-us.ts +++ b/src/locales/langs/en-us.ts @@ -178,6 +178,7 @@ const local: any = { back: 'Back', validateSuccess: 'Verification passed', loginSuccess: 'Login successfully', + registerSuccess:'Register successfully', welcomeBack: 'Welcome back, {username} !', checkCode: 'Please check the verification code', emailPlaceholder:'Please enter the email' @@ -224,6 +225,9 @@ const local: any = { address: 'Address', next: 'Next', prev: 'Prev', + birthDate: 'Birth Date', + birthDatePlaceholder: 'Please select birth date', + birthDateRequired: 'Please select birth date', }, resetPwd: { title: 'Reset Password' diff --git a/src/locales/langs/zh-cn.ts b/src/locales/langs/zh-cn.ts index 7da9af8..1f725c6 100644 --- a/src/locales/langs/zh-cn.ts +++ b/src/locales/langs/zh-cn.ts @@ -178,6 +178,7 @@ const local:any = { back: '返回', validateSuccess: '验证成功', loginSuccess: '登录成功', + registerSuccess:'注册成功', welcomeBack: '欢迎回来,{username} !', checkCode: '请输入验证码', emailPlaceholder:'请输入邮箱' @@ -224,6 +225,9 @@ const local:any = { address: '地址', next: '下一步', prev: '上一步', + birthDate: '出生日期', + birthDatePlaceholder: '请选择出生日期', + birthDateRequired: '请选择出生日期', }, resetPwd: { title: '重置密码' diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 01cd180..45163c8 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -13,7 +13,23 @@ export function fetchLogin(body: Api.Auth.LoginBody) { data: body }); } +//邮箱验证码接口 +export function sendCaptcha(body:Api.Auth.EmailCaptcha){ + return request({ + url:`/system/email/code?email=${body.email}`, + method:'get', + }) +} +//验证注册 +//添加注册 +export function fetchRegister(body: Api.Auth.RegisterBody) { + return request({ + url: '/auth/register', + method: 'post', + 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 e9f6b77..132d094 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -7,6 +7,7 @@ import { localStg } from '@/utils/storage'; import { $t } from '@/locales'; import { useRouteStore } from '../route'; import { clearAuthStorage, emptyInfo, getToken } from './shared'; +import {sendCaptcha} from "@/service/api/auth"; export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const routeStore = useRouteStore(); @@ -121,6 +122,34 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { } return false; } + /** + * Register new user + */ + async function register(registerForm: Api.Auth.RegisterBody) { + startLoading(); + + const { error } = await fetchRegister(registerForm); + + if (!error) { + $message?.success($t('page.login.common.registerSuccess')); + // 注册成功后跳转到登录页 + await toLogin(); + } + + endLoading(); + return !error; + } + async function captcha(email:string){ + if (!email) { + return; + } + + try { + await sendCaptcha({ email }); // 这里调用后端接口发送验证码 + } catch (error) { + + } + } return { token, @@ -131,6 +160,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { resetStore, permissions, login, - refreshUserInfo + refreshUserInfo, + register, + captcha, }; }); diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index d4262dd..63746d2 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -138,6 +138,20 @@ declare namespace Api { uuid: string; authType: string; } + interface RegisterBody{ + username: string; + password: string; + authType:string; + email: string; + fullName: string; + age: number; + address: string; + sex: string; + phonenumber: string; + } + interface EmailCaptcha{ + email:string; + } } /** diff --git a/src/typings/app.d.ts b/src/typings/app.d.ts index 65c56f0..06bea1f 100644 --- a/src/typings/app.d.ts +++ b/src/typings/app.d.ts @@ -358,6 +358,7 @@ declare namespace App { back: string; validateSuccess: string; loginSuccess: string; + registerSuccess: string; welcomeBack: string; checkCode: string; }; diff --git a/src/typings/auto-imports.d.ts b/src/typings/auto-imports.d.ts index 889b2c3..ae8942e 100644 --- a/src/typings/auto-imports.d.ts +++ b/src/typings/auto-imports.d.ts @@ -20,6 +20,7 @@ declare global { const beforeAll: typeof import('vitest')['beforeAll'] const beforeEach: typeof import('vitest')['beforeEach'] const chai: typeof import('vitest')['chai'] + const checkReport: typeof import('../service/api/auth')['checkReport'] const clearAuthStorage: typeof import('../store/modules/auth/shared')['clearAuthStorage'] const cloneDeep: typeof import('lodash-es')['cloneDeep'] const computed: typeof import('vue')['computed'] @@ -96,6 +97,7 @@ declare global { const fetchIsRouteExist: typeof import('../service/api/route')['fetchIsRouteExist'] const fetchLogin: typeof import('../service/api/auth')['fetchLogin'] const fetchRefreshToken: typeof import('../service/api/auth')['fetchRefreshToken'] + const fetchRegister: typeof import('../service/api/auth')['fetchRegister'] const filterAuthRoutesByRoles: typeof import('../store/modules/route/shared')['filterAuthRoutesByRoles'] const filterTabsById: typeof import('../store/modules/tab/shared')['filterTabsById'] const filterTabsByIds: typeof import('../store/modules/tab/shared')['filterTabsByIds'] @@ -182,6 +184,7 @@ declare global { const resolveComponent: typeof import('vue')['resolveComponent'] const resolveRef: typeof import('@vueuse/core')['resolveRef'] const resolveUnref: typeof import('@vueuse/core')['resolveUnref'] + const sendCaptcha: typeof import('../service/api/auth')['sendCaptcha'] const sessionStg: typeof import('../utils/storage')['sessionStg'] const setActivePinia: typeof import('pinia')['setActivePinia'] const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix'] diff --git a/src/typings/components.d.ts b/src/typings/components.d.ts index a5dc4fc..49cd77d 100644 --- a/src/typings/components.d.ts +++ b/src/typings/components.d.ts @@ -13,6 +13,7 @@ declare module 'vue' { ACard: typeof import('ant-design-vue/es')['Card'] ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] ACol: typeof import('ant-design-vue/es')['Col'] + ADatePicker: typeof import('ant-design-vue/es')['DatePicker'] ADescriptions: typeof import('ant-design-vue/es')['Descriptions'] ADescriptionsItem: typeof import('ant-design-vue/es')['DescriptionsItem'] ADivider: typeof import('ant-design-vue/es')['Divider'] diff --git a/src/views/_builtin/login/modules/register.vue b/src/views/_builtin/login/modules/register.vue index 64d7440..62afc6c 100644 --- a/src/views/_builtin/login/modules/register.vue +++ b/src/views/_builtin/login/modules/register.vue @@ -1,17 +1,22 @@