@wfrog/vc
Version:
vue3 组件库 vc
138 lines (132 loc) • 4.97 kB
JavaScript
import './index.css'
import '../../chunk/E_WRn0OP.mjs';
import '../../chunk/D19ZZ4OA.mjs';
import { E as ElInputNumber } from '../../chunk/DGEkVwni.mjs';
import { defineComponent, useCssVars, useSlots, useCssModule, ref, useTemplateRef, computed, watch, onUnmounted, createElementBlock, openBlock, normalizeClass, unref, createCommentVNode, createBlock, renderSlot, mergeProps, isRef, createSlots, withCtx, nextTick } from 'vue';
import { _ as _export_sfc } from '../../chunk/pcqpp-6-.mjs';
const _hoisted_1 = {
key: 0,
class: "el-input-group__prepend"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "input-number",
props: {
modelValue: {},
precision: { default: 0 },
controlsPosition: {},
size: {},
inputNumberClass: {},
inputWidth: { default: "80px" }
},
emits: ["update:modelValue", "change", "blur"],
setup(__props, { emit: __emit }) {
useCssVars((_ctx) => ({
"v16e6e851": _ctx.inputWidth
}));
const props = __props;
const emits = __emit;
const $slots = useSlots();
const $style = useCssModule();
const visible = ref(true);
const inputNumberRef = useTemplateRef("inputNumberRef");
const mainClass = computed(() => {
const className = {
[$style["input-number"]]: true,
"el-input": true,
"el-input-group--prepend": $slots.prepend,
"input-with-select": inputNumberRef.value?.querySelector(".el-input-group__prepend>.el-select")
};
if (props.size) {
className[`el-input--${props.size}`] = true;
}
return className;
});
const myControlsPosition = computed(() => $slots.prepend && props.controlsPosition === void 0 ? "right" : props.controlsPosition);
const myValue = computed({
get: () => props.modelValue,
set: (val) => {
const myVal = val === null ? myValue.value : val;
emits("update:modelValue", myVal);
}
});
function limitInputValue(e) {
const key = e.key;
if (key === "e" || key === "E" || props.precision === 0 && key === ".") {
e.preventDefault();
return false;
}
return true;
}
function handleChange(currentValue, oldValue) {
myValue.value = currentValue === 0 ? currentValue : currentValue || oldValue || 0;
emits("change", myValue.value, oldValue || 0);
}
function rerender() {
visible.value = false;
nextTick(() => visible.value = true);
}
function handleBlur(e) {
const eleInput = inputNumberRef.value?.querySelector(".el-input__inner[type=number]");
if (eleInput.value === "") {
rerender();
}
emits("blur", e);
}
const watchHandler = watch(() => props.precision, (val) => val === 0 && rerender());
onUnmounted(() => watchHandler.stop());
return (_ctx, _cache) => {
const _component_ElInputNumber = ElInputNumber;
return openBlock(), createElementBlock("div", {
ref_key: "inputNumberRef",
ref: inputNumberRef,
class: normalizeClass(unref(mainClass))
}, [
unref($slots).prepend ? (openBlock(), createElementBlock("div", _hoisted_1, [
renderSlot(_ctx.$slots, "prepend")
])) : createCommentVNode("", true),
unref(visible) ? (openBlock(), createBlock(_component_ElInputNumber, mergeProps({
key: 1,
modelValue: unref(myValue),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(myValue) ? myValue.value = $event : null),
"step-strictly": "",
size: __props.size,
class: [__props.inputNumberClass, unref($style)["el-input-number"]],
precision: __props.precision,
"controls-position": unref(myControlsPosition)
}, _ctx.$attrs, {
onKeydown: limitInputValue,
onChange: handleChange,
onBlur: handleBlur
}), createSlots({ _: 2 }, [
unref($slots).prefix ? {
name: "prefix",
fn: withCtx(() => [
renderSlot(_ctx.$slots, "prefix")
]),
key: "0"
} : void 0,
unref($slots).suffix ? {
name: "suffix",
fn: withCtx(() => [
renderSlot(_ctx.$slots, "suffix")
]),
key: "1"
} : void 0
]), 1040, ["modelValue", "size", "class", "precision", "controls-position"])) : createCommentVNode("", true)
], 2);
};
}
});
/* unplugin-vue-components disabled */const style0 = {
"input-number": "_input-number_1piks_1",
"el-input-number": "_el-input-number_1piks_18"
};
const cssModules = {
"$style": style0
};
const Component = /* @__PURE__ */ _export_sfc(_sfc_main, [["__cssModules", cssModules]]);
const __vite_glob_0_20 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
__proto__: null,
default: Component
}, Symbol.toStringTag, { value: 'Module' }));
export { Component as C, __vite_glob_0_20 as _ };