index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @keyup.enter="handleKeyup"
  31. ></v-text-field>
  32. </div>
  33. </template>
  34. <script setup>
  35. import { defineEmits, ref, watch } from 'vue';
  36. defineOptions({ name:'FormUI-v-text-field'})
  37. const props = defineProps({item: Object, modelValue: [String, Number]})
  38. const emit = defineEmits(['update:modelValue', 'change', 'appendClick', 'appendInnerClick', 'enter'])
  39. const item = props.item
  40. const value = ref(props.modelValue)
  41. watch(() => props.modelValue, (newVal) => {
  42. value.value = newVal
  43. })
  44. const modelValueUpDate = (val) => {
  45. value.value = val
  46. emit('update:modelValue', value.value)
  47. emit('change', value.value)
  48. }
  49. const appendClick = () => {
  50. if (item.appendClick) item.appendClick()
  51. emit('appendClick', value.value)
  52. }
  53. const appendInnerClick = () => {
  54. if (item.appendInnerClick) item.appendInnerClick()
  55. emit('appendInnerClick', value.value)
  56. }
  57. const handleKeyup = () => {
  58. emit('enter', value.value)
  59. }
  60. const handleWheel = (event, item) => {
  61. if (item.type !== 'number') return
  62. event.preventDefault()
  63. if (event.deltaY > 0) {
  64. item.value--
  65. } else {
  66. item.value++
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. </style>