index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="icon-body">
  3. <el-input
  4. v-model="iconName"
  5. class="icon-search"
  6. clearable
  7. placeholder="请输入图标名称"
  8. @clear="filterIcons"
  9. @input="filterIcons"
  10. >
  11. <template #suffix><i class="el-icon-search el-input__icon" /></template>
  12. </el-input>
  13. <div class="icon-list">
  14. <div class="list-container">
  15. <div v-for="(item, index) in iconList" class="icon-item-wrapper" :key="index" @click="selectedIcon(item)">
  16. <div :class="['icon-item', { active: activeIcon === item }]">
  17. <svg-icon :icon-class="item" class-name="icon" style="height: 25px;width: 16px;"/>
  18. <span>{{ item }}</span>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import icons from './requireIcons'
  27. const props = defineProps({
  28. activeIcon: {
  29. type: String
  30. }
  31. });
  32. const iconName = ref('');
  33. const iconList = ref(icons);
  34. const emit = defineEmits(['selected']);
  35. function filterIcons() {
  36. iconList.value = icons
  37. if (iconName.value) {
  38. iconList.value = icons.filter(item => item.indexOf(iconName.value) !== -1)
  39. }
  40. }
  41. function selectedIcon(name) {
  42. emit('selected', name)
  43. document.body.click()
  44. }
  45. function reset() {
  46. iconName.value = ''
  47. iconList.value = icons
  48. }
  49. defineExpose({
  50. reset
  51. })
  52. </script>
  53. <style lang='scss' scoped>
  54. .icon-body {
  55. width: 100%;
  56. padding: 10px;
  57. .icon-search {
  58. position: relative;
  59. margin-bottom: 5px;
  60. }
  61. .icon-list {
  62. height: 200px;
  63. overflow: auto;
  64. .list-container {
  65. display: flex;
  66. flex-wrap: wrap;
  67. .icon-item-wrapper {
  68. width: calc(100% / 3);
  69. height: 25px;
  70. line-height: 25px;
  71. cursor: pointer;
  72. display: flex;
  73. .icon-item {
  74. display: flex;
  75. max-width: 100%;
  76. height: 100%;
  77. padding: 0 5px;
  78. &:hover {
  79. background: #ececec;
  80. border-radius: 5px;
  81. }
  82. .icon {
  83. flex-shrink: 0;
  84. }
  85. span {
  86. display: inline-block;
  87. vertical-align: -0.15em;
  88. fill: currentColor;
  89. padding-left: 2px;
  90. overflow: hidden;
  91. text-overflow: ellipsis;
  92. white-space: nowrap;
  93. }
  94. }
  95. .icon-item.active {
  96. background: #ececec;
  97. border-radius: 5px;
  98. }
  99. }
  100. }
  101. }
  102. }
  103. </style>