index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div :style="{ width: item.width ? item.width + 'px' : '100%' }">
  3. <v-autocomplete
  4. v-model="value"
  5. :rules="item.rules"
  6. :attach="!item.noAttach"
  7. :loading="item.loading"
  8. :label="item.label"
  9. :placeholder="item.placeholder || item.label"
  10. :item-title="item.itemText || 'label'"
  11. :item-value="item.itemValue || 'value'"
  12. :items="item.items"
  13. variant="outlined"
  14. :density="item.dense || 'compact'"
  15. :append-to-body="true"
  16. :disabled="item.disabled"
  17. :multiple="item.multiple"
  18. :clearable="item.clearable"
  19. color="primary"
  20. :hide-no-data="item.hideNoData"
  21. :no-data-text="item.noDataText || 'No data available'"
  22. :hide-selected="item.hideSelected"
  23. :hide-details="item.hideDetails || false"
  24. @update:search="v => item.search ? debouncedCallbackSearch(v) : null"
  25. @update:modelValue="modelValueUpDate"
  26. ></v-autocomplete>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { debounce } from 'lodash'
  31. import { ref, watch } from 'vue';
  32. defineOptions({ name:'FormUI-v-autocomplete'})
  33. const props = defineProps({item: Object, modelValue: [String, Array, Number, Boolean]})
  34. const value = ref()
  35. watch(
  36. () => props.modelValue,
  37. (newVal) => {
  38. value.value = newVal
  39. },
  40. { immediate: true },
  41. { deep: true }
  42. )
  43. const emit = defineEmits(['update:modelValue', 'change', 'search'])
  44. const item = props.item
  45. const searchDebouncedTime = item.searchDebouncedTime === 0 ? 0 : 500
  46. const modelValueUpDate = (val) => {
  47. value.value = val
  48. emit('update:modelValue', value.value)
  49. emit('change', value.value)
  50. }
  51. const debouncedCallbackSearch = debounce(newValue => {
  52. emit('search', newValue)
  53. }, searchDebouncedTime)
  54. </script>
  55. <style lang="scss" scoped>
  56. </style>