index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div :style="{ width: item.width ? item.width + 'px' : '100%' }">
  3. <v-text-field
  4. v-model="value"
  5. variant="outlined"
  6. :density="item.dense || 'compact'"
  7. :type="item.type"
  8. :rules="item.rules"
  9. :disabled="item.disabled"
  10. :dense="item.dense"
  11. :style="{width: item.width}"
  12. :color="item.color"
  13. :label="item.label"
  14. :placeholder="item.placeholder || item.label"
  15. :outlined="item.outlined"
  16. :autofocus="item.autofocus"
  17. :required="item.required"
  18. :class="item.class"
  19. :suffix="item.suffix"
  20. :append-icon="item.appendIcon"
  21. :clearable="item.clearable"
  22. :readonly="item.readonly"
  23. :prepend-inner-icon="item.prependInnerIcon"
  24. hide-spin-buttons
  25. @wheel="$event => handleWheel($event, item)"
  26. @keyup.enter="item.keyupEnterNative && item.keyupEnterNative(index)"
  27. @click="item.click && item.click(index)"
  28. @click:append-inner="item.clickAppendInner"
  29. ></v-text-field>
  30. </div>
  31. </template>
  32. <script setup>
  33. import { computed, defineEmits } from 'vue';
  34. defineOptions({ name:'FormUI-v-text-field'})
  35. const props = defineProps({item: Object, modelValue: [String, Number]})
  36. const emit = defineEmits(['update:modelValue'])
  37. const item = props.item
  38. const value = computed({
  39. get() { return props.modelValue },
  40. set(value) { emit('update:modelValue', value) }
  41. })
  42. const handleWheel = (event, item) => {
  43. if (item.type !== 'number') return
  44. event.preventDefault()
  45. if (event.deltaY > 0) {
  46. item.value--
  47. } else {
  48. item.value++
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. </style>