<template>
  <div id="test01">
    <!-- test01 -->
    <!-- <el-button @click="getInfo">点击获取</el-button> -->
  </div>
</template>

<script>
import axios from 'axios'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { sso } from '@/api/sso/ssoLogin';
export default {
  data () {
    return {
    }
  },
  created() {
  },
  mounted() {
    this.$nextTick(() => {
      this.jump()
    })
  },
  methods: {
    jump() {
      let userInfo = JSON.parse(localStorage.getItem('userInfo'))
      // console.log('拿到userInfo了不：', userInfo)
      // console.log('路径拿到了不：', this.GetQueryString('path'))
      var jumpPath = this.GetQueryString('path')
      console.log('jumpPath', jumpPath)
      // axios.post('https://test-sy.derom.com/drp-admin/login/sso', userInfo).then(res => {
      sso(userInfo).then(res => {
        if (res.code === 200) {
          let token = res.token
          setToken(token)
          this.$store.commit('SET_TOKEN', token)
          this.$store.dispatch("GetInfo").then(() => {})
          this.$store.dispatch("GenerateRoutes").then(
            this.$router.push({ path: jumpPath }).catch(()=>{})
          )
          // this.$router.push({ path: "/" })
        }
      })
    },
    GetQueryString(name) {
      var  reg = new  RegExp( "(^|&)" + name + "=([^&]*)(&|$)" );
      var  r = window.location.search.substr(1).match(reg);
      if (r!= null ) return   unescape(r[2]); return  null ;
    }
  }
}
</script>