UNPKG

yanzhen-design-vue

Version:

113 lines (112 loc) 3.63 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const vue = require("vue"); const antDesignVue = require("ant-design-vue"); const rangeNumber = require("./rangeNumber.cjs"); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...{ name: rangeNumber.rangeNumberName }, __name: "rangeNumber", props: rangeNumber.rangeNumberProps, emits: rangeNumber.rangeNumberEmits, setup(__props, { emit: __emit }) { const { ns } = rangeNumber.rangeNumberOptions; const props = __props; const emit = __emit; const state = vue.reactive({ min: "", max: "" }); const updateMinAndMaxValues = (value) => { if (value) { const values = value.split(","); if (values.length === 1) { const val = values[0]; state.min = val; state.max = val; } else { const minVal = values[0]; const maxVal = values[1]; state.min = minVal; state.max = maxVal; } } else { state.min = ""; state.max = ""; } }; vue.watch( () => props.value, () => { updateMinAndMaxValues(props.value); }, { immediate: true } ); const updateValueForInteger = (value) => { let result = value; if (value !== "" && typeof Number(value) === "number" && !Number.isNaN(Number(value)) && props.integer) { result = Number.parseInt(value); } return result; }; const onBlur = (type) => { const min = state.min; const max = state.max; if (type === "max" && max) { const precision = props.precision; if (precision) { state.max = Number.parseFloat(max).toFixed(precision); } } else if (type === "min" && min) { const precision = props.precision; if (precision) { state.min = Number.parseFloat(min).toFixed(precision); } } }; const onInputValue = (value, type) => { if (type === "max") { state.max = value; } else { state.min = value; } let max = state.max; let min = state.min; if (min === void 0 || min === null) { min = ""; } if (max === void 0 || max === null) { max = ""; } if (min === "" && max === "") { emit("update:value", ""); } else { min = updateValueForInteger(min); max = updateValueForInteger(max); emit("update:value", `${min},${max}`); updateMinAndMaxValues(`${min},${max}`); } }; return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock("div", { class: vue.normalizeClass([vue.unref(ns).b()]) }, [ vue.createVNode(vue.unref(antDesignVue.InputNumber), { value: state.min, placeholder: _ctx.placeholder, onBlur: _cache[0] || (_cache[0] = ($event) => onBlur("min")), onChange: _cache[1] || (_cache[1] = ($event) => onInputValue($event, "min")) }, null, 8, ["value", "placeholder"]), _cache[4] || (_cache[4] = vue.createElementVNode("span", { class: "separator" }, "~", -1)), vue.createVNode(vue.unref(antDesignVue.InputNumber), { value: state.max, placeholder: _ctx.placeholder, onBlur: _cache[2] || (_cache[2] = ($event) => onBlur("max")), onChange: _cache[3] || (_cache[3] = ($event) => onInputValue($event, "max")) }, null, 8, ["value", "placeholder"]) ], 2); }; } }); exports.default = _sfc_main;