ssoLogin.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import HtProgress from 'nprogress'
  2. import store from '@/store'
  3. import {
  4. recordRoute,
  5. routesWhiteList,
  6. progressBar,
  7. tokenName,
  8. casTokenName,
  9. oauthTokenName,
  10. } from '@/config'
  11. export default function (to, from, next) {
  12. // 白名单页面
  13. if (
  14. (routesWhiteList.indexOf(to.path) !== -1 ||
  15. routesWhiteList.indexOf(to.name) !== -1) && window.ssoConfig.mode !== 'oauth'
  16. ) {
  17. if(to.query.corpId){
  18. next({ path: '/matter/approvalForm' })
  19. }else{
  20. next()
  21. }
  22. } else if (to.query && to.query[tokenName]) {
  23. // 先跳转到加载中页面
  24. next({ path: '/loading' })
  25. store
  26. .dispatch('user/authentication', to.query)
  27. .then(() => {
  28. // 鉴权完成后再跳转回来
  29. next({ ...to, replace: true })
  30. })
  31. .catch(() => {
  32. next({ path: '/500', replace: true })
  33. })
  34. } else if (window.ssoConfig.mode == 'cas') {
  35. // cas单点登录
  36. if (to.query && to.query[casTokenName]) {
  37. const ticket = to.query[casTokenName]
  38. store
  39. .dispatch('user/ssoLogin', {
  40. ticket,
  41. service: window.location.href.split('?')[0],
  42. })
  43. .then(() => {
  44. next({ ...to, replace: true })
  45. })
  46. .catch(() => {
  47. next({ path: '/500', replace: true })
  48. })
  49. } else {
  50. window.location.href = `${window.ssoConfig.url}?service=${window.location.href}`
  51. }
  52. } else if (window.ssoConfig.mode == 'oauth') {
  53. // oauth单点登录
  54. if (to.query && to.query[oauthTokenName]) {
  55. const code = to.query[oauthTokenName]
  56. store
  57. .dispatch('user/ssoLogin', {
  58. code,
  59. service: window.location.href.split('?')[0],
  60. })
  61. .then(() => {
  62. next({ ...to, replace: true })
  63. })
  64. .catch(() => {
  65. next({ path: '/500', replace: true })
  66. })
  67. } else {
  68. window.location.href = `${window.ssoConfig.url}?response_type=code&client_id=${window.ssoConfig.clientId}&redirect_uri=${window.location.href}`
  69. }
  70. } else {
  71. if (recordRoute) {
  72. if(to.fullPath=='/matter/approvalForm'){
  73. next()
  74. }else{
  75. next(`/login?redirect=${to.fullPath}`)
  76. }
  77. } else {
  78. next('/login')
  79. }
  80. if (progressBar) HtProgress.done()
  81. }
  82. }