UNPKG

birdpaper-ui

Version:

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

62 lines (61 loc) 1.77 kB
"use strict"; const vue = require("vue"); const clickOutside = require("../../directives/clickOutside.js"); const birdpaperIcon = require("birdpaper-icon"); const _sfc_main = vue.defineComponent({ name: "Popconfirm", props: { /**确认框文本内容 */ content: { type: String, default: "" }, /** 类型 */ type: { type: String, default: "info" }, /** 弹出位置 */ position: { type: String, default: "top" }, /** 确认按钮文本 */ okText: { type: String, default: "确认" }, /** 取消按钮文本 */ cancleText: { type: String, default: "取消" }, /** 触发确定前的回调,返回 false 则中断 */ onBeforeOk: { type: Function, default: () => true } }, directives: { clickOutside: clickOutside.vClickOutside }, emits: ["ok", "cancle"], setup(props, { emit }) { const name = "bp-popconfirm"; const show = vue.ref(false); const iconType = { info: birdpaperIcon.IconInformationFill, success: birdpaperIcon.IconCheckboxCircleFill, error: birdpaperIcon.IconCloseCircleFill, warning: birdpaperIcon.IconErrorWarningFill }; const handleCancle = () => { show.value = false; emit("cancle"); }; const okLoading = vue.ref(false); const handleOk = async () => { try { okLoading.value = true; const res = await props.onBeforeOk(); if (!res) return; show.value = false; emit("ok"); } catch (error) { console.log("[ Popconfirm -onBeforeOk error]", error); } finally { okLoading.value = false; } }; return { name, show, okLoading, iconType, handleCancle, handleOk }; } }); module.exports = _sfc_main;