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 === 0) && props.precision !== undefined) {\n value = toPrecision(Number(value))\n }\n if (Number(value) > props.max) value = toPrecision(props.max)\n if (Number(value) < props.min) value = toPrecision(props.min)\n\n dispatchChangeEvent(value, change)\n}\n\nfunction changeStep(val: string | number, step: number) {\n val = Number(val)\n\n if (isNaN(val)) {\n return props.min\n }\n\n const precisionFactory = Math.pow(10, props.precision)\n return toPrecision((val * precisionFactory + step * precisionFactory) / precisionFactory)\n}\n\nfunction sub() {\n if (minDisabled.value || props.disableMinus) return\n\n const newValue = changeStep(inputValue.value, -props.step)\n dispatchChangeEvent(newValue)\n}\n\nfunction add() {\n if (maxDisabled.value || props.disablePlus) return\n\n const newValue = changeStep(inputValue.value, props.step)\n dispatchChangeEvent(newValue)\n}\n\nfunction handleInput(event: any) {\n const value = event.detail.value || ''\n dispatchChangeEvent(value)\n}\n\nfunction handleFocus(event: any) {\n emit('focus', event.detail)\n}\n\nfunction handleBlur() {\n const value = formatValue(inputValue.value)\n if (!isEqual(inputValue.value, value)) {\n setValue(value)\n }\n emit('blur', {\n value\n })\n}\n\nfunction dispatchChangeEvent(value: string | number, change: boolean = true) {\n if (isEqual(inputValue.value, value)) {\n return\n }\n inputValue.value = value\n change && emit('update:modelValue', inputValue.value)\n change && emit('change', { value })\n}\n\nfunction formatValue(value: string | number) {\n if (props.allowNull && (!isDef(value) || value === '')) {\n return ''\n }\n\n value = Number(value)\n\n if (isNaN(value)) {\n value = props.min\n }\n\n if (props.stepStrictly) {\n value = toStrictlyStep(value)\n }\n\n if (props.precision !== undefined) {\n value = value.toFixed(props.precision)\n }\n\n return Number(value)\n}\n</script>\n\n<style lang=\"scss\" scoped>\n@import './index.scss';\n</style>\n","import Component from 'D:/App/Work/addr/acdr-ui/node_modules/wot-design-uni/components/wd-input-number/wd-input-number.vue'\nwx.createComponent(Component)"],"names":["ref","watch","debounce","isEqual","isDef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAA,cAAe;AAAA,EACb,MAAM;AAAA,EACN,SAAS;AAAA,IACP,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EAClB;AACF;;;;;AAQA,UAAM,QAAQ;AACd,UAAM,OAAO;AAEP,UAAA,cAAcA,kBAAa,KAAK;AAChC,UAAA,cAAcA,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