index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <el-autocomplete
  3. v-bind="inputProps"
  4. :disabled="disabled"
  5. :placeholder="placeholder"
  6. :clearable="clearable"
  7. :style="{width}"
  8. v-model="proxyValue"
  9. :fetch-suggestions="querySearchAsync"
  10. />
  11. </template>
  12. <script>
  13. import { ElAutocomplete } from 'element-plus'
  14. import { useFormInput, useInputProps, formInputProps, fromInputEmits } from '@cip/components/helper/form-input'
  15. export default {
  16. components: { ElAutocomplete },
  17. props: formInputProps,
  18. emits: fromInputEmits,
  19. setup (props, content) {
  20. const { width, securityConfig, proxyValue, placeholder, clearable } = useFormInput(props, content)
  21. const inputProps = useInputProps(props, [
  22. 'icon',
  23. 'debounce',
  24. 'placement',
  25. 'popperClass',
  26. 'triggerOnFocus',
  27. 'name',
  28. 'selectWhenUnmatched',
  29. 'label',
  30. 'prefixIcon',
  31. 'suffixIcon',
  32. 'hideLoading',
  33. 'teleported',
  34. 'highlightFirstItem',
  35. 'fitInputWidth'
  36. ])
  37. const querySearchAsync = async (query, cb) => {
  38. if (securityConfig.value.asyncOptions) {
  39. const options = await securityConfig.value.asyncOptions(query)
  40. cb(options)
  41. } else {
  42. // eslint-disable-next-line standard/no-callback-literal
  43. cb([])
  44. throw new Error('autocomplete 类型的 config 需要编写 asyncOptions')
  45. }
  46. }
  47. return {
  48. width,
  49. securityConfig,
  50. proxyValue,
  51. placeholder,
  52. clearable,
  53. inputProps,
  54. querySearchAsync
  55. }
  56. }
  57. }
  58. </script>