index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!-- @author zhengjie -->
  2. <template>
  3. <div class="icon-body">
  4. <el-input v-model="name" style="position: relative;" clearable placeholder="请输入图标名称" @clear="filterIcons" @input.native="filterIcons">
  5. <i slot="suffix" class="el-icon-search el-input__icon" />
  6. </el-input>
  7. <div class="icon-list">
  8. <div v-for="(item, index) in iconList" :key="index" @click="selectedIcon(item)">
  9. <svg-icon :icon-class="item" style="height: 30px;width: 16px;" />
  10. <span>{{ item }}</span>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import icons from './requireIcons'
  17. export default {
  18. name: 'IconSelect',
  19. data() {
  20. return {
  21. name: '',
  22. iconList: icons
  23. }
  24. },
  25. methods: {
  26. filterIcons() {
  27. if (this.name) {
  28. this.iconList = this.iconList.filter(item => item.includes(this.name))
  29. } else {
  30. this.iconList = icons
  31. }
  32. },
  33. selectedIcon(name) {
  34. this.$emit('selected', name)
  35. document.body.click()
  36. },
  37. reset() {
  38. this.name = ''
  39. this.iconList = icons
  40. }
  41. }
  42. }
  43. </script>
  44. <style rel="stylesheet/scss" 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>