@wfrog/vc
Version:
vue3 组件库 vc
312 lines (303 loc) • 11.8 kB
JavaScript
import './index.css'
import { c as buildProps, u as useNamespace } from '../../chunk/E_WRn0OP.mjs';
import { h as useTooltipTriggerProps, u as useTooltipContentProps, a as ElTooltip } from '../../chunk/DUd8IaU9.mjs';
/* empty css */
import { b as buttonTypes, E as ElButton } from '../../chunk/BT7IBuxS.mjs';
import { defineComponent, ref, computed, unref, createBlock, openBlock, mergeProps, withCtx, renderSlot, createCommentVNode, createElementVNode, normalizeClass, createTextVNode, normalizeStyle, resolveDynamicComponent, toDisplayString, createVNode, createElementBlock } from 'vue';
import { ElMessageBox } from 'element-plus';
import { i as injectConfig } from '../config-provider/config-provider2.mjs';
import { C as Component$1 } from '../icon/icon.mjs';
import { a as useThrottleFn } from '../../chunk/GvCnndsC.mjs';
import { E as ElIcon } from '../../chunk/m2vp1CCf.mjs';
import { QuestionFilled } from '@element-plus/icons-vue';
import { i as iconPropType } from '../icon/icon2.mjs';
import { _ as _export_sfc, w as withInstall } from '../../chunk/D389hx_T.mjs';
import { u as useLocale } from '../../chunk/-m34CPRn.mjs';
import { a as addUnit } from '../../chunk/CD1S5tP1.mjs';
import { _ as _export_sfc$1 } from '../../chunk/pcqpp-6-.mjs';
const popconfirmProps = buildProps({
title: String,
confirmButtonText: String,
cancelButtonText: String,
confirmButtonType: {
type: String,
values: buttonTypes,
default: "primary"
},
cancelButtonType: {
type: String,
values: buttonTypes,
default: "text"
},
icon: {
type: iconPropType,
default: () => QuestionFilled
},
iconColor: {
type: String,
default: "#f90"
},
hideIcon: Boolean,
hideAfter: {
type: Number,
default: 200
},
effect: {
...useTooltipContentProps.effect,
default: "light"
},
teleported: useTooltipContentProps.teleported,
persistent: useTooltipContentProps.persistent,
width: {
type: [String, Number],
default: 150
},
virtualTriggering: useTooltipTriggerProps.virtualTriggering,
virtualRef: useTooltipTriggerProps.virtualRef
});
const popconfirmEmits = {
confirm: (e) => e instanceof MouseEvent,
cancel: (e) => e instanceof MouseEvent
};
const __default__ = defineComponent({
name: "ElPopconfirm"
});
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
...__default__,
props: popconfirmProps,
emits: popconfirmEmits,
setup(__props, { expose, emit }) {
const props = __props;
const { t } = useLocale();
const ns = useNamespace("popconfirm");
const tooltipRef = ref();
const rootRef = ref();
const popperRef = computed(() => {
var _a;
return (_a = unref(tooltipRef)) == null ? void 0 : _a.popperRef;
});
const showPopper = () => {
var _a, _b;
(_b = (_a = rootRef.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
};
const hidePopper = () => {
var _a, _b;
(_b = (_a = tooltipRef.value) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a);
};
const style = computed(() => {
return {
width: addUnit(props.width)
};
});
const confirm = (e) => {
emit("confirm", e);
hidePopper();
};
const cancel = (e) => {
emit("cancel", e);
hidePopper();
};
const finalConfirmButtonText = computed(() => props.confirmButtonText || t("el.popconfirm.confirmButtonText"));
const finalCancelButtonText = computed(() => props.cancelButtonText || t("el.popconfirm.cancelButtonText"));
expose({
popperRef,
hide: hidePopper
});
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(ElTooltip), mergeProps({
ref_key: "tooltipRef",
ref: tooltipRef,
trigger: "click",
effect: _ctx.effect
}, _ctx.$attrs, {
"popper-class": `${unref(ns).namespace.value}-popover`,
"popper-style": unref(style),
teleported: _ctx.teleported,
"fallback-placements": ["bottom", "top", "right", "left"],
"hide-after": _ctx.hideAfter,
persistent: _ctx.persistent,
loop: "",
onShow: showPopper
}), {
content: withCtx(() => [
createElementVNode("div", {
ref_key: "rootRef",
ref: rootRef,
tabindex: "-1",
class: normalizeClass(unref(ns).b())
}, [
createElementVNode("div", {
class: normalizeClass(unref(ns).e("main"))
}, [
!_ctx.hideIcon && _ctx.icon ? (openBlock(), createBlock(unref(ElIcon), {
key: 0,
class: normalizeClass(unref(ns).e("icon")),
style: normalizeStyle({ color: _ctx.iconColor })
}, {
default: withCtx(() => [
(openBlock(), createBlock(resolveDynamicComponent(_ctx.icon)))
]),
_: 1
}, 8, ["class", "style"])) : createCommentVNode("v-if", true),
createTextVNode(" " + toDisplayString(_ctx.title), 1)
], 2),
createElementVNode("div", {
class: normalizeClass(unref(ns).e("action"))
}, [
renderSlot(_ctx.$slots, "actions", {
confirm,
cancel
}, () => [
createVNode(unref(ElButton), {
size: "small",
type: _ctx.cancelButtonType === "text" ? "" : _ctx.cancelButtonType,
text: _ctx.cancelButtonType === "text",
onClick: cancel
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(finalCancelButtonText)), 1)
]),
_: 1
}, 8, ["type", "text"]),
createVNode(unref(ElButton), {
size: "small",
type: _ctx.confirmButtonType === "text" ? "" : _ctx.confirmButtonType,
text: _ctx.confirmButtonType === "text",
onClick: confirm
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(finalConfirmButtonText)), 1)
]),
_: 1
}, 8, ["type", "text"])
])
], 2)
], 2)
]),
default: withCtx(() => [
_ctx.$slots.reference ? renderSlot(_ctx.$slots, "reference", { key: 0 }) : createCommentVNode("v-if", true)
]),
_: 3
}, 16, ["effect", "popper-class", "popper-style", "teleported", "hide-after", "persistent"]);
};
}
});
var Popconfirm = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__file", "popconfirm.vue"]]);
const ElPopconfirm = withInstall(Popconfirm);
const _hoisted_1 = { key: 1 };
const _hoisted_2 = { key: 1 };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "button",
props: {
icon: {},
time: { default: 800 },
type: { default: "" },
confirm: { default: void 0 }
},
emits: ["click"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const { button: buttonConfig } = injectConfig();
const defaultConfirmInfo = { title: "提示", confirmButtonText: "确定", cancelButtonText: "取消", msg: "请确认您的操作" };
const myConfirm = computed(() => buttonConfig?.confirm?.type !== void 0 ? buttonConfig?.confirm?.type : props.confirm?.type !== void 0 ? props.confirm.type : ["danger", "warning"].includes(props.type) ? "messagebox" : void 0);
const { name, type: iconType = "el", position = "left" } = props.icon || {};
const { msg, title, confirmButtonText, cancelButtonText } = { ...defaultConfirmInfo, ...buttonConfig?.confirm, ...props.confirm };
async function handleComfirm() {
try {
const result = await ElMessageBox.confirm(msg, title, { confirmButtonText, cancelButtonText, type: "warning", dangerouslyUseHTMLString: true });
return result;
} catch {
return false;
}
}
const handleClick = useThrottleFn(async (e) => {
if (myConfirm.value === "messagebox") {
const result = await handleComfirm();
result && emits("click", e);
return;
}
if (myConfirm.value === "popconfirm") {
return;
}
emits("click", e);
}, props.time);
const handleConfirm = useThrottleFn(async (e) => {
emits("click", e);
}, props.time);
return (_ctx, _cache) => {
const _component_ElButton = ElButton;
const _component_ElPopconfirm = ElPopconfirm;
return unref(myConfirm) === "popconfirm" ? (openBlock(), createBlock(_component_ElPopconfirm, {
key: 0,
title: unref(msg),
"confirm-button-text": unref(confirmButtonText),
"cancel-button-text": unref(cancelButtonText),
"popper-class": `${_ctx.$style.popper} el-popover`,
onConfirm: unref(handleConfirm)
}, {
reference: withCtx(() => [
createVNode(_component_ElButton, mergeProps(_ctx.$attrs, {
type: __props.type,
class: _ctx.$style.button,
onClick: unref(handleClick)
}), {
default: withCtx(() => [
unref(position) === "left" && unref(name) ? (openBlock(), createBlock(Component$1, {
key: 0,
type: unref(iconType),
name: unref(name)
}, null, 8, ["type", "name"])) : createCommentVNode("", true),
_ctx.$slots.default ? (openBlock(), createElementBlock("span", _hoisted_1, [
renderSlot(_ctx.$slots, "default")
])) : createCommentVNode("", true),
unref(position) === "right" && unref(name) ? (openBlock(), createBlock(Component$1, {
key: 2,
type: unref(iconType),
name: unref(name)
}, null, 8, ["type", "name"])) : createCommentVNode("", true)
]),
_: 3
}, 16, ["type", "class", "onClick"])
]),
_: 3
}, 8, ["title", "confirm-button-text", "cancel-button-text", "popper-class", "onConfirm"])) : (openBlock(), createBlock(_component_ElButton, mergeProps({ key: 1 }, _ctx.$attrs, {
type: __props.type,
class: _ctx.$style.button,
onClick: unref(handleClick)
}), {
default: withCtx(() => [
unref(position) === "left" && unref(name) ? (openBlock(), createBlock(Component$1, {
key: 0,
type: unref(iconType),
name: unref(name)
}, null, 8, ["type", "name"])) : createCommentVNode("", true),
_ctx.$slots.default ? (openBlock(), createElementBlock("span", _hoisted_2, [
renderSlot(_ctx.$slots, "default")
])) : createCommentVNode("", true),
unref(position) === "right" && unref(name) ? (openBlock(), createBlock(Component$1, {
key: 2,
type: unref(iconType),
name: unref(name)
}, null, 8, ["type", "name"])) : createCommentVNode("", true)
]),
_: 3
}, 16, ["type", "class", "onClick"]));
};
}
});
/* unplugin-vue-components disabled */const button = "_button_1dzv7_1";
const popper = "_popper_1dzv7_5";
const style0 = {
button: button,
popper: popper
};
const cssModules = {
"$style": style0
};
const Component = /* @__PURE__ */ _export_sfc$1(_sfc_main, [["__cssModules", cssModules]]);
const __vite_glob_0_2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
__proto__: null,
default: Component
}, Symbol.toStringTag, { value: 'Module' }));
export { Component as C, __vite_glob_0_2 as _ };