<template>
    <div id="app">
        <router-view/>
    </div>
</template>

<script>
import ResizeMixin from './mixin/ResizeHandler'
import {getCurrentLang} from "ap-util/util/LoginUserUtil";

export default {
    name: 'App',
    mixins: [ResizeMixin],
    async created() {
        await this.loadLangScript();
    },
    methods: {
        async loadLangScript() {
            // 加载语言包
            return new Promise((resolve, reject) => {
                this.$request({
                    url: "/apm/lang/getLangDate",
                    method: 'post',
                }).then(response => {
                    const script = document.createElement('script');
                    let lang = getCurrentLang();
                    // 外网使用host，内网使用env配置项
                    let host = location.host.startsWith("wwww") ? location.origin : process.env.VUE_APP_IP;
                    script.src = host + "/fs/apm/lang/lang_" + lang + ".js?v=" + response.data;
                    script.onload = resolve;
                    script.onerror = reject;
                    // 插入到所有script标签之前
                    const firstScript = document.getElementsByTagName('script')[0];
                    if (firstScript) {
                        firstScript.parentNode.insertBefore(script, firstScript);
                    } else {
                        document.head.appendChild(script);
                    }
                })
            });
        }
    }
}
</script>
