diff --git a/src/main.ts b/src/main.ts index daa2839..16cb86a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ async function setupApp() { // 注册模块 Vue-router await installRouter(app) - /* 注册模块 Vue-router/Pinia */ + /* 注册模块 指令/静态资源 */ Object.values( import.meta.glob<{ install: (app: App) => void }>('./modules/*.ts', { eager: true, diff --git a/src/service/api/login.ts b/src/service/api/login.ts index 04c42c3..a877601 100644 --- a/src/service/api/login.ts +++ b/src/service/api/login.ts @@ -6,14 +6,14 @@ interface Ilogin { } export function fetchLogin(params: Ilogin) { - const methodInstance = alovaInstance.Post('/login', params) + const methodInstance = alovaInstance.Post>('/login', params) methodInstance.meta = { authRole: null, } return methodInstance } export function fetchUpdateToken(params: any) { - const method = alovaInstance.Post('/updateToken', params) + const method = alovaInstance.Post>('/updateToken', params) method.meta = { authRole: 'refreshToken', } @@ -21,5 +21,5 @@ export function fetchUpdateToken(params: any) { } export function fetchUserRoutes(params: { id: number }) { - return alovaInstance.Get('/getUserRoutes', { params }) + return alovaInstance.Get >('/getUserRoutes', { params }) } diff --git a/src/service/http/handle.ts b/src/service/http/handle.ts index b444d10..65532f9 100644 --- a/src/service/http/handle.ts +++ b/src/service/http/handle.ts @@ -56,11 +56,12 @@ export function handleBusinessError(data: Record, config: Required< * @return {*} result */ export function handleServiceResult(data: any, isSuccess: boolean = true) { - return { + const result = { isSuccess, errorType: null, ...data, } + return result } /** @@ -69,7 +70,7 @@ export function handleServiceResult(data: any, isSuccess: boolean = true) { */ export async function handleRefreshToken() { const authStore = useAuthStore() - const data = await fetchUpdateToken({ refreshToken: local.get('refreshToken') }) + const { data } = await fetchUpdateToken({ refreshToken: local.get('refreshToken') }) if (data) { local.set('token', data.accessToken) local.set('refreshToken', data.refreshToken) diff --git a/src/store/auth.ts b/src/store/auth.ts index 1c39f7a..764ef55 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -53,9 +53,11 @@ export const useAuthStore = defineStore('auth-store', { /* 用户登录 */ async login(username: string, password: string) { - const { error, data } = await fetchLogin({ username, password }) - if (error) + const { isSuccess, data } = await fetchLogin({ username, password }) + if (!isSuccess) { + window.$message.error('登录失败,请检查用户名和密码') return + } // 处理登录信息 await this.handleAfterLogin(data) diff --git a/src/store/route.ts b/src/store/route.ts index 8c61da6..75ea41d 100644 --- a/src/store/route.ts +++ b/src/store/route.ts @@ -181,6 +181,10 @@ export const useRouteStore = defineStore('route-store', { this.isInitAuthRoute = false // 初始化路由信息 const rowRoutes = await this.initRouteInfo() + if (!rowRoutes) { + window.$message.error('获取路由失败,请稍后再试') + return + } this.rowRoutes = rowRoutes // 生成真实路由并插入 this.createRoutes(rowRoutes) diff --git a/src/typings/route.d.ts b/src/typings/route.d.ts index 396135a..7c2edf8 100644 --- a/src/typings/route.d.ts +++ b/src/typings/route.d.ts @@ -1,5 +1,5 @@ declare namespace AppRoute { - /** 路由描述 */ + /** 单个路由所携带的meta标识 */ interface RouteMeta { /* 页面标题,通常必选。 */ title: string @@ -17,7 +17,7 @@ declare namespace AppRoute { order?: number /* 嵌套外链 */ herf?: string - /** 当前路由需要选中的菜单项(用于跳转至不在左侧菜单显示的路由且需要高亮某个菜单的情况) */ + /** 当前路由需要选中的菜单项,用于跳转至不在左侧菜单显示的路由且需要高亮某个菜单的情况 */ activeMenu?: string /** 当前路由是否会被添加到Tab中 */ withoutTab?: boolean @@ -34,9 +34,9 @@ declare namespace AppRoute { redirect?: string /* 页面组件地址 */ componentPath?: string | null - // 路由id + /* 路由id */ id: numnber - // 父级路由id,顶级页面为null + /* 父级路由id,顶级页面为null */ pid: number | null } @@ -44,6 +44,9 @@ declare namespace AppRoute { [K in keyof RouteMeta as `meta.${K}`]?: RouteMeta[K] } & baseRoute + /** + * 挂载到项目上的真实路由结构 + */ interface Route extends baseRoute { /** 子路由 */ children?: Route[] diff --git a/src/typings/service.d.ts b/src/typings/service.d.ts index 888fe56..3585416 100644 --- a/src/typings/service.d.ts +++ b/src/typings/service.d.ts @@ -20,7 +20,7 @@ declare namespace Service { successCode?: number | string } - type RequestErrorType = 'Response Error' | 'Business Error' + type RequestErrorType = 'Response Error' | 'Business Error' | null type RequestCode = string | number interface RequestError { @@ -33,4 +33,17 @@ declare namespace Service { /** 返回的数据 */ data?: any } + + interface ResponseResult extends RequestError { + /** 请求服务是否成功 */ + isSuccess: boolean + /** 请求服务的错误类型 */ + errorType: RequestErrorType + /** 错误码 */ + code: RequestCode + /** 错误信息 */ + msg: string + /** 返回的数据 */ + data: T + } } diff --git a/vercel.json b/vercel.json deleted file mode 100644 index afea4ae..0000000 --- a/vercel.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rewrites": [{ "source": "/:path*", "destination": "/index.html" }] -}