主动取消重复请求关闭loading
This commit is contained in:
@@ -32,16 +32,11 @@ axios.defaults.withCredentials = true //跨域携带cookie
|
||||
// request拦截器
|
||||
service.interceptors.request.use(
|
||||
(config: any) => {
|
||||
removePending(config)
|
||||
if (removePending(config) && config.loading) closeLoading()
|
||||
// 如果repeatRequest不配置,那么默认该请求就取消重复接口请求
|
||||
!config.repeatRequest && addPending(config)
|
||||
// 打开loading
|
||||
if (config.loading) {
|
||||
LoadingInstance._count++
|
||||
if (LoadingInstance._count === 1) {
|
||||
openLoading(config.loadingDom)
|
||||
}
|
||||
}
|
||||
if (config.loading) openLoading(config.loadingDom)
|
||||
// 如果登录了,有token,则请求携带token
|
||||
// Do something before request is sent
|
||||
const token = useUserInfoStore().state.token
|
||||
@@ -165,6 +160,7 @@ function removePending(config: any) {
|
||||
const cancelToken = pendingMap.get(pendingKey)
|
||||
cancelToken(pendingKey)
|
||||
pendingMap.delete(pendingKey)
|
||||
return true
|
||||
}
|
||||
}
|
||||
// ----------------------------------loading的函数-------------------------------
|
||||
@@ -172,7 +168,10 @@ const LoadingInstance: { _count: number } = {
|
||||
_count: 0
|
||||
}
|
||||
function openLoading(loadingDom: any) {
|
||||
LoadingInstance._count++
|
||||
// if(LoadingInstance._count === 1) {
|
||||
useGlobalStore().setLoading(true)
|
||||
// }
|
||||
}
|
||||
function closeLoading() {
|
||||
if (LoadingInstance._count > 0) LoadingInstance._count--
|
||||
|
||||
Reference in New Issue
Block a user