UsageSelect.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <a-select
  3. :value="value"
  4. @change="handleChange"
  5. :filterOption="filterOption"
  6. showSearch
  7. optionLabelProp="title">
  8. <a-select-option v-for="item of scopedUsages" :value="item.key" :key="item.key" :title="item.label">
  9. <div style="font-size: 14px;">{{ item.label }}</div>
  10. <div class="text-color-help">{{ item.key }}</div>
  11. </a-select-option>
  12. </a-select>
  13. </template>
  14. <script>
  15. import _ from 'lodash'
  16. export default {
  17. name: 'DashboardUsageSelect',
  18. props: {
  19. usages: {
  20. type: Array,
  21. required: true,
  22. },
  23. value: {
  24. type: String,
  25. required: true,
  26. },
  27. },
  28. computed: {
  29. scopedUsages () {
  30. const ret = {}
  31. for (const k in this.usages) {
  32. ret[k] = this.usages[k]
  33. }
  34. return ret
  35. },
  36. },
  37. methods: {
  38. filterOption (input, option) {
  39. const desc = _.get(option, 'componentOptions.children[0].children[0].text', '')
  40. return option.key.toLowerCase().indexOf(input.toLowerCase()) >= 0 || desc.toLowerCase().indexOf(input.toLowerCase()) >= 0
  41. },
  42. handleChange (val) {
  43. this.$emit('change', val)
  44. this.$emit('input', val)
  45. },
  46. },
  47. }
  48. </script>