<template>
    <h1 v-if="status">参数错误</h1>
</template>
<script>
import Vue from "vue";
export default {
  name: "login",
  data() {
    return {
      // openid: this.$route.query.code || "oEBIgv6MkQnyHpzCqdQtNuyXAYzI",
      // openid: this.$route.query.code || "oEBIgv6Lx53zXrBC-kedo_vVBrOs",
     openid: this.$route.query.code || "oEBIgv-3InRW7r6a0LNJluod1br8" ,
    //  openid: this.$route.query.code || "oEBIgv7IMjx4CRevaYqSjxruqkdk" ,
      // openid: this.$route.query.code,
      // openid: '',
      status:false,
    };
  },
  created() {
    // sessionStorage.setItem('userDate',data);

  // console.log(this.openid);
  let that = this;
  // location.href.split('?')[1].split('#')[0].split('=')[1]
  try {
    var arr = location.href.split('?')[1].split('#')[0].split('&')
    arr.map(v=>{
     if( v.indexOf('code')>=0){
       that.openid = v.split('=')[1];
     }
    })
  } catch (error) {
    
  }

    if (!this.openid){
        this.status = true;
        this.$toast("参数错误");
        return 
    }

    this.$toast({
      message: "登陆中...",
      type: "loading",
      duration: 0,
      forbidClick: true
    });
    this.$http.Login(this.openid).then(({ data }) => {
    if(data.success){
          sessionStorage.setItem("userDate", data.data);
    }else{
      sessionStorage.removeItem("userDate");
    }

    sessionStorage.setItem("openId", this.openid);

    sessionStorage.setItem("data",JSON.stringify(data))
    // console.log(data)
        this.$router.replace("/MCenter");
    });
  },
  destroyed() {
    this.$toast.clear();
  }
};
</script>
