<template>
    <div id="app" ref="app">
        <router-view :key="$route.fullPath"></router-view>
    </div>
</template>

<script>
import user from "@/http/api/user";
import { setToken, getToken } from "@/utils/auth";
import { encrypt } from "@/utils/jsencrypt";
export default {
    name: "App",
    mounted() {
        // INFO: 本地调试，自动登录
        if (process.env.NODE_ENV === 'development') {
            this.SubmitLogin();
        }
    },
    methods: {
        SubmitLogin() {
            const username = '5000715133579';
            const password = 'Hjy@123456';
            // const type = '1';
            const schoolType = sessionStorage.getItem('schoolType');
            if (getToken() && schoolType) {
                return
            }
            sessionStorage.setItem('schoolType', schoolType || 2);
            user.loginEmailPass({
                username: username,
                password: encrypt(password),
                deviceType: "PC"
            }).then((res) => {
                if (res.code === 200) {
                    this.$store.dispatch("user/CLEAR_LOCAL_STORAGE");//清空本地存储
                    setToken(res.data.tokenValue);
                    this.$store.dispatch("user/SET_TOKEN", res.data.tokenValue);
                    this.$store.dispatch("user/SET_SCHOOL_LOGO", res.data.schoolLogoUrl);//设置学校logo
                    this.$store.dispatch("user/SET_SCHOOL_WEB_SITE_ID", res.data.cloudMonitorSiteId || '');//设置学校网站id
                    this.$store.dispatch("user/getUserInfoByToken");//获取用户登录信息
                    this.$router.push("/jointStudentAnalysisReport/list");
                }
            });
        },
    }
};
</script>

<style lang="scss">
@use "@/styles/setting.scss";

#app {
    height: 100%;
    width: 100%;
}
</style>
