SIconSelect2.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const n = `<template>
  2. <a-select
  3. :value="value"
  4. :disabled="disabled"
  5. :mode="multiple ? 'multiple' : undefined"
  6. :allow-clear="!required"
  7. :placeholder="placeholder"
  8. show-search
  9. :filter-option="filterOption"
  10. @change="handleSelect"
  11. v-bind="attrs"
  12. :style="{ minWidth: minWidth + 'px' }"
  13. >
  14. <a-select-option :value="item" v-for="item in iconList" :key="item">
  15. <s-icon :name="item" color=""></s-icon>
  16. <span style="margin-left: 8px">{{ item }}</span>
  17. </a-select-option>
  18. </a-select>
  19. </template>
  20. <script setup>
  21. import { useAttrs } from 'vue'
  22. import { filterIcons } from './icon-groups'
  23. const attrs = useAttrs()
  24. defineProps({
  25. // 选中图标名,支持 v-model:value
  26. value: {
  27. type: String,
  28. default: ''
  29. },
  30. // 占位文案
  31. placeholder: {
  32. type: String,
  33. default() {
  34. return window.$l('请选择图标')
  35. }
  36. },
  37. // 是否多选
  38. multiple: {
  39. type: Boolean,
  40. default: false
  41. },
  42. // 是否禁用
  43. disabled: {
  44. type: Boolean,
  45. default: false
  46. },
  47. // 是否必填(表单校验用)
  48. required: {
  49. type: Boolean,
  50. default: false
  51. },
  52. // 下拉面板最小宽度,单位 px
  53. minWidth: {
  54. type: Number,
  55. default: 240
  56. }
  57. })
  58. const emits = defineEmits(['update:value', 'change'])
  59. const handleSelect = (v) => {
  60. emits('update:value', v)
  61. emits('change', v)
  62. }
  63. // 图标名固定,列表只需算一次;搜索交给 a-select 的 filter-option(虚拟滚动只渲染可见项)
  64. const iconList = filterIcons('all', '')
  65. // 按图标名做不区分大小写的包含匹配,默认的 value 匹配对 Pascal 名同样适用但区分大小写
  66. const filterOption = (input, option) =>
  67. String(option?.value ?? '')
  68. .toLowerCase()
  69. .includes(String(input ?? '').trim().toLowerCase())
  70. <\/script>
  71. `;
  72. export {
  73. n as default
  74. };