index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. this.iconList = icons
  28. if (this.name) {
  29. this.iconList = this.iconList.filter(item => item.includes(this.name))
  30. }
  31. },
  32. selectedIcon(name) {
  33. this.$emit('selected', name)
  34. document.body.click()
  35. },
  36. reset() {
  37. this.name = ''
  38. this.iconList = icons
  39. }
  40. }
  41. }
  42. </script>
  43. <style rel="stylesheet/scss" lang="scss" scoped>
  44. .icon-body {
  45. width: 100%;
  46. padding: 10px;
  47. .icon-list {
  48. height: 200px;
  49. overflow-y: scroll;
  50. div {
  51. height: 30px;
  52. line-height: 30px;
  53. margin-bottom: -5px;
  54. cursor: pointer;
  55. width: 33%;
  56. float: left;
  57. }
  58. span {
  59. display: inline-block;
  60. vertical-align: -0.15em;
  61. fill: currentColor;
  62. overflow: hidden;
  63. }
  64. }
  65. }
  66. </style>