index.vue 2.5 KB

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