fuchengshen
2022-06-24 0924fcc06ead4d10ea5d0d579c8224850a0f37a4
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
    <div class="cl-menu-icons__wrap">
        <el-popover
            v-model:visible="visible"
            placement="bottom-start"
            width="480px"
            popper-class="cl-menu-icons"
        >
            <el-row :gutter="10" class="list scroller1">
                <el-col v-for="(item, index) in list" :key="index" :span="3" :xs="4">
                    <el-button
                        size="mini"
                        :class="{ 'is-active': item === name }"
                        @click="onChange(item)"
                    >
                        <icon-svg :name="item" />
                    </el-button>
                </el-col>
            </el-row>
 
            <template #reference>
                <el-input
                    v-model="name"
                    placeholder="请选择"
                    clearable
                    @click="open"
                    @input="onChange"
                />
            </template>
        </el-popover>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, ref, watch } from "vue";
import { iconList } from "/$/base";
 
export default defineComponent({
    name: "cl-menu-icons",
 
    props: {
        modelValue: {
            type: String,
            default: ""
        }
    },
 
    emits: ["update:modelValue"],
 
    setup(props, { emit }) {
        // 是否可见
        const visible = ref<boolean>(false);
 
        // 图标列表
        const list = ref<any[]>(iconList());
 
        // 已选图标
        const name = ref<string>(props.modelValue);
 
        watch(
            () => props.modelValue,
            (val) => {
                name.value = val;
            }
        );
 
        function open() {
            visible.value = true;
        }
 
        function close() {
            visible.value = false;
        }
 
        function onChange(val: string) {
            emit("update:modelValue", val);
            close();
        }
 
        return {
            name,
            list,
            visible,
            open,
            close,
            onChange
        };
    }
});
</script>
 
.
<style lang="scss">
.cl-menu-icons {
    max-width: 90%;
    box-sizing: border-box;
 
    .list {
        display: flex;
        flex-wrap: wrap;
        height: 250px;
    }
 
    .el-button {
        margin-bottom: 10px;
        height: 40px;
        width: 100%;
        padding: 0;
 
        .icon-svg {
            font-size: 18px;
            color: #444;
        }
    }
}
</style>