From 0099840e8ee746adcaecd0e9683009890bd70688 Mon Sep 17 00:00:00 2001 From: jiangpeng <1649773715@qq.com> Date: Fri, 12 Jun 2026 14:52:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 30 +++- src/router/index.ts | 9 + src/store/auth.ts | 5 +- src/types/index.ts | 8 + src/views/Login/index.vue | 37 +++- src/views/ResetPassword/index.vue | 274 ++++++++++++++++++++++++++++++ 6 files changed, 357 insertions(+), 6 deletions(-) create mode 100644 src/views/ResetPassword/index.vue diff --git a/src/api/auth.ts b/src/api/auth.ts index 2eebb03..fe9f06d 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,5 +1,5 @@ import http from '@/utils/http' -import type { ApiResponse, LoginParams } from '@/types' +import type { ApiResponse, LoginParams, ResetPwdParams } from '@/types' import type { AxiosResponse } from 'axios' /** @@ -33,4 +33,32 @@ export const getInfo = (): Promise>> => { */ export const logout = (): Promise>> => { return http.post('/logout') +} + +const createFormData = (data: Record) => { + const formData = new FormData() + Object.keys(data).forEach((key) => formData.append(key, data[key])) + return formData +} + +/** + * 发送重置密码邮箱验证码 + */ +export const sendResetPwdEmailCode = (username: string): Promise>> => { + return http.post('/login/sendResetPwdEmailCode', createFormData({ username })) +} + +/** + * 重置登录密码 + */ +export const resetLoginPwd = (params: ResetPwdParams): Promise>> => { + return http.post( + '/login/resetPwd', + createFormData({ + username: params.username, + newPassword: params.newPassword, + confirmPassword: params.confirmPassword, + emailCode: params.emailCode + }) + ) } \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index c9cfc5f..52bc205 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -17,6 +17,15 @@ const routes: RouteRecordRaw[] = [ requiresAuth: false } }, + { + path: '/reset-password', + name: 'ResetPassword', + component: () => import('@/views/ResetPassword/index.vue'), + meta: { + title: '修改密码', + requiresAuth: false + } + }, { path: '/list', name: 'Home', diff --git a/src/store/auth.ts b/src/store/auth.ts index e93f0d3..90382f3 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -44,7 +44,10 @@ export const useAuthStore = defineStore('auth', { return response.data } else { - throw new Error(response.data.msg || '登录失败') + const error: any = new Error(response.data.msg || '登录失败') + error.code = response.data.code + error.response = response + throw error } } catch (error: any) { console.error('登录接口调用失败:', error) diff --git a/src/types/index.ts b/src/types/index.ts index 152e0c2..c7dd8e9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -14,6 +14,14 @@ export interface LoginParams { rememberMe?: boolean } +// 重置登录密码参数类型 +export interface ResetPwdParams { + username: string + newPassword: string + confirmPassword: string + emailCode: string +} + // 订单状态类型 export type OrderStatus = '0' | '1' | '2' // 待审批、已审批、已拒绝 export type FileType = '0' | '1' | '2' // 待审批、已审批、已拒绝 diff --git a/src/views/Login/index.vue b/src/views/Login/index.vue index 6b558fd..9737ad9 100644 --- a/src/views/Login/index.vue +++ b/src/views/Login/index.vue @@ -72,6 +72,10 @@ 点击图片刷新验证码 + +