index.vue 1.8 KB

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