43b8d82018bc16e14773c637ab40033b67437bd7.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div>
  3. <div id="loader-wrapper">
  4. <div id="loader"></div>
  5. <div class="loader-section section-left"></div>
  6. <div class="loader-section section-right"></div>
  7. <div class="load_title">正在登录 JeecgBoot 低代码平台,请耐心等待</div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapActions } from 'vuex'
  13. import { isOAuth2AppEnv, timeFix } from '@/utils/util'
  14. import { INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types'
  15. export default {
  16. name: 'OAuth2Login',
  17. data() {
  18. return {
  19. env: {
  20. thirdApp: false,
  21. wxWork: false,
  22. dingtalk: false,
  23. },
  24. }
  25. },
  26. beforeCreate() {
  27. // 如果当前 不是 OAuth2APP环境,就重定向到 /user/login 页面
  28. if (!isOAuth2AppEnv()) {
  29. this.$router.replace({path: '/user/login'})
  30. }
  31. },
  32. created() {
  33. this.checkEnv()
  34. this.doOAuth2Login()
  35. },
  36. methods: {
  37. ...mapActions(['ThirdLogin']),
  38. /** 检测当前的环境 */
  39. checkEnv() {
  40. // 判断当时是否是企业微信环境
  41. if (/wxwork/i.test(navigator.userAgent)) {
  42. this.env.thirdApp = true
  43. this.env.wxWork = true
  44. }
  45. // 判断当时是否是钉钉环境
  46. if (/dingtalk/i.test(navigator.userAgent)) {
  47. this.env.thirdApp = true
  48. this.env.dingtalk = true
  49. }
  50. },
  51. /** 进行OAuth2登录操作 */
  52. doOAuth2Login() {
  53. if (this.env.thirdApp) {
  54. // 判断是否携带了Token,是就说明登录成功
  55. if (this.$route.query.oauth2LoginToken) {
  56. this.thirdType = this.$route.query.thirdType
  57. let token = this.$route.query.oauth2LoginToken
  58. this.doThirdLogin(token)
  59. } else if (this.env.wxWork) {
  60. this.doWechatEnterpriseOAuth2Login()
  61. } else if (this.env.dingtalk) {
  62. this.doDingTalkOAuth2Login()
  63. }
  64. }
  65. },
  66. // 根据token执行登录
  67. doThirdLogin(token) {
  68. let param = {}
  69. param.thirdType = this.thirdType
  70. param.token = token
  71. this.ThirdLogin(param).then(res => {
  72. if (res.success) {
  73. this.loginSuccess()
  74. } else {
  75. this.requestFailed(res)
  76. }
  77. })
  78. },
  79. loginSuccess() {
  80. // 登陆成功,重定向到主页
  81. this.$router.replace({path: INDEX_MAIN_PAGE_PATH})
  82. // TODO 这个提示是否还需要?
  83. this.$notification.success({
  84. message: '欢迎',
  85. description: `${timeFix()},欢迎回来`,
  86. })
  87. },
  88. requestFailed(err) {
  89. this.$error({
  90. title: '登录失败',
  91. content: ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试',
  92. okText: '重新登陆',
  93. onOk() {
  94. window.location.reload()
  95. },
  96. onCancel() {
  97. window.location.reload()
  98. },
  99. })
  100. },
  101. /** 企业微信OAuth2登录 */
  102. doWechatEnterpriseOAuth2Login() {
  103. this.sysOAuth2Login('wechat_enterprise')
  104. },
  105. /** 钉钉OAuth2登录 */
  106. doDingTalkOAuth2Login() {
  107. this.sysOAuth2Login('dingtalk')
  108. },
  109. /** 后台构造oauth2登录地址 */
  110. sysOAuth2Login(source) {
  111. let url = `${window._CONFIG['domianURL']}/sys/thirdLogin/oauth2/${source}/login`
  112. url += `?state=${encodeURIComponent(window.location.origin)}`
  113. window.location.href = url
  114. },
  115. },
  116. }
  117. </script>
  118. <style scoped>
  119. </style>