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 @@ 点击图片刷新验证码 + +