index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. :style="{width: item.width}"
  11. :color="item.color || 'primary'"
  12. :label="item.label"
  13. :placeholder="item.placeholder || item.label"
  14. :autofocus="item.autofocus"
  15. :required="item.required"
  16. :class="item.class"
  17. :suffix="item.suffix"
  18. :append-icon="item.appendIcon"
  19. :append-inner-icon="item.appendInnerIcon"
  20. :clearable="item.clearable"
  21. :readonly="item.readonly"
  22. :counter="item.counter"
  23. :prepend-inner-icon="item.prependInnerIcon"
  24. hide-spin-buttons
  25. :hide-details="item.hideDetails || false"
  26. @wheel="$event => handleWheel($event, item)"
  27. @update:modelValue="modelValueUpDate"
  28. @click:append="appendClick"
  29. @click:append-inner="appendInnerClick"
  30. ></v-text-field>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { defineEmits, ref, watch } from 'vue';
  35. defineOptions({ name:'FormUI-v-text-field'})
  36. const props = defineProps({item: Object, modelValue: [String, Number]})
  37. const emit = defineEmits(['update:modelValue', 'change', 'appendClick', 'appendInnerClick'])
  38. const item = props.item
  39. const value = ref(props.modelValue)
  40. watch(() => props.modelValue, (newVal) => {
  41. value.value = newVal
  42. })
  43. const modelValueUpDate = (val) => {
  44. value.value = val
  45. emit('update:modelValue', value.value)
  46. emit('change', value.value)
  47. }
  48. const appendClick = () => {
  49. if (item.appendClick) item.appendClick()
  50. emit('appendClick', value.value)
  51. }
  52. const appendInnerClick = () => {
  53. if (item.appendInnerClick) item.appendInnerClick()
  54. emit('appendInnerClick', value.value)
  55. }
  56. const handleWheel = (event, item) => {
  57. if (item.type !== 'number') return
  58. event.preventDefault()
  59. if (event.deltaY > 0) {
  60. item.value--
  61. } else {
  62. item.value++
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. </style>