<template>
  <div class="full-width window-height bg-grey-3 flex items-center justify-center">
    <div class=" flex column items-center justify-center" v-if="!isError">
        <q-spinner-bars
          color="primary"
          size="6em"
        />
        <div class="q-mt-lg f12 text-grey-6">正在自动登录中，请稍后...</div>
    </div>
    <div class=" flex column items-center justify-center" v-if="isError">
        <q-spinner-bars
          color="primary"
          size="6em"
        />
        <div class="q-mt-lg f12 text-red-6">
            <span>登录异常，请重新打开连接，或</span>
            <router-link :to="{ path: 'login' }">
                返回登录页
            </router-link>
        </div>
    </div>
  </div>
</template>

<script>
export default {
    meta: {
        title: '自动登录中...',
    },
    data() {
        return {
            target:"",
            id:0,
            isError:false
        }
    },
    mounted() {
        if(this.$route.query.loginId){
            this.id=this.$route.query.loginId
        }
        if(this.$route.query.target){
            this.target=this.$route.query.target
        }
        if(this.id!=0&&this.target!=""){
            this.$store
            .dispatch('Login', {
                Account: '',
                Password: '',
                AutoLoginId:this.id
            })
            .then(res => {
                this.$router.push({
                    path: this.target
                })
            })
            .catch(() => {
                this.isError = true
            })
        }else{
             this.isError = true
        }
    },
}
</script>

<style>

</style>