index.vue 2.7 KB

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