<template>

</template>
<script>
import user from "@/http/api/user";
import { setToken } from "@/utils/auth";
// import { getToken} from '@/utils/auth';
import base from "@/http/common/base";
export default {
  data() {
    return {
    }
  },
  mounted() {
    // if(getToken()){
    //   const directUrl = "/studentAnalysisReport/list";
    //   this.$router.push({ path: directUrl });
    //   return false
    // }else{
      
    // }
    this.SubmitLogin();
  },
  methods: {
    //登录提交
    SubmitLogin() {
      const code = this.$route.query.code || '';
      const pw = this.$route.query.pw || '';
      const type = this.$route.query.type || '1';//1:单校 2:联校
      if(!code && !pw){
        window.location.href = base.STUDENT_LOGIN;//跳转到教师端登录页面
      }
      sessionStorage.setItem('schoolType', type);//1:单校 2:联校
      const params = {
        "password": decodeURI(pw),//解密
        "username": code
      };
      user.loginEmailPass(params).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/getUserInfoByToken");//获取用户登录信息

          const directUrl = "/studentAnalysisReport/list";
          this.$router.push({ path: directUrl });
        }else{
          this.$message({
            message: res.msg,
            type: 'warning'
          });
        }
      });
    },
  }

}
</script>

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