index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="input-number-range flex">
  3. <div class="from">
  4. <el-input-number
  5. ref="input_from"
  6. v-model="userInputForm"
  7. :disabled="disabled"
  8. placeholder="最小值"
  9. @change="handleInputChangeFrom"
  10. :min="min"
  11. :max="userInputTo - 1"
  12. />
  13. </div>
  14. <div class="center">
  15. <span>至</span>
  16. </div>
  17. <div class="to">
  18. <el-input-number
  19. ref="input_to"
  20. v-model="userInputTo"
  21. :disabled="disabled"
  22. placeholder="最大值"
  23. @change="handleInputChangeTo"
  24. :min="userInputForm + 1"
  25. :max="max"
  26. ></el-input-number>
  27. </div>
  28. </div>
  29. </template>
  30. <script lang="ts" setup name="inputNumberRange">
  31. import { ref, watch } from 'vue';
  32. const props = defineProps({
  33. modelValue: {
  34. type: Array,
  35. default: () => [],
  36. },
  37. disabled: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. min: {
  42. type: Number,
  43. default: 0,
  44. },
  45. max: {
  46. type: Number,
  47. default: 100,
  48. },
  49. });
  50. const emit = defineEmits(['update:modelValue','change']);
  51. const userInputForm = ref<any>(null);
  52. const userInputTo = ref<any>(null);
  53. watch(
  54. () => props.modelValue,
  55. (value: any) => {
  56. userInputForm.value = typeof value[0] === 'number' ? value[0] : null;
  57. userInputTo.value = typeof value[1] === 'number' ? value[1] : null;
  58. },
  59. { immediate: true }
  60. );
  61. const handleInputChangeFrom = () => {
  62. emit('update:modelValue', [userInputForm.value, userInputTo.value]);
  63. emit('change', [userInputForm.value, userInputTo.value])
  64. };
  65. const handleInputChangeTo = () => {
  66. emit('update:modelValue', [userInputForm.value, userInputTo.value]);
  67. emit('change', [userInputForm.value, userInputTo.value])
  68. };
  69. </script>
  70. <style lang="scss" scoped>
  71. .flex {
  72. display: flex;
  73. width: 100%;
  74. justify-content: center;
  75. align-items: center;
  76. .center {
  77. margin: 1px 10px 0 10px;
  78. }
  79. }
  80. </style>