<template>
    <a-config-provider :locale="locale">
        <div id="app">
            <router-view v-if="isRouterAlive"/>
        </div>
    </a-config-provider>
</template>

<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import moment from 'moment'
import 'moment/locale/zh-cn'
import { mapActions } from 'vuex';
moment.locale('zh-cn')
export default {
    name: 'App',
    data () {
        return {
            isRouterAlive: true,
            locale: zhCN
        }
    },
    provide(){ //提供
        return {
            reload: this.reload
        }
    },
    methods: {
        ...mapActions(['getStyles']),
        reload(){
            this.isRouterAlive = false
            this.$nextTick( function () {
                this.isRouterAlive = true
            })
        }
    },
    mounted() {
        // 获取标题样式
        this.getStyles();
        window.onmessage = e => {
            if (!e.data.id) return;
            sessionStorage.setItem("postMessage", e.data.id);
            if (e.data.userInfo && e.data.userInfo.id) {
                if (
                    e.data.userInfo.permissionList.some(
                        item => item.rights === "duojiSystem"
                    )
                ) {
                    let authList = this.$utils.translateDataToTree(
                        e.data.userInfo.permissionList,
                        'duojiSystem'
                    );
                    e.data.userInfo.permissionList = this.$utils.treeToArray(
                        authList
                    );
                } else {
                    e.data.userInfo.permissionList = [];
                }
                localStorage.setItem(
                    "userInfo",
                    JSON.stringify(e.data.userInfo)
                );
            } else {
                localStorage.clear();
            }
        };
    }
};
</script>
<!--<script type="text/javascript" src="./utils/jsmpeg.min.js"></script>-->
<style lang="scss">
@import "style/common/reset.css";
@import "style/common/layout";
@import "style/common/form";
</style>
