index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. @update:search="v => item.search ? debouncedCallbackSearch(v) : null"
  24. @update:modelValue="modelValueUpDate"
  25. ></v-autocomplete>
  26. </div>
  27. </template>
  28. <script setup>
  29. import { debounce } from 'lodash'
  30. import { ref, defineEmits, watch } from 'vue';
  31. defineOptions({ name:'FormUI-v-autocomplete'})
  32. const props = defineProps({item: Object, modelValue: [String, Number, Boolean]})
  33. const value = ref()
  34. watch(
  35. () => props.modelValue,
  36. (newVal) => {
  37. value.value = newVal
  38. },
  39. { immediate: true },
  40. { deep: true }
  41. )
  42. const emit = defineEmits(['update:modelValue', 'change', 'search'])
  43. const item = props.item
  44. const searchDebouncedTime = item.searchDebouncedTime === 0 ? 0 : 500
  45. const modelValueUpDate = (val) => {
  46. value.value = val
  47. emit('update:modelValue', value.value)
  48. emit('change', value.value)
  49. }
  50. const debouncedCallbackSearch = debounce(newValue => {
  51. emit('search', newValue)
  52. }, searchDebouncedTime)
  53. </script>
  54. <style lang="scss" scoped>
  55. </style>