login.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. </template>
  3. <script>
  4. /* export default {
  5. layout: 'login',
  6. mounted () {
  7. this.crossBefore()
  8. },
  9. methods: {
  10. async crossBefore () {
  11. try {
  12. let { data } = await this.$axios.get('/login/crossBefore')
  13. const params = data || {}
  14. this.proxyLogin(params.askUrl, params.askData, params.loginUrl)
  15. } catch (err) {
  16. this.$router.replace('/')
  17. console.log(err)
  18. }
  19. },
  20. proxyLogin (askUrl, askData, loginUrl) {
  21. const crossAfter = this.crossAfter
  22. this.$jsonp(`${askUrl}?askData=${askData}`, function (err, data) {
  23. if (err) throw err
  24. // 判断是否已经登录
  25. if (data.error) {
  26. // 如果未登录,跳转登录界面
  27. window.location.href = loginUrl
  28. } else {
  29. crossAfter(data.content)
  30. }
  31. })
  32. },
  33. async crossAfter (content) {
  34. if (!content && content === '') {
  35. this.$router.replace('/')
  36. }
  37. try {
  38. let { data } = await this.$axios.post('/login/crossAfter', {}, { params: { replyTxt: content } })
  39. this.$store.dispatch('loadUserInfo', data)
  40. window.location.href = data.returnUrl || '/'
  41. } catch (err) {
  42. this.$router.replace('/')
  43. console.log(err)
  44. }
  45. }
  46. }
  47. }*/
  48. export default {
  49. layout: 'login',
  50. mounted () {
  51. this.$axios.get('/sso/login/page', {params: {returnUrl: window.location.protocol + '//' + window.location.host}}).then(response => {
  52. if (response.data) {
  53. var url = response.data.content
  54. if (response.data.cross) {
  55. url += '&baseUrl=' + window.location.origin + '/sso/login/other';
  56. }
  57. window.location.href = url;
  58. }
  59. })
  60. }
  61. /* mounted () {
  62. this.$axios.get('/sso/login/page', {params: {returnUrl: window.location.protocol + '//' + window.location.host}})
  63. .then(response => {
  64. if (response.data) {
  65. console.log(response.data.content)
  66. window.location.href = response.data.content
  67. // window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  68. }
  69. }, err => {
  70. alert('重定向失败')
  71. })
  72. }*/
  73. }
  74. </script>