index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="icon-picker">
  3. <el-select
  4. v-model="localValue"
  5. placeholder="请选择图标"
  6. filterable
  7. clearable
  8. class="bs-el-select"
  9. popper-class="bs-el-select"
  10. @change="changeValue"
  11. >
  12. <el-option
  13. v-for="icon in iconList"
  14. :key="icon"
  15. :label="icon"
  16. :value="icon"
  17. >
  18. <div class="icon-option">
  19. <i :class="icon" />
  20. <span>{{ icon }}</span>
  21. </div>
  22. </el-option>
  23. </el-select>
  24. <div class="icon">
  25. <i :class="localValue" />
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import iconList from './icon.json'
  31. const originList = iconList.map(name => `el-icon-${name}`)
  32. export default {
  33. inheritAttrs: false,
  34. props: {
  35. value: {
  36. type: String,
  37. default: ''
  38. }
  39. },
  40. data () {
  41. return {
  42. iconList: originList,
  43. localValue: this.value,
  44. key: ''
  45. }
  46. },
  47. watch: {
  48. key (val) {
  49. if (val) {
  50. this.iconList = originList.filter(name => name.indexOf(val) > -1)
  51. } else {
  52. this.iconList = originList
  53. }
  54. }
  55. },
  56. methods: {
  57. changeValue (event) {
  58. this.$emit('input', this.localValue)
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .icon-picker {
  65. display: flex;
  66. }
  67. .icon-option {
  68. display: flex;
  69. justify-content: space-between;
  70. align-items: center;
  71. i {
  72. font-size: 20px;
  73. }
  74. }
  75. .icon {
  76. width: 32px;
  77. height: 28px;
  78. margin-left: 5px;
  79. align-self: center;
  80. text-align: center;
  81. background-color: var(--bs-background-1);
  82. }
  83. </style>