Blame view

src/utils/requestLoading.js 953 Bytes
任超 committed
1
import Loading from '@/components/Loading/index.js';
2 3 4 5
// 定义 loading 
let loading

// loading开始 方法
任超 committed
6
function startLoading (loadingText = '正在加载中...') {
7
  loading = Loading.service({
8
    text: loadingText,
任超 committed
9 10
    spinner: 'el-icon-loading',
    background: 'rgba(255, 255, 255, 0.5)',
任超 committed
11
    target: document.querySelector('.loadingtext')
12 13 14 15 16 17 18 19 20 21 22 23 24 25
  })
}

// loading结束 方法
function endLoading () {
  loading.close()
}
// 定义一个变量,有请求变量加一,收到响应变量减一
let loadingCount = 0

/**
 * 调用一次startLoadingAddCount() 方法 开启Loading 并 loadingCount + 1
 * 调用一次endLoadingSubCount() 方法 loadingCount - 1 直到为0 关闭loading
 */
任超 committed
26
export function startLoadingAddCount (LoadingText, target) {
27
  if (loadingCount === 0) {
任超 committed
28
    startLoading(LoadingText, target)
29 30 31 32 33 34 35 36 37 38
  }
  loadingCount++
}

export function endLoadingSubCount () {
  loadingCount--
  if (loadingCount === 0) {
    endLoading()
  }
}