作者 刘元博

优化选择图标组件

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 -  
16 -<script>  
17 -import icons from './requireIcons'  
18 -export default {  
19 - name: 'IconSelect',  
20 - data() {  
21 - return {  
22 - name: '',  
23 - iconList: icons  
24 - }  
25 - },  
26 - methods: {  
27 - filterIcons() {  
28 - this.iconList = icons  
29 - if (this.name) {  
30 - this.iconList = this.iconList.filter(item => item.includes(this.name))  
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 -  
45 -<style rel="stylesheet/scss" lang="scss" scoped>  
46 - .icon-body {  
47 - width: 100%;  
48 - padding: 10px;  
49 - .icon-list {  
50 - height: 200px;  
51 - overflow-y: scroll;  
52 - div {  
53 - height: 30px;  
54 - line-height: 30px;  
55 - margin-bottom: -5px;  
56 - cursor: pointer;  
57 - width: 33%;  
58 - float: left;  
59 - }  
60 - span {  
61 - display: inline-block;  
62 - vertical-align: -0.15em;  
63 - fill: currentColor;  
64 - overflow: hidden;  
65 - }  
66 - }  
67 - }  
68 -</style> 1 +<!-- @author zhengjie -->
  2 +<template>
  3 + <div class="icon-body">
  4 + <el-input v-model="name" style="position: relative;" 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 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 +
  16 +<script>
  17 +import icons from './requireIcons'
  18 +export default {
  19 + name: 'IconSelect',
  20 + data() {
  21 + return {
  22 + name: '',
  23 + iconList: icons
  24 + }
  25 + },
  26 + methods: {
  27 + filterIcons() {
  28 + this.iconList = icons
  29 + if (this.name) {
  30 + this.iconList = this.iconList.filter(item => item.includes(this.name))
  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 +
  45 +<style rel="stylesheet/scss" lang="scss" scoped>
  46 + .icon-body {
  47 + width: 100%;
  48 + padding: 10px;
  49 + .icon-list {
  50 + height: 200px;
  51 + overflow-y: scroll;
  52 + div {
  53 + height: 30px;
  54 + line-height: 30px;
  55 + margin-bottom: -5px;
  56 + cursor: pointer;
  57 + width: 33%;
  58 + float: left;
  59 + }
  60 + span {
  61 + display: inline-block;
  62 + vertical-align: -0.15em;
  63 + fill: currentColor;
  64 + overflow: hidden;
  65 + }
  66 + }
  67 + }
  68 +</style>
@@ -77,7 +77,7 @@ @@ -77,7 +77,7 @@
77 </el-table-column> 77 </el-table-column>
78 <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> 78 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
79 <template slot-scope="scope"> 79 <template slot-scope="scope">
80 - <el-button 80 + <el-button
81 size="mini" 81 size="mini"
82 type="text" 82 type="text"
83 icon="el-icon-edit" 83 icon="el-icon-edit"
@@ -140,8 +140,7 @@ @@ -140,8 +140,7 @@
140 v-if="form.icon" 140 v-if="form.icon"
141 slot="prefix" 141 slot="prefix"
142 :icon-class="form.icon" 142 :icon-class="form.icon"
143 - class="el-input__icon"  
144 - style="height: 32px;width: 16px;" 143 + style="width: 25px;"
145 /> 144 />
146 <i v-else slot="prefix" class="el-icon-search el-input__icon" /> 145 <i v-else slot="prefix" class="el-icon-search el-input__icon" />
147 </el-input> 146 </el-input>