张卓
2022-09-20 5aead44ba1be31db948dfd8362c2bfcbedbbce29
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
<template>
<a-dropdown>
    <div class="item">
        <a-icon type="global" />
        <span>{{$t(`lang.${this.$i18n.locale}`)}}</span>
    </div>
    <a-menu slot="overlay" @click="localeChange">
        <a-menu-item v-for="(locale) in localeList()" :key="locale.key">
            <a href="javascript:;">{{$t(`lang.${locale.key}`)}}</a>
        </a-menu-item>
    </a-menu>
</a-dropdown>
</template>
 
<script lang="ts">
/**
 * 多语言选择组件
 */
import { Component, Prop, Vue } from 'vue-property-decorator';
import { State, Mutation, namespace } from 'vuex-class';
 
import localeService from '@/core/localeService';
 
import * as _ from 'lodash';
 
@Component({})
export default class SelectLange extends Vue {
 
    /**
     * 多语言列表
     */
    private localeList() {
        return _.map(_.keys(this.$i18n.messages), (item: any) => {
            return { key: item };
        });
    }
 
    /**
     * 切换语言
     */
    private localeChange(e: any) {
        localeService.loadLanguageAsync(e.key)
            .then((res: any) => {
            });
    }
}
</script>