various-ui
Version:
This is a test version of the Vue 3 component library
67 lines (64 loc) • 2.31 kB
JavaScript
import { createApp } from 'vue';
import '../../constants/index.mjs';
import '../../utils/index.mjs';
import UiLoading from '../../constants/components/loading/src/loading.vue.mjs';
import { scrollbarHidden } from '../../utils/src/node/index.mjs';
const show = (config) => {
var _a;
const body = document.body;
if (body.instance) {
if (config == null ? void 0 : config.icon) body.instance.$.props.icon = config.icon;
if (config == null ? void 0 : config.message) body.instance.$.props.message = config.message;
} else {
const app = createApp(UiLoading, Object.assign({ visible: false, mode: "fixed" }, config));
const instance = app.mount(document.createElement("div"));
if (body.style.position == "") body.classList.add("ui-relative");
body.app = app;
body.instance = instance;
body.appendChild(instance.$el);
}
if (!((_a = body.instance) == null ? void 0 : _a.$.props.visible)) {
$loading.spacing = { x: document.body.style.paddingRight, y: document.body.style.paddingBottom };
$loading.overflow = document.body.style.overflow;
scrollbarHidden({ unit: config == null ? void 0 : config.unit });
}
body.instance.$.props.visible = true;
};
const hidden = () => {
const body = document.body;
document.body.style.overflow = $loading.overflow;
document.body.style.paddingRight = $loading.spacing.x;
document.body.style.paddingBottom = $loading.spacing.y;
if (body.instance) {
body.instance.$.props.visible = false;
}
};
const $loading = {
delay: false,
//* 是否延迟关闭
timer: void 0,
//* 定时器
spacing: { x: "", y: "" },
//* 内间距属性
overflow: "",
//* overflow属性
//* Loading 激活函数
open: function(config) {
this.timer && clearTimeout(this.timer);
if (!(config == null ? void 0 : config.delay)) show(config);
else {
this.timer = setTimeout(() => (show(config), this.delay = true), config.delay);
}
},
//* Loading 关闭函数
close: function(config) {
this.timer && clearTimeout(this.timer);
if (!this.delay) return hidden();
else {
this.delay = false;
this.timer = setTimeout(() => hidden(), (config == null ? void 0 : config.delay) || 200);
}
}
};
export { $loading, $loading as default };
//# sourceMappingURL=index.mjs.map