ivue-material-plus
Version:
A high quality UI components Library with Vue.js
141 lines (138 loc) • 2.81 kB
JavaScript
import { createVNode, render } from 'vue';
import LoadingBar$1 from './index2.mjs';
let instances;
let color = "primary";
let failedColor = "error";
let height = 2;
let duration = 800;
let timer;
const newInstance = (options) => {
const vm = instances || createVNode(LoadingBar$1, options);
const container = document.createElement("div");
vm.props.onDestroy = () => {
render(null, container);
};
render(vm, container);
instances = vm;
document.body.appendChild(container.firstElementChild);
return {
update(options2) {
const data = vm.component.proxy.data;
if (options2.percent !== void 0) {
data.percent = options2.percent;
}
data.visible = options2.visible;
if (options2.status) {
data.status = options2.status;
}
},
component: vm,
destroy() {
document.body.removeChild(
document.getElementsByClassName("ivue-loading-bar")[0]
);
}
};
};
const getIvueLoadingBarInstance = () => {
instances = instances || newInstance({
color,
failedColor,
height
});
return instances;
};
const update = (options) => {
const instance = getIvueLoadingBarInstance();
instance.update(options);
};
const clearTimer = () => {
if (timer) {
clearInterval(timer);
timer = null;
}
};
const hide = () => {
setTimeout(() => {
update({
visible: false
});
setTimeout(() => {
update({
percent: 0
});
}, 500);
}, duration);
};
var LoadingBar = {
start() {
if (timer) {
return;
}
let percent = 0;
update({
percent,
status: "success",
visible: true
});
timer = setInterval(() => {
percent += Math.floor(Math.random() * 3 + 1);
if (percent > 95) {
clearTimer();
}
update({
percent,
status: "success",
visible: true
});
}, 200);
},
update(percent) {
clearTimer();
update({
percent,
status: "success",
visible: true
});
},
finish() {
clearTimer();
update({
percent: 100,
status: "success",
visible: true
});
hide();
},
error() {
clearTimer();
update({
percent: 100,
status: "error",
visible: true
});
hide();
},
config(options) {
if (options.color) {
color = options.color;
}
if (options.failedColor) {
failedColor = options.failedColor;
}
if (options.height) {
height = options.height;
}
if (options.duration) {
duration = options.duration;
}
},
destroy() {
clearTimer();
const _instance = getIvueLoadingBarInstance();
instances = null;
_instance.destroy();
}
};
export { LoadingBar as default };
//# sourceMappingURL=loading-bar.mjs.map