// loading.js
import { Loading } from 'element-ui';
import store from '@/store/index.js';
/**
* 展示遮罩层
* @param {*} text 遮罩层显示的文本信息
*/
export const showLoading = (text) => {
// 先进行关闭
hideLoading()
// 创建遮罩层
let loadingInstance = Loading.service(
{
text : text,
lock: true,
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
}
);
// 定义全局
store.commit("SET_LOADING_INSTANCE", loadingInstance);
}
/**
* 隐藏遮罩层
*/
export const hideLoading = () => {
// 隐藏 loading 的逻辑
let loadingInstance = store.getters.loadingInstance
if (loadingInstance && loadingInstance != null) {
loadingInstance.close();
store.commit("SET_LOADING_INSTANCE", null);
}
}