globalLoading.js 678 B

123456789101112131415161718192021
  1. import Vue from 'vue'
  2. import store from '../../store'
  3. import { SET_SHOW_LOADING } from '../../store/modules/type'
  4. export function showLoading(info = '') {
  5. store.commit(`app/${SET_SHOW_LOADING}`, { flag: true, info })
  6. }
  7. export function hideLoading() {
  8. store.commit(`app/${SET_SHOW_LOADING}`, { flag: false, info: '' })
  9. }
  10. export function showLoadingAuto(info = '', time = 2000) {
  11. store.commit(`app/${SET_SHOW_LOADING}`, { flag: true, info })
  12. setTimeout(() => {
  13. store.commit(`app/${SET_SHOW_LOADING}`, { flag: false, info: '' })
  14. }, time)
  15. }
  16. Vue.prototype.$showLoading = showLoading
  17. Vue.prototype.$hideLoading = hideLoading
  18. Vue.prototype.$showLoadingAuto = showLoadingAuto