1 line
9.5 KiB
Plaintext
1 line
9.5 KiB
Plaintext
|
{"version":3,"file":"wd-input-number.js","sources":["../../../../../../../node_modules/wot-design-uni/components/wd-input-number/wd-input-number.vue","../../../../../../../uniComponent:/RDovQXBwL1dvcmsvYWRkci9hY2RyLXVpL25vZGVfbW9kdWxlcy93b3QtZGVzaWduLXVuaS9jb21wb25lbnRzL3dkLWlucHV0LW51bWJlci93ZC1pbnB1dC1udW1iZXIudnVl"],"sourcesContent":["<template>\n <view :class=\"`wd-input-number ${customClass} ${disabled ? 'is-disabled' : ''} ${withoutInput ? 'is-without-input' : ''}`\" :style=\"customStyle\">\n <view :class=\"`wd-input-number__action ${minDisabled || disableMinus ? 'is-disabled' : ''}`\" @click=\"sub\">\n <wd-icon name=\"decrease\" custom-class=\"wd-input-number__action-icon\"></wd-icon>\n </view>\n <view v-if=\"!withoutInput\" class=\"wd-input-number__inner\" @click.stop=\"\">\n <input\n class=\"wd-input-number__input\"\n :style=\"`${inputWidth ? 'width: ' + inputWidth : ''}`\"\n type=\"digit\"\n :disabled=\"disabled || disableInput\"\n v-model=\"inputValue\"\n :placeholder=\"placeholder\"\n @input=\"handleInput\"\n @focus=\"handleFocus\"\n @blur=\"handleBlur\"\n />\n <view class=\"wd-input-number__input-border\"></view>\n </view>\n <view :class=\"`wd-input-number__action ${maxDisabled || disablePlus ? 'is-disabled' : ''}`\" @click=\"add\">\n <wd-icon name=\"add\" custom-class=\"wd-input-number__action-icon\"></wd-icon>\n </view>\n </view>\n</template>\n\n<script lang=\"ts\">\nexport default {\n name: 'wd-input-number',\n options: {\n virtualHost: true,\n addGlobalClass: true,\n styleIsolation: 'shared'\n }\n}\n</script>\n\n<script lang=\"ts\" setup>\nimport { ref, watch } from 'vue'\nimport { debounce, isDef, isEqual } from '../common/util'\nimport { inputNumberProps } from './types'\n\nconst props = defineProps(inputNumberProps)\nconst emit = defineEmits(['focus', 'blur', 'change', 'update:modelValue'])\n\nconst minDisabled = ref<boolean>(false)\nconst maxDisabled = ref<boolean>(false)\nconst inputValue = ref<string | number>('') // 输入框的值\n\nwatch(\n () => props.modelValue,\n (newValue) => {\n inputValue.value = newValue\n splitDisabled(newValue)\n },\n { immediate: true, deep: true }\n)\n\nwatch(\n [() => props.max, () => props.min],\n () => {\n updateBoundary()\n },\n { immediate: true, deep: true }\n)\n\nwatch(\n () => props.disabled,\n (newValue) => {\n minDisabled.value = newValue\n maxDisabled.value = newValue\n },\n { immediate: true, deep: true }\n)\n\nfunction updateBoundary() {\n debounce(() => {\n const value = formatValue(inputValue.value)\n if (!isEqual(inputValue.value, value)) {\n setValue(value)\n }\n splitDisabled(value)\n }, 30)()\n}\n\nfunction splitDisabled(value: number | string) {\n const { disabled, min, max, step } = props\n minDisabled.value = disabled || Number(value) <= min || changeStep(value, -step) < min\n maxDisabled.value = disabled || Number(value) >= max || changeStep(value, step) > max\n}\n\nfunction toPrecision(value: number) {\n return Number(parseFloat(`${Math.round(value * Math.pow(10, props.precision)) / Math.pow(10, props.precision)}`).toFixed(props.precision))\n}\n\nfunction getPrecision(value?: number) {\n if (value === undefined) return 0\n const valueString = value.toString()\n const dotPosition = valueString.indexOf('.')\n let precision = 0\n if (dotPosition !== -1) {\n precision = valueString.length - dotPosition - 1\n }\n return precision\n}\n\nfunction toStrictlyStep(value: number | string) {\n const stepPrecision = getPrecision(props.step)\n const precisionFactory = Math.pow(10, stepPrecision)\n return (Math.round(Number(value) / props.step) * precisionFactory * props.step) / precisionFactory\n}\n\nfunction setValue(value: string | number, change: boolean = true) {\n if (props.allowNull && (!isDef(value) || value === '')) {\n dispatchChangeEvent(value, change)\n return\n }\n\n if (props.stepStrictly) {\n value = toStrictlyStep(value)\n }\n if ((value || value =
|