test01.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <div id="test01">
  3. <!-- test01 -->
  4. <!-- <el-button @click="getInfo">点击获取</el-button> -->
  5. </div>
  6. </template>
  7. <script>
  8. import axios from 'axios'
  9. import { getToken, setToken, removeToken } from '@/utils/auth'
  10. import { sso } from '@/api/sso/ssoLogin';
  11. export default {
  12. data () {
  13. return {
  14. }
  15. },
  16. created() {
  17. },
  18. mounted() {
  19. this.$nextTick(() => {
  20. this.jump()
  21. })
  22. },
  23. methods: {
  24. jump() {
  25. let userInfo = JSON.parse(localStorage.getItem('userInfo'))
  26. // console.log('拿到userInfo了不:', userInfo)
  27. // console.log('路径拿到了不:', this.GetQueryString('path'))
  28. var jumpPath = this.GetQueryString('path')
  29. console.log('jumpPath', jumpPath)
  30. // axios.post('https://test-sy.derom.com/drp-admin/login/sso', userInfo).then(res => {
  31. sso(userInfo).then(res => {
  32. if (res.code === 200) {
  33. let token = res.token
  34. setToken(token)
  35. this.$store.commit('SET_TOKEN', token)
  36. this.$store.dispatch("GetInfo").then(() => {})
  37. this.$store.dispatch("GenerateRoutes").then(
  38. this.$router.push({ path: jumpPath }).catch(()=>{})
  39. )
  40. // this.$router.push({ path: "/" })
  41. }
  42. })
  43. },
  44. GetQueryString(name) {
  45. var reg = new RegExp( "(^|&)" + name + "=([^&]*)(&|$)" );
  46. var r = window.location.search.substr(1).match(reg);
  47. if (r!= null ) return unescape(r[2]); return null ;
  48. }
  49. }
  50. }
  51. </script>