UNPKG

979 BJavaScriptView Raw
1/**
2 * @author SoldierAb
3 */
4
5import LoadingComp from "./src/Loading.vue";
6
7let LoadingInstance = null;
8
9const Loading = (Vue, opts) => {
10 if (!opts) opts = { background: "rgba(0,0,0,0.6)", color: "#4b9cdb" };
11 let { background, color } = opts;
12 if (!background) background = "rgba(0,0,0,0.6)";
13 if (!color) color = "#4b9cdb";
14 Vue.prototype.$loading = (showLoading, callback) => {
15 if (!LoadingInstance) {
16 const LoadingTpl = Vue.extend(LoadingComp);
17 LoadingInstance = new LoadingTpl();
18 LoadingInstance.background = background;
19 LoadingInstance.color = color;
20 const tpl = LoadingInstance.$mount().$el;
21 document.body.appendChild(tpl);
22 }
23 LoadingInstance.show = showLoading;
24 if (!callback) callback = new Function();
25 callback();
26 };
27 ["show", "hide"].forEach(item => {
28 return (Vue.prototype.$loading[`${item}`] = callback =>
29 Vue.prototype.$loading(item === "show", callback));
30 });
31};
32
33export default Loading;