@wfrog/vc
Version:
vue3 组件库 vc
83 lines (77 loc) • 2.94 kB
JavaScript
import './index.css'
import { defineComponent, useTemplateRef, computed, onMounted, createBlock, openBlock, unref, mergeProps, withCtx, createElementVNode, normalizeClass, createVNode } from 'vue';
import { ElSwitch, ElPopconfirm } from 'element-plus';
import { _ as _export_sfc } from '../../chunk/pcqpp-6-.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "switch",
props: {
modelValue: {},
confirmTitle: { default: "确认切换吗?" },
disabled: { type: Boolean, default: false },
className: { default: "" },
confirm: { type: Boolean, default: false },
confirmProps: {}
},
emits: ["update:modelValue"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const mainRef = useTemplateRef("mainRef");
function getSwitchEle() {
if (!mainRef.value) {
return;
}
const ele = mainRef.value.getElementsByClassName("h-switch")[0];
return ele;
}
const handleConfirm = () => getSwitchEle()?.click();
const myValue = computed({
get: () => props.modelValue,
set: (val) => emits("update:modelValue", val)
});
onMounted(() => {
getSwitchEle()?.addEventListener("click", (event) => {
event.stopPropagation();
});
});
return (_ctx, _cache) => {
return __props.disabled || !__props.confirm ? (openBlock(), createBlock(unref(ElSwitch), mergeProps({
key: 0,
modelValue: myValue.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => myValue.value = $event),
class: __props.className
}, _ctx.$attrs, { disabled: __props.disabled }), null, 16, ["modelValue", "class", "disabled"])) : (openBlock(), createBlock(unref(ElPopconfirm), mergeProps({
key: 1,
title: __props.confirmTitle
}, props.confirmProps, { onConfirm: handleConfirm }), {
reference: withCtx(() => [
createElementVNode("span", {
ref_key: "mainRef",
ref: mainRef,
class: normalizeClass(_ctx.$style.main)
}, [
createVNode(unref(ElSwitch), mergeProps({
modelValue: myValue.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => myValue.value = $event),
class: ["h-switch", __props.className]
}, _ctx.$attrs), null, 16, ["modelValue", "class"])
], 2)
]),
_: 1
}, 16, ["title"]));
};
}
});
/* unplugin-vue-components disabled */const main = "_main_5oj5r_1";
const style0 = {
main: main
};
const cssModules = {
"$style": style0
};
const Component = /* @__PURE__ */ _export_sfc(_sfc_main, [["__cssModules", cssModules]]);
const __vite_glob_0_28 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
__proto__: null,
default: Component
}, Symbol.toStringTag, { value: 'Module' }));
export { Component as C, __vite_glob_0_28 as _ };