mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
web端优化数据加载
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user