@opensig/opendesign
Version:
77 lines (76 loc) • 2.17 kB
JavaScript
;
const vue = require("vue");
const is = require("../_utils/is.js");
const types = require("./types.js");
const _hoisted_1 = {
key: 0,
class: "o-toast"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "OToast",
props: types.toastProps,
emits: ["duration-end", "close", "update:visible"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const innerIsVisible = vue.ref(props.visible ?? props.defaultVisible);
const isVisible = vue.computed(() => props.visible ?? innerIsVisible.value);
const emits = __emit;
let timer = 0;
const clearTimer = () => {
if (timer) {
window.clearTimeout(timer);
timer = 0;
}
};
const startTimer = () => {
if (is.isUndefined(props.duration) || props.duration <= 0) {
return;
}
timer = window.setTimeout(() => {
emits("duration-end");
innerIsVisible.value = false;
emits("update:visible", innerIsVisible.value);
clearTimer();
}, props.duration);
};
const onClose = async (ev) => {
ev == null ? void 0 : ev.stopPropagation();
if (is.isFunction(props.beforeClose)) {
const rlt = await props.beforeClose();
if (rlt) {
innerIsVisible.value = false;
emits("update:visible", innerIsVisible.value);
emits("close", ev);
return;
}
}
innerIsVisible.value = false;
emits("update:visible", innerIsVisible.value);
emits("close", ev);
};
vue.onMounted(() => {
startTimer();
});
vue.onUnmounted(() => {
clearTimer();
});
__expose({
/**
* 关闭即时反馈
*/
close: onClose
});
return (_ctx, _cache) => {
return isVisible.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
vue.renderSlot(_ctx.$slots, "default", {}, () => [
vue.createTextVNode(
vue.toDisplayString(_ctx.message),
1
/* TEXT */
)
])
])) : vue.createCommentVNode("v-if", true);
};
}
});
module.exports = _sfc_main;