web端优化数据加载

This commit is contained in:
Xwite
2024-10-15 14:55:40 +08:00
parent b326d2a3c0
commit 123d9b48bb
21 changed files with 197 additions and 139 deletions

View File

@@ -1,16 +1,12 @@
import type { AxiosResponse } from 'axios'
import type { LeagdoApiResponse } from './api'
import API, {
setWebsocketOnError,
legado_http_entry_point,
legado_webSocket_entry_point,
setApiEntryPoint,
} from './api'
import API, { setWebsocketOnError, setApiEntryPoint } from './api'
import ajax from './axios'
import { validatorHttpUrl } from '@/utils/utils'
const LeagdoApiResponseKeys: string[] = Array.of('isSuccess', 'errorMsg')
const notification = ElMessage
/** Axios.Interceptor: check if resp is LeagaoLeagdoApiResponse*/
const responseCheckInterceptor = (resp: AxiosResponse) => {
let isLeagdoApiResponse = true
@@ -26,21 +22,23 @@ const responseCheckInterceptor = (resp: AxiosResponse) => {
if ((data as LeagdoApiResponse<unknown>).isSuccess === true) {
if (!('data' in data)) {
isLeagdoApiResponse = false
LeagdoApiResponseKeys.length = 0
}
}
} catch {
isLeagdoApiResponse = false
}
if (isLeagdoApiResponse === false) {
ElNotification.warning('后端返回内容格式错误')
notification.warning({ message: '后端返回内容格式错误', grouping: true })
throw new Error()
}
return resp
}
const axiosErrorInterceptor = (err: unknown) => {
ElNotification.error('后端连接失败请检查阅读WEB服务或者设置其它可用链接')
notification.error({
message: '后端连接失败请检查阅读WEB服务或者设置其它可用链接',
grouping: true,
})
throw err
}
// http全局
@@ -80,8 +78,8 @@ export const parseLeagdoHttpUrlWithDefault = (
console.info('legado_api_config:')
console.table({
'http API入口': legado_http_entry_point,
'webSocket API入口': legado_webSocket_entry_point,
'http API入口': http_entry_point,
'webSocket API入口': webSocket_entry_point,
})
return [http_entry_point, webSocket_entry_point]
}