<template>
  <div>
  </div>
</template>

<script>
import { setToken } from '@/utils/auth'
import { ehrLogin } from '@/api/sso/ssoLogin';
export default {
  data () {
    return {
    }
  },
  created() {
  },
  mounted() {
    this.$nextTick(() => {
      this.jump()
    })
  },
  methods: {
    jump() {
      let query = this.$route.query;
      console.log('query',query);
      //判断PC、移动端
      let r = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
      if (r) {
        console.log("移动端");
        let url = window.location.href;
        console.log('url',url,this.$route,'this.$route');
        let arr = url.split('/ehrentrance?');
        console.log('arr[0]',arr[0]);
        let resUrl = "";
        //移动端判断环境
        if(arr[0].includes('//sy.derom.com/')){
          resUrl = "https://sy.derom.com/drp-mobile/#/pages/public-entrance?path=" + query.mobilePath + window.location.search;
        }else{
          resUrl = "https://sy.derom.com/test-drp-mobile/#/pages/public-entrance?path=" + query.mobilePath + window.location.search;
        }
        console.log('resUrl',resUrl);
        location.replace(resUrl);
      } else {
        console.log("PC端");
        let str = query.pcPath + window.location.search;
        console.log('str',str);
        ehrLogin(query.code).then(res => {
          console.log('res',res);
          if (res.code === 200) {
            let token = res.token;
            setToken(token);
            this.$store.commit('SET_TOKEN', token)
            this.$store.dispatch("GetInfo").then(
              this.$router.push({ path: str})
            )
          }
        })
      }
      // ehrLogin(query.code).then(res => {
      //   console.log('res',res);
      //   if (res.code === 200) {
      //     let token = res.token;
      //     setToken(token);
      //     this.$store.commit('SET_TOKEN', token)
      //     this.$store.dispatch("GetInfo").then(
      //       this.$router.push({ path: str})
      //     )
      //   }
      // })
      console.log('执行完成');
    },
  }
}
</script>