import Vue from 'vue'

import {
    LoadingPlugin
} from 'vux'

Vue.use(LoadingPlugin)

let loadingCount = 0

const startLoading = () => {
    Vue.$vux.loading.show({
        text: '数据加载中'
    })
}

const endLoading = () => {
    Vue.$vux.loading.hide()
}

export const showLoading = () => {
    if (loadingCount === 0) {
        startLoading()
    }
    loadingCount += 1
}

export const hideLoading = () => {
    if (loadingCount <= 0) {
        return
    }
    loadingCount -= 1
    if (loadingCount === 0) {
        endLoading()
    }
}
