mobile.jsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Stepper as VanStepper } from 'vant'
  2. import { useFormInput } from '../../../hooks/form-input'
  3. import { formInputProps } from '../../form-input-props'
  4. import { computed } from 'vue'
  5. export default {
  6. props: formInputProps,
  7. setup (props, context) {
  8. const { emitModelValue, placeholder, securityConfig } = useFormInput(props, context)
  9. // min和max限制输入值大小
  10. const emitInput = (val) => {
  11. if (props.config?.min && val && val < props.config.min) {
  12. val = props.config.min
  13. }
  14. if (props.config?.max && val && val > props.config.max) {
  15. val = props.config.max
  16. }
  17. if (val && props.config?.precision) {
  18. val = Number(val).toFixed(props.config?.precision ?? 0)
  19. }
  20. emitModelValue(val)
  21. }
  22. const precision = computed(() => {
  23. return !securityConfig.value.noPrecision ? (securityConfig.value.precision ?? 0) : undefined
  24. })
  25. return () => <VanStepper modelValue={props.modelValue}
  26. onUpdate:modelValue={emitInput}
  27. placeholder={placeholder.value}
  28. step={securityConfig.value.step ?? 1}
  29. min={securityConfig.value.min}
  30. max={securityConfig.value.max}
  31. decimal-length={precision.value}
  32. />
  33. }
  34. }