UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

87 lines (86 loc) 2.96 kB
"use strict"; const vue = require("vue"); const birdpaperIcon = require("birdpaper-icon"); const __default__ = vue.defineComponent({ name: "MessageList" }); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...__default__, props: { /** 消息ID Message id */ id: { type: String }, /** 消息提示类型 Message prompt type */ type: { type: String, default: "text" }, /** 消息提示内容 Message prompt content */ content: { type: String, default: "" }, /** 延迟关闭时间 Delayed shutdown time */ duration: { type: Number, default: 3e3 }, /** 是否允许手动关闭 Closeable or not */ closeable: { type: Boolean, default: false }, /** 是否开启无背景展示 */ plain: { type: Boolean, default: false }, /** 关闭后的回调函数 */ onClose: { type: Function } }, emits: ["remove"], setup(__props, { emit: emits }) { const props = __props; const name = "bp-message"; const timer = vue.ref(0); const iconType = { success: birdpaperIcon.IconCheckboxCircleFill, error: birdpaperIcon.IconCloseCircleFill, warning: birdpaperIcon.IconErrorWarningFill, loading: birdpaperIcon.IconLoader5Line }; const init = () => { if (props.duration > 0 && props.type !== "loading") { timer.value = window.setTimeout(handleClose, props.duration); } }; const clsName = vue.computed(() => { let cls = [name]; cls.push(props.plain ? `${name}-plain` : `${name}-${props.type}`); return cls; }); const clearTimer = () => { if (timer) { window.clearTimeout(timer.value); timer.value = 0; } }; const handleClose = () => { emits("remove", props.id); props.onClose && props.onClose(props.id); }; vue.onMounted(() => { vue.nextTick(() => init()); }); vue.onUnmounted(() => { clearTimer(); }); return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock("li", { class: vue.normalizeClass(clsName.value) }, [ __props.type !== "text" ? (vue.openBlock(), vue.createElementBlock("span", { key: 0, class: vue.normalizeClass([`${name}-icon`, `icon-${__props.type}`]) }, [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(iconType[__props.type]), { size: "18px" })) ], 2)) : vue.createCommentVNode("", true), vue.createElementVNode("span", { class: vue.normalizeClass(`${name}-content`) }, vue.toDisplayString(__props.content), 3), __props.closeable ? (vue.openBlock(), vue.createElementBlock("span", { key: 1, class: vue.normalizeClass(`${name}-close`), onClick: handleClose }, [ vue.createVNode(vue.unref(birdpaperIcon.IconCloseLine)) ], 2)) : vue.createCommentVNode("", true) ], 2); }; } }); module.exports = _sfc_main;