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
<template>
    <div class="i18n-switch">
        <el-dropdown trigger="click">
            <div class="cl-comm__icon">
                <cl-svg name="i18n-lang" />
            </div>
 
            <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item
                        v-for="item in list"
                        :key="item.value"
                        @click="setLang(item.value)"
                    >
                        <div
                            class="i18n-switch__item"
                            :class="{ active: config.i18n.locale === item.value }"
                        >
                            <span class="i18n-switch__item-label">{{ item.label }}</span>
                            <span class="i18n-switch__item-dot"></span>
                        </div>
                    </el-dropdown-item>
                </el-dropdown-menu>
            </template>
        </el-dropdown>
    </div>
</template>
 
<script setup lang="ts">
import { ref } from 'vue';
import { storage } from '/@/cool';
import { config } from '/@/config';
 
const list = ref(config.i18n.languages);
 
function setLang(value: string) {
    storage.set('locale', value);
    location.reload();
}
</script>
 
<style lang="scss" scoped>
.i18n-switch {
    &__item {
        width: 120px;
        display: flex;
        align-items: center;
        justify-content: space-between;
 
        &-label {
            font-size: 12px;
        }
 
        &.active {
            .i18n-switch__item-label {
                color: var(--el-color-primary);
            }
 
            .i18n-switch__item-dot {
                width: 8px;
                height: 8px;
                border-radius: 50%;
                background-color: var(--el-color-primary);
            }
        }
 
        &:hover {
            color: var(--el-color-primary);
        }
    }
}
</style>