ssoLogin.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div />
  3. </template>
  4. <script>
  5. import CryptoJS from 'crypto-js'
  6. import Cookie from 'js-cookie'
  7. export default {
  8. name: 'SSOLogin',
  9. data() {
  10. return {
  11. loading: false,
  12. redirect: undefined
  13. }
  14. },
  15. watch: {},
  16. created() {
  17. // console.log('this.$route', this.$route)
  18. // console.log('window.location.href', window.location.href)
  19. window.localStorage.clear()
  20. // 第三方平台登录
  21. this.getLoginByToken()
  22. },
  23. methods: {
  24. // 第三方平台单点登录系统
  25. getLoginByToken() {
  26. // 获取地址栏中的token
  27. var token = this.$route.query
  28. // alert('token: ' + token)
  29. // console.log('token===', token)
  30. // console.log('loginid===', token.loginid)
  31. // 调用登录的接口
  32. if (token == '' || token == undefined || token == null) {
  33. // 无token,跳转到登录页面
  34. this.$router.push({ path: '/login' }).catch(() => {})
  35. } else {
  36. // 免密登录
  37. const postForm = {
  38. url: 'loginSecret',
  39. username: token.loginid,
  40. password: '',
  41. validateCode: ''
  42. }
  43. this.$store
  44. .dispatch('user/ssoLogin', postForm)
  45. .then((res) => {
  46. console.log('res', res)
  47. if (res.result) {
  48. this.$router.push({ path: '/backstage?menuIndex=1296067156231847936&subMenu=1296067784098185216' })
  49. } else {
  50. this.$message(res.msg)
  51. this.$router.push({ path: '/login' }).catch(() => {})
  52. }
  53. }).catch((e) => {
  54. this.$router.push({ path: '/login' }).catch(() => {})
  55. // console.log(e)
  56. })
  57. }
  58. },
  59. baseRequest(opUrl, postData) {
  60. return this.$channel.globeRequest('pub', opUrl, postData, 'project')
  61. }
  62. }
  63. }
  64. </script>