wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
<template>
    <div class="cl-menu-icon">
        <div class="cl-menu-icon__current" v-if="showIcon && modelValue">
            <cl-svg :name="modelValue" />
        </div>
 
        <el-select v-model="value" filterable fit-input-width clearable>
            <div class="cl-menu-icon__list">
                <el-option v-for="item in list" :key="item" :value="item">
                    <cl-svg :name="item" />
                </el-option>
            </div>
        </el-select>
    </div>
</template>
 
<script lang="ts" setup>
defineOptions({
    name: 'cl-menu-icon'
});
 
import { ref, useModel } from 'vue';
import { svgIcons } from 'virtual:svg-icons';
 
const props = defineProps({
    modelValue: {
        type: String,
        default: ''
    },
    showIcon: Boolean
});
 
const emit = defineEmits(['update:modelValue']);
 
// 图标列表
const list = ref(svgIcons.filter(e => e.indexOf('icon-') === 0));
 
// 已选图标
const value = useModel(props, 'modelValue');
</script>
 
<style lang="scss" scoped>
.cl-menu-icon {
    display: flex;
    align-items: center;
 
    &__current {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 5px;
        border: 1px solid var(--el-border-color);
        height: 32px;
        width: 32px;
        border-radius: var(--el-border-radius-base);
        box-sizing: border-box;
        flex-shrink: 0;
 
        .cl-svg {
            font-size: 16px;
        }
    }
 
    &__list {
        display: flex;
        flex-wrap: wrap;
        padding-left: 5px;
 
        .el-select-dropdown__item {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            height: 50px;
            width: 50px;
            border-radius: 4px;
        }
 
        .cl-svg {
            font-size: 18px;
        }
    }
}
</style>