驾驶舱报表&指标填报&接口添加loading
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import {Message, MessageBox, Notification} from 'element-ui'
|
||||
import {Message, MessageBox, Notification, Loading} from 'element-ui'
|
||||
import store from '@/store'
|
||||
import {getAccessToken, getRefreshToken, getTenantId, setToken, getVisitTenantId} from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
@@ -31,8 +31,36 @@ const service = axios.create({
|
||||
// 禁用 Cookie 等信息
|
||||
withCredentials: false,
|
||||
})
|
||||
|
||||
|
||||
let loadingInstance = null
|
||||
function startLoading() {
|
||||
loadingInstance = Loading.service({
|
||||
fullscreen: false,
|
||||
text: '拼命加载中...',
|
||||
background: 'rgba(0, 0, 0, 0.1)'
|
||||
})
|
||||
}
|
||||
function endLoading() {
|
||||
loadingInstance.close()
|
||||
}
|
||||
let needLoadingRequestCount = 0
|
||||
function showFullScreenLoading() {
|
||||
if (needLoadingRequestCount === 0) {
|
||||
startLoading()
|
||||
}
|
||||
needLoadingRequestCount++
|
||||
}
|
||||
function tryHideFullScreenLoading() {
|
||||
if (needLoadingRequestCount <= 0) return
|
||||
needLoadingRequestCount--
|
||||
if (needLoadingRequestCount === 0) {
|
||||
endLoading()
|
||||
}
|
||||
}
|
||||
// request拦截器
|
||||
service.interceptors.request.use(config => {
|
||||
showFullScreenLoading()
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
if (getAccessToken() && !isToken) {
|
||||
@@ -88,12 +116,14 @@ service.interceptors.request.use(config => {
|
||||
}
|
||||
return config
|
||||
}, error => {
|
||||
tryHideFullScreenLoading()
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(async res => {
|
||||
tryHideFullScreenLoading()
|
||||
let { data } = res
|
||||
// 未设置状态码则默认成功状态
|
||||
// 二进制数据则直接返回,例如说 Excel 导出
|
||||
@@ -202,6 +232,7 @@ service.interceptors.response.use(async res => {
|
||||
}
|
||||
}, error => {
|
||||
console.log('err' + error)
|
||||
tryHideFullScreenLoading()
|
||||
let {message} = error;
|
||||
if (message === "Network Error") {
|
||||
message = "后端接口连接异常";
|
||||
|
||||
Reference in New Issue
Block a user