华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.4 KiB

  1. <template>
  2. <div class="icon-dialog">
  3. <el-dialog
  4. v-bind="$attrs"
  5. width="980px"
  6. :modal-append-to-body="false"
  7. v-on="$listeners"
  8. @open="onOpen"
  9. @close="onClose"
  10. >
  11. <div slot="title">
  12. 选择图标
  13. <el-input
  14. v-model="key"
  15. :style="{width: '260px'}"
  16. placeholder="请输入图标名称"
  17. prefix-icon="el-icon-search"
  18. clearable
  19. />
  20. </div>
  21. <ul class="icon-ul">
  22. <li
  23. v-for="icon in iconList"
  24. :key="icon"
  25. :class="active===icon?'active-item':''"
  26. @click="onSelect(icon)"
  27. >
  28. <i :class="icon" />
  29. <div>{{ icon }}</div>
  30. </li>
  31. </ul>
  32. </el-dialog>
  33. </div>
  34. </template>
  35. <script>
  36. import iconList from '@/utils/generator/icon.json'
  37. const originList = iconList.map(name => `el-icon-${name}`)
  38. export default {
  39. inheritAttrs: false,
  40. props: ['current'],
  41. data() {
  42. return {
  43. iconList: originList,
  44. active: null,
  45. key: ''
  46. }
  47. },
  48. watch: {
  49. key(val) {
  50. if (val) {
  51. this.iconList = originList.filter(name => name.indexOf(val) > -1)
  52. } else {
  53. this.iconList = originList
  54. }
  55. }
  56. },
  57. methods: {
  58. onOpen() {
  59. this.active = this.current
  60. this.key = ''
  61. },
  62. onClose() {},
  63. onSelect(icon) {
  64. this.active = icon
  65. this.$emit('select', icon)
  66. this.$emit('update:visible', false)
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .icon-ul {
  73. margin: 0;
  74. padding: 0;
  75. font-size: 0;
  76. li {
  77. list-style-type: none;
  78. text-align: center;
  79. font-size: 14px;
  80. display: inline-block;
  81. width: 16.66%;
  82. box-sizing: border-box;
  83. height: 108px;
  84. padding: 15px 6px 6px 6px;
  85. cursor: pointer;
  86. overflow: hidden;
  87. &:hover {
  88. background: #f2f2f2;
  89. }
  90. &.active-item{
  91. background: #e1f3fb;
  92. color: #7a6df0
  93. }
  94. > i {
  95. font-size: 30px;
  96. line-height: 50px;
  97. }
  98. }
  99. }
  100. .icon-dialog {
  101. ::v-deep .el-dialog {
  102. border-radius: 8px;
  103. margin-bottom: 0;
  104. margin-top: 4vh !important;
  105. display: flex;
  106. flex-direction: column;
  107. max-height: 92vh;
  108. overflow: hidden;
  109. box-sizing: border-box;
  110. .el-dialog__header {
  111. padding-top: 14px;
  112. }
  113. .el-dialog__body {
  114. margin: 0 20px 20px 20px;
  115. padding: 0;
  116. overflow: auto;
  117. }
  118. }
  119. }
  120. </style>