mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-05-22 01:15:42 +08:00
fix: fecth type error
This commit is contained in:
parent
ca768ea228
commit
03ad287f43
@ -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,
|
||||
|
@ -6,14 +6,14 @@ interface Ilogin {
|
||||
}
|
||||
|
||||
export function fetchLogin(params: Ilogin) {
|
||||
const methodInstance = alovaInstance.Post<any>('/login', params)
|
||||
const methodInstance = alovaInstance.Post<Service.ResponseResult<ApiAuth.loginInfo>>('/login', params)
|
||||
methodInstance.meta = {
|
||||
authRole: null,
|
||||
}
|
||||
return methodInstance
|
||||
}
|
||||
export function fetchUpdateToken(params: any) {
|
||||
const method = alovaInstance.Post<ApiAuth.loginInfo>('/updateToken', params)
|
||||
const method = alovaInstance.Post<Service.ResponseResult<ApiAuth.loginInfo>>('/updateToken', params)
|
||||
method.meta = {
|
||||
authRole: 'refreshToken',
|
||||
}
|
||||
@ -21,5 +21,5 @@ export function fetchUpdateToken(params: any) {
|
||||
}
|
||||
|
||||
export function fetchUserRoutes(params: { id: number }) {
|
||||
return alovaInstance.Get<AppRoute.RowRoute[]>('/getUserRoutes', { params })
|
||||
return alovaInstance.Get<Service.ResponseResult<AppRoute.RowRoute[]> >('/getUserRoutes', { params })
|
||||
}
|
||||
|
@ -56,11 +56,12 @@ export function handleBusinessError(data: Record<string, any>, 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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
11
src/typings/route.d.ts
vendored
11
src/typings/route.d.ts
vendored
@ -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[]
|
||||
|
15
src/typings/service.d.ts
vendored
15
src/typings/service.d.ts
vendored
@ -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<T> extends RequestError {
|
||||
/** 请求服务是否成功 */
|
||||
isSuccess: boolean
|
||||
/** 请求服务的错误类型 */
|
||||
errorType: RequestErrorType
|
||||
/** 错误码 */
|
||||
code: RequestCode
|
||||
/** 错误信息 */
|
||||
msg: string
|
||||
/** 返回的数据 */
|
||||
data: T
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"rewrites": [{ "source": "/:path*", "destination": "/index.html" }]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user