index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="icon-body">
  3. <el-input
  4. v-model="iconName"
  5. style="position: relative;"
  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 v-for="(item, index) in iconList" :key="index" @click="selectedIcon(item)">
  15. <svg-icon :icon-class="item" style="height: 30px;width: 16px;" />
  16. <span>{{ item }}</span>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script setup>
  22. import icons from './requireIcons'
  23. const iconName = ref('');
  24. const iconList = ref(icons);
  25. const emit = defineEmits(['selected']);
  26. function filterIcons() {
  27. iconList.value = icons
  28. if (iconName.value) {
  29. iconList.value = icons.filter(item => item.indexOf(iconName.value) !== -1)
  30. }
  31. }
  32. function selectedIcon(name) {
  33. emit('selected', name)
  34. document.body.click()
  35. }
  36. function reset() {
  37. iconName.value = ''
  38. iconList.value = icons
  39. }
  40. defineExpose({
  41. reset
  42. })
  43. </script>
  44. <style lang='scss' scoped>
  45. .icon-body {
  46. width: 100%;
  47. padding: 10px;
  48. .icon-list {
  49. height: 200px;
  50. overflow-y: scroll;
  51. div {
  52. height: 30px;
  53. line-height: 30px;
  54. margin-bottom: -5px;
  55. cursor: pointer;
  56. width: 33%;
  57. float: left;
  58. }
  59. span {
  60. display: inline-block;
  61. vertical-align: -0.15em;
  62. fill: currentColor;
  63. overflow: hidden;
  64. }
  65. }
  66. }
  67. </style>