<template>
    <div></div>
</template>
<style lang="scss" scoped>

</style>
<script lang="ts">
import { accessToken, authLogin } from "@/api";
import { setToken } from "@/api/base";
import router from "@/router";
import store from "@/store";
import { saveValue } from "@/utils/common";
import { message } from "ant-design-vue";
import axios from "axios";
import { defineComponent } from "vue";
import { useRoute } from "vue-router";


export default defineComponent(({
    setup(){
       const code: any =  useRoute().query.code;
       console.log(code)
       alert(code)
       if(!code){
            router.push("/")
            return ;
       }
       accessToken(code, 1).then((res: any)=>{
           console.log(res)
           authLogin(res.uid, 1).then((res: any)=>{
            if(res.redirect == 1){
              sessionStorage.setItem('mid',res.memberid);
              router.push("/sign")
              
            }else{
              if(!saveValue("token", res.api_token) && !saveValue("memberid", res.memberid) ){
                  message.error("存储错误, 请允许网页使用本地存储！")
                  return false;
              }else{
                  setToken();
                  store.commit("login", true);
                  store.dispatch("setUserInfo");
                  router.push("/mine/archives")
        }
            }
          })
       })
    //    window.location.href=`https://api.weibo.com/oauth2/access_token?client_id=2754574056&client_secret=2f16267634db2de14cda7891c49aa54a&grant_type=authorization_code&redirect_uri=https://beelink.theluyuan.com/wblogin&code=${code}`
    }
}))
</script>