<template>
  <div>
    <!--页面加载，加载完成后-->
  </div>
</template>

<script>
  import Cookies from 'vue-cookies'
  import apiLogin from '@/api/login.js'
  import { getToken,setToken } from '@/utils/token'
  export default{
    mounted(){
      this.toUrl=this.$route.query.returnUrl;
      let token=getToken();
      let $this=this;
      if(!token){
        //console.log(token,'未获取token');
        setTimeout(function(){
          $this.curToken=getToken();
          if(!$this.curToken){
            //console.log(token,'第二次未获取token');
            location.href=this.webBaseUrl+process.env.VUE_APP_LOGIN_URL;
          }else{
            $this.boeLogin();
          }

        },500);
      }else{
        this.curToken=token;
        this.boeLogin();
      }
    },
    data(){
      return {
        curToken:'',
        toUrl:''
      }
    },
    methods:{
       boeLogin(){
           apiLogin.boeLogin(this.curToken).then(rs=>{
             if(rs.status==200){
               //setToken(rs.result.access_token);
               localStorage.setItem(this.$xpage.constants.newLoginKey,1);
               if(this.toUrl){
                 location.href=this.toUrl;
               }else{
                 this.$router.push({ path: "/index" })
               }
               //this.$router.push({ path: "/index" })
             }else{
               this.$message.error("登录失败："+rs.message);
             }
           })
       }
    }
  }
</script>

<style>
</style>
