mayf
2024-09-02 d3e09bace1db01d68a9a7a434c07b4331e1b15b7
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
88
89
90
91
92
93
94
95
96
97
98
<template>
  <div>
    <el-popover
      ref="popover"
      width="800"
      placement="bottom-start"
      trigger="click"
      popper-class="mod-menu__icon-popover"
    >
      <el-tabs v-model="activeTab">
        <el-tab-pane
          v-for="tab in tabs"
          :key="tab.title"
          :label="tab.title"
          :name="tab.title"
        >
          <div class="mod-menu__icon-list">
            <el-button
              v-for="(item, index) in tab.icons"
              :key="index"
              :class="{ 'is-active': item === currentValue }"
              @click="onIconChange(item)"
            >
              <i :class="item" aria-hidden="true" />
            </el-button>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-popover>
    <el-input
      v-popover:popover
      v-bind="$attrs"
      :value="currentValue"
      placeholder="图标"
      @input="onInput"
    />
  </div>
</template>
 
<script>
import {
  FILE_ICONS,
  EDITOR_ICONS,
  CHART_ICONS,
  COMMON_ICONS,
} from '@/plugins/icons'
export default {
  inheritAttrs: false,
  props: {
    value: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      tabs: [
        { title: '文件类图标', icons: FILE_ICONS },
        { title: '文本编辑类图标', icons: EDITOR_ICONS },
        { title: '数据类图标', icons: CHART_ICONS },
        { title: '通用类', icons: COMMON_ICONS },
      ],
      activeTab: '文件类图标',
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(value) {
        this.currentValue = value
      },
    },
  },
  methods: {
    onIconChange(value) {
      this.$emit('input', value)
      this.$emit('change', value)
    },
    onInput(e) {
      this.$emit('input', e)
      this.$emit('change', e)
      // this.onValidate()
    },
  },
}
</script>
 
<style lang="scss">
.mod-menu__icon-popover {
  .mod-menu__icon-list {
    height: 300px;
    overflow: auto;
    .el-button {
      margin: 0 10px 10px 0;
    }
  }
}
</style>