<template>
  <div>认证中,请稍等</div>
</template>

<script>
import Vue from "vue";
import { getAuthen } from "../assets/util";
import querystring from "querystring";

export default Vue.extend({
  head() {
    return {
      title: "认证",
    };
  },
  data() {
    return {
      redirect: "",
    };
  },
  created() {
    console.log(this.$route);
    const [url, str] = this.$route.query.state.split("abc")
    this.redirect = url;
    if(str!==undefined){
      const search = querystring.parse(str.replace(/def/g,"&").replace(/ghi/g,"="));
      console.log(search)
    }
    
    if (!this.$route.query.code) {
      getAuthen();
    } else {
      console.log("-----");
      console.log(this.$route);
      this.$store.dispatch("authen/login",this.$route.query.code).then((res)=>{
        console.log(this.$route.query);
        this.handleGoto();
      }).catch((res)=>{
        alert(res);
        getAuthen();
      });
    }
  },
  methods: {
    handleGoto() {
      console.log("goto")
      console.log(this.redirect);
      this.$router.replace({
        path: this.redirect,
      });
    },
  },
});
</script>

<style lang="less">
</style>
