3328350766
6 天以前 761eb03d6b3bebd0b197179564c84d89d3d12a0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
  <div class="icon-picker">
    <el-select
      v-model="localValue"
      placeholder="请选择图标"
      filterable
      clearable
      class="bs-el-select"
      popper-class="bs-el-select"
      @change="changeValue"
    >
      <el-option
        v-for="icon in iconList"
        :key="icon"
        :label="icon"
        :value="icon"
      >
        <div class="icon-option">
          <i :class="icon" />
          <span>{{ icon }}</span>
        </div>
      </el-option>
    </el-select>
    <div class="icon">
      <i :class="localValue" />
    </div>
  </div>
</template>
<script>
import iconList from './icon.json'
 
const originList = iconList.map(name => `el-icon-${name}`)
 
export default {
  inheritAttrs: false,
  props: {
    value: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      iconList: originList,
      localValue: this.value,
      key: ''
    }
  },
  watch: {
    key (val) {
      if (val) {
        this.iconList = originList.filter(name => name.indexOf(val) > -1)
      } else {
        this.iconList = originList
      }
    }
  },
  methods: {
    changeValue (event) {
      this.$emit('input', this.localValue)
    }
  }
}
</script>
<style lang="scss" scoped>
.icon-picker {
  display: flex;
}
 
.icon-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
 
    i {
      font-size: 20px;
    }
  }
  .icon {
    width: 32px;
    height: 28px;
    margin-left: 5px;
    align-self: center;
    text-align: center;
    background-color: var(--bs-background-1);
  }
</style>