loading增加定制属性,可自行配置 (#1683)

* feature:增加区域loading功能

* feature:增加修改loading配置
This commit is contained in:
奇淼(piexlmax
2024-03-20 10:44:21 +08:00
committed by GitHub
parent d4db16b501
commit d4b9c2c97b
5 changed files with 25 additions and 30 deletions
+10 -5
View File
@@ -1,8 +1,8 @@
import axios from 'axios' // 引入axios
import { ElMessage, ElMessageBox } from 'element-plus'
import { useUserStore } from '@/pinia/modules/user'
import { emitter } from '@/utils/bus.js'
import router from '@/router/index'
import { ElLoading } from 'element-plus'
const service = axios.create({
baseURL: import.meta.env.VITE_BASE_API,
@@ -10,14 +10,19 @@ const service = axios.create({
})
let activeAxios = 0
let timer
const showLoading = () => {
let loadingInstance
const showLoading = (option = {
target: null,
}) => {
const loadDom = document.getElementById('gva-base-load-dom')
activeAxios++
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
if (activeAxios > 0) {
emitter.emit('showLoading')
if (!option.target) option.target = loadDom
loadingInstance = ElLoading.service(option)
}
}, 400)
}
@@ -26,14 +31,14 @@ const closeLoading = () => {
activeAxios--
if (activeAxios <= 0) {
clearTimeout(timer)
emitter.emit('closeLoading')
loadingInstance && loadingInstance.close()
}
}
// http request 拦截器
service.interceptors.request.use(
config => {
if (!config.donNotShowLoading) {
showLoading()
showLoading(config.loadingOption)
}
const userStore = useUserStore()
config.headers = {