You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
33 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, ref, reactive, computed, watch, onMounted, onUpdated, openBlock, createElementBlock, normalizeClass, unref, withModifiers, withDirectives, withKeys, renderSlot, createVNode, withCtx, createBlock, createCommentVNode, createSlots } from 'vue';\nimport { isNil } from 'lodash-unified';\nimport { ElInput } from '../../input/index.mjs';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { ArrowDown, Minus, ArrowUp, Plus } from '@element-plus/icons-vue';\nimport { inputNumberProps, inputNumberEmits } from './input-number.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { vRepeatClick } from '../../../directives/repeat-click/index.mjs';\nimport { useLocale } from '../../../hooks/use-locale/index.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useFormItem } from '../../form/src/hooks/use-form-item.mjs';\nimport { isNumber, isUndefined } from '../../../utils/types.mjs';\nimport { debugWarn, throwError } from '../../../utils/error.mjs';\nimport { useFormSize, useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';\nimport { UPDATE_MODEL_EVENT, INPUT_EVENT, CHANGE_EVENT } from '../../../constants/event.mjs';\nimport { isString } from '@vue/shared';\nimport { isFirefox } from '../../../utils/browser.mjs';\nconst __default__ = defineComponent({\n name: \"ElInputNumber\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: inputNumberProps,\n emits: inputNumberEmits,\n setup(__props, {\n expose,\n emit\n }) {\n const props = __props;\n const {\n t\n } = useLocale();\n const ns = useNamespace(\"input-number\");\n const input = ref();\n const data = reactive({\n currentValue: props.modelValue,\n userInput: null\n });\n const {\n formItem\n } = useFormItem();\n const minDisabled = computed(() => isNumber(props.modelValue) && props.modelValue <= props.min);\n const maxDisabled = computed(() => isNumber(props.modelValue) && props.modelValue >= props.max);\n const numPrecision = computed(() => {\n const stepPrecision = getPrecision(props.step);\n if (!isUndefined(props.precision)) {\n if (stepPrecision > props.precision) {\n debugWarn(\"InputNumber\", \"precision should not be less than the decimal places of step\");\n }\n return props.precision;\n } else {\n return Math.max(getPrecision(props.modelValue), stepPrecision);\n }\n });\n const controlsAtRight = computed(() => {\n return props.controls && props.controlsPosition === \"right\";\n });\n const inputNumberSize = useFormSize();\n const inputNumberDisabled = useFormDisabled();\n const displayValue = computed(() => {\n if (data.userInput !== null) {\n return data.userInput;\n }\n let currentValue = data.currentValue;\n if (isNil(currentValue)) return \"\";\n if (isNumber(currentValue)) {\n if (Number.isNaN(currentValue)) return \"\";\n if (!isUndefined(props.precision)) {\n currentValue = currentValue.toFixed(props.precision);\n }\n }\n return currentValue;\n });\n const toPrecision = (num, pre) => {\n if (isUndefined(pre)) pre = numPrecision.value;\n if (pre === 0) return Math.round(num);\n let snum = String(num);\n const pointPos = snum.indexOf(\".\");\n if (pointPos === -1) return num;\n const nums = snum.replace(\".\", \"\").split(\"\");\n const datum = nums[pointPos + pre];\n if (!datum) return num;\n const length = snum.length;\n if (snum.charAt(length - 1) === \"5\") {\n snum = `${snum.slice(0, Math.max(0, length - 1))}6`;\n }\n return Number.parseFloat(Number(snum).toFixed(pre));\n };\n const getPrecision = value => {\n if (isNil(value)) return 0;\n const valueString = value.toString();\n const dotPosition = valueString.indexOf(\".\");\n let precision = 0;\n if (dotPosition !== -1) {\n