diff --git a/src/api/index.ts b/src/api/index.ts index 1b6106a..ab52281 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,3 +1,4 @@ +import { REQUEST_BASE_URL } from '@/env'; import { userInfoRespSchema, userInfoRespSchemaNullable, @@ -13,7 +14,7 @@ import { ElMessage } from 'element-plus'; import type { z } from 'zod'; export const axiosInstance = axios.create({ - baseURL: import.meta.env.VITE_REQUEST_BASE_URL, + baseURL: REQUEST_BASE_URL, }); // 自动添加token到请求中. axiosInstance.interceptors.request.use((config) => { @@ -32,11 +33,8 @@ axiosInstance.interceptors.response.use((response) => { return response; }); export type RawResp = Record; -const errorMessage = ( - description: string = '请求错误', - code: string | number | undefined, - msg: string, -) => `${description}:(${code})${msg}`; +const errorMessage = (description: string, code: string | number | undefined, msg: string) => + `${description}:(${code})${msg}`; interface RequestOptions extends Override { errorDescription?: string; @@ -44,7 +42,7 @@ interface RequestOptions extends Override( schema: T, raw: RawResp | undefined, - errorDescription?: string, + errorDescription: string, ): SucceedRespOf> | undefined { if (!raw) return; const resp = schema.parse(raw); @@ -59,14 +57,16 @@ export async function request( schema: T, options: RequestOptions = {}, ) { + const { errorDescription = '请求错误' } = options; return parseRawResp( schema, await axiosInstance .request(Object.assign(options, { url })) .then((r) => r.data) .catch((err: AxiosError): undefined => { - ElMessage.error(errorMessage(options.errorDescription, err.code, err.message)); + ElMessage.error(errorMessage(errorDescription, err.code, err.message)); }), + errorDescription, ); } export async function getUserInfo(): Promise; diff --git a/src/components/app/LoginRegisterDialog.vue b/src/components/app/LoginRegisterDialog.vue index c42e5ef..ac20220 100644 --- a/src/components/app/LoginRegisterDialog.vue +++ b/src/components/app/LoginRegisterDialog.vue @@ -41,7 +41,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -151,9 +151,12 @@ export interface LoginRegisterDialogProps { handleLogin: (params: LoginParams) => Promise; handleRegister: (params: RegisterParams) => Promise; } +export const usernameLength = 3; +export const passwordLength = usernameLength; diff --git a/src/views/user/UserPage.vue b/src/views/user/UserPage.vue index 1de455b..480e6bb 100644 --- a/src/views/user/UserPage.vue +++ b/src/views/user/UserPage.vue @@ -40,7 +40,7 @@
- +

个人中心

@@ -49,7 +49,6 @@ 编辑信息 -