App.vue 2.52 KB
Newer Older
wb-ct393452's avatar
wb-ct393452 committed
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
<template>
    <a-config-provider :locale="locale" :get-popup-container="popContainer">
        <router-view />
    </a-config-provider>
</template>

<script>
import { enquireScreen } from './utils/commonUtil';
import { mapState, mapMutations } from 'vuex';
import { getI18nKey } from '@/utils/routerUtil';
import { changeThemeColor } from '@/utils/themeUtil';

export default {
    name: 'App',
    data() {
        return {
            locale: {},
        };
    },
    created() {
        this.setHtmlTitle();
        this.setLanguage(this.lang);
        enquireScreen((isMobile) => this.setDevice(isMobile));
    },
    mounted() {},
    watch: {
        lang(val) {
            
            this.setLanguage(val);
            this.setHtmlTitle();
        },
        $route() {
            this.setHtmlTitle();
        },
        'theme.mode': function (val) {
            let closeMessage = this.$message.loading(`您选择了主题模式 ${val}, 正在切换...`);
            changeThemeColor(this.theme.color, val).then(closeMessage);
        },
        'theme.color': function (val) {
            let closeMessage = this.$message.loading(`您选择了主题色 ${val}, 正在切换...`);
            changeThemeColor(val, this.theme.mode).then(closeMessage);
        },
        layout: function () {
            window.dispatchEvent(new Event('resize'));
        },
    },
    computed: {
        //setting = mapStore.name
        ...mapState('settingModule', ['layout', 'theme', 'lang']),
    },
    methods: {
        ...mapMutations('settingModule', ['setDevice']),

        setLanguage(lang) {
            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;
            const key =
                route.path === '/' ? 'home.name' : getI18nKey(route.matched[route.matched.length - 1].path);
            document.title = process.env.VUE_APP_NAME + ' | ' + this.$t(key);
        },
        popContainer() {
            return document.getElementById('popContainer');
        },
    },
};
</script>

<style lang="less" scoped>
</style>