UNPKG

@ctsy/layui-vue

Version:

a component library for Vue 3 base on layui-vue

154 lines (153 loc) 5.46 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { defineComponent, ref, watch, computed, openBlock, createElementBlock, createVNode, unref, withCtx, createElementVNode, isRef } from "vue"; import _sfc_main$1 from "../button/index.js"; import "../input/index.js"; import "../icon/index.js"; import { _ as _sfc_main$2E } from "../icons-vue.es.js"; import { _ as _sfc_main$2 } from "../index5.js"; import "../vue-i18n.esm-bundler.js"; var index = ""; const _hoisted_1 = ["position", "size"]; const _hoisted_2 = { class: "layui-input-number-input" }; const __default__ = { name: "LayInputNumber" }; const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), { props: { modelValue: { default: 0 }, name: null, disabled: { type: Boolean, default: false }, disabledInput: { type: Boolean, default: false }, step: { default: 1 }, position: null, min: { default: -Infinity }, max: { default: Infinity }, size: null }, emits: ["update:modelValue", "change"], setup(__props, { emit }) { const props = __props; let num = ref(props.modelValue); watch(num, (val) => { if (props.max !== Infinity && val > props.max) { num.value = props.max; return; } if (props.min !== -Infinity && val < props.min) { num.value = props.min; return; } if (isNumber(num.value)) { tempValue.value = Number(num.value); emit("update:modelValue", tempValue.value); emit("change", tempValue.value); } }); watch(() => props.modelValue, (val) => { if (val !== num.value) { num.value = props.modelValue; } }); const tempValue = ref(0); let timer = 0; const minControl = computed(() => props.min !== -Infinity && Number(props.min) >= num.value); const maxControl = computed(() => props.max !== Infinity && Number(props.max) <= num.value); const addition = function() { num.value += Number(props.step); }; const subtraction = function() { num.value -= Number(props.step); }; const longDown = function(fn) { cancelLongDown(); if (props.disabled) { return; } timer = setInterval(() => fn.call(timer), 150); fn.call(timer); }; const cancelLongDown = function() { clearInterval(timer); }; const inputChange = function() { if (isNumber(num.value)) { tempValue.value = Number(num.value); return; } num.value = tempValue.value; }; const isNumber = function(num2) { return /^\d+(\.\d+)?$/.test(num2); }; return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: "layui-input-number", position: __props.position, size: __props.size }, [ createVNode(unref(_sfc_main$1), { size: "gl", onMousedown: _cache[0] || (_cache[0] = ($event) => longDown(subtraction)), onMouseup: cancelLongDown, onBlur: cancelLongDown, disabled: unref(minControl), class: "layui-control-btn layui-subtraction-btn" }, { default: withCtx(() => [ createVNode(unref(_sfc_main$2E), { type: __props.position === "right" ? "layui-icon-down" : "layui-icon-subtraction" }, null, 8, ["type"]) ]), _: 1 }, 8, ["disabled"]), createElementVNode("div", _hoisted_2, [ createVNode(unref(_sfc_main$2), { modelValue: unref(num), "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(num) ? num.value = $event : num = $event), readonly: __props.disabledInput || __props.disabled, type: "number", name: __props.name, onChange: inputChange }, null, 8, ["modelValue", "readonly", "name"]) ]), createVNode(unref(_sfc_main$1), { size: "gl", onMousedown: _cache[2] || (_cache[2] = ($event) => longDown(addition)), onMouseup: cancelLongDown, onBlur: cancelLongDown, disabled: unref(maxControl), class: "layui-control-btn layui-addition-btn" }, { default: withCtx(() => [ createVNode(unref(_sfc_main$2E), { type: __props.position === "right" ? "layui-icon-up" : "layui-icon-addition" }, null, 8, ["type"]) ]), _: 1 }, 8, ["disabled"]) ], 8, _hoisted_1); }; } })); _sfc_main.install = (app) => { app.component(_sfc_main.name, _sfc_main); }; export { _sfc_main as default };