ehrentrance.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div>
  3. </div>
  4. </template>
  5. <script>
  6. import { setToken,getToken } from '@/utils/auth'
  7. import { ehrLogin } from '@/api/sso/ssoLogin';
  8. export default {
  9. data () {
  10. return {
  11. }
  12. },
  13. created() {
  14. },
  15. mounted() {
  16. this.$nextTick(() => {
  17. this.jump()
  18. })
  19. },
  20. methods: {
  21. jump() {
  22. var code = this.GetQueryString('code')
  23. var jumpPath = this.GetQueryString('path')
  24. let str = jumpPath + window.location.search;
  25. if(getToken()){
  26. this.$router.push({ path: str});
  27. }else{
  28. ehrLogin(code).then(res => {
  29. if (res.code === 200) {
  30. let token = res.token
  31. setToken(token)
  32. this.$store.commit('SET_TOKEN', token)
  33. this.$store.dispatch("GetInfo").then(() => {})
  34. console.log("str", str)
  35. this.$store.dispatch("GenerateRoutes").then(
  36. this.$router.push({ path: str}).catch(()=>{})
  37. )
  38. }
  39. })
  40. }
  41. },
  42. GetQueryString(name) {
  43. var reg = new RegExp( "(^|&)" + name + "=([^&]*)(&|$)" );
  44. var r = window.location.search.substr(1).match(reg);
  45. if (r!= null ) return unescape(r[2]); return null ;
  46. }
  47. }
  48. }
  49. </script>