App.vue 2.01 KB
Newer Older
wb-ct393452's avatar
wb-ct393452 committed
1 2 3 4 5 6 7
<template>
    <a-config-provider :locale="locale" :get-popup-container="popContainer">
        <router-view />
    </a-config-provider>
</template>

<script>
8
import { mapState } from 'vuex';
wb-ct393452's avatar
wb-ct393452 committed
9
import { changeThemeColor } from '@/utils/themeUtil';
10
import langUtils from '@/utils/langUtils';
wb-ct393452's avatar
wb-ct393452 committed
11 12 13 14 15 16 17 18 19 20

export default {
    name: 'App',
    data() {
        return {
            locale: {},
        };
    },
    created() {
        this.setHtmlTitle();
21
        this.setLanguage();
wb-ct393452's avatar
wb-ct393452 committed
22
    },
水落(YangLei)'s avatar
水落(YangLei) committed
23

wb-ct393452's avatar
wb-ct393452 committed
24 25 26 27
    watch: {
        $route() {
            this.setHtmlTitle();
        },
水落(YangLei)'s avatar
水落(YangLei) committed
28
        'theme.mode'(val) {
wb-ct393452's avatar
wb-ct393452 committed
29 30 31
            let closeMessage = this.$message.loading(`您选择了主题模式 ${val}, 正在切换...`);
            changeThemeColor(this.theme.color, val).then(closeMessage);
        },
水落(YangLei)'s avatar
水落(YangLei) committed
32
        'theme.color'(val) {
wb-ct393452's avatar
wb-ct393452 committed
33 34 35
            let closeMessage = this.$message.loading(`您选择了主题色 ${val}, 正在切换...`);
            changeThemeColor(val, this.theme.mode).then(closeMessage);
        },
水落(YangLei)'s avatar
水落(YangLei) committed
36
        layout() {
wb-ct393452's avatar
wb-ct393452 committed
37 38 39 40 41
            window.dispatchEvent(new Event('resize'));
        },
    },
    computed: {
        //setting = mapStore.name
42
        ...mapState('settingModule', ['layout', 'theme']),
wb-ct393452's avatar
wb-ct393452 committed
43 44
    },
    methods: {
45 46
        setLanguage() {
            const lang = langUtils.get();
wb-ct393452's avatar
wb-ct393452 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            this.$i18n.locale = lang;
            switch (lang) {
                case 'zh_CN':
                    this.locale = require('ant-design-vue/es/locale-provider/zh_CN').default;
                    break;
                case 'en_US':
                    this.locale = require('ant-design-vue/es/locale-provider/en_US').default;
                    break;
                default:
                    this.locale = require('ant-design-vue/es/locale-provider/en_US').default;
                    break;
            }
        },
        setHtmlTitle() {
            const route = this.$route;
水落(YangLei)'s avatar
水落(YangLei) committed
62
            if (route.name) window.title = route.name;
wb-ct393452's avatar
wb-ct393452 committed
63 64 65 66 67 68 69
        },
        popContainer() {
            return document.getElementById('popContainer');
        },
    },
};
</script>