otherLogin.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. @@ -0,0 +1,70 @@
  2. <template>
  3. <view>
  4. <web-view :src="url"></web-view>
  5. </view>
  6. </template>
  7. <script>
  8. import {
  9. getTicketStatus,
  10. socialsLogin
  11. } from '@/api/common.js'
  12. import {
  13. useUserStore
  14. } from '@/store/modules/user'
  15. export default {
  16. data() {
  17. return {
  18. show: false,
  19. url: '',
  20. ticket: '',
  21. ssoTimer: null,
  22. tenantUserInfo: [],
  23. }
  24. },
  25. onLoad(option) {
  26. this.url = uni.getStorageSync('ssoUrl')
  27. this.ticket = option.ssoTicket
  28. this.ssoTimer = setInterval(() => {
  29. this.getTicketStatus()
  30. }, 1000)
  31. },
  32. onUnload() {
  33. this.clearTimer()
  34. },
  35. methods: {
  36. getTicketStatus() {
  37. const userStore = useUserStore()
  38. if (!this.ticket) return
  39. getTicketStatus(this.ticket).then(res => {
  40. if (res.data.status != 2) {
  41. this.clearTimer()
  42. // 登录成功
  43. if (res.data.status == 1) {
  44. uni.showLoading({
  45. title: '登录中'
  46. })
  47. userStore.setToken(res.data.value)
  48. userStore.getCurrentUser().then((res) => {
  49. uni.hideLoading()
  50. uni.reLaunch({
  51. url: '/pages/index/index'
  52. });
  53. }).catch(() => {
  54. uni.hideLoading()
  55. uni.reLaunch({
  56. url: '/pages/login/index'
  57. });
  58. })
  59. } else if (res.data.status == 4) {
  60. uni.setStorageSync('ssoTicket', this.ticket)
  61. uni.reLaunch({
  62. url: '/pages/login/index'
  63. });
  64. } else if (res.data.status == 6) {
  65. let tenantUserInfo = JSON.parse(res.data.value)
  66. if (tenantUserInfo.length == 1) {
  67. uni.showLoading({
  68. title: '登录中'
  69. })
  70. userStore.setToken(res.data.value)
  71. userStore.getCurrentUser().then((res) => {
  72. uni.hideLoading()
  73. uni.reLaunch({
  74. url: '/pages/index/index'
  75. });
  76. }).catch(() => {
  77. uni.hideLoading()
  78. uni.reLaunch({
  79. url: '/pages/login/index'
  80. })
  81. })
  82. } else {
  83. uni.reLaunch({
  84. url: '/pages/login/index?data=' + JSON.stringify(tenantUserInfo)
  85. })
  86. }
  87. } else if (res.data.status == 7) {
  88. this.$u.toast('第三方账号未绑定账号,请绑定后重试')
  89. setTimeout(() => {
  90. uni.reLaunch({
  91. url: '/pages/login/index'
  92. })
  93. }, 600)
  94. } else {
  95. this.show = false
  96. this.ssoUrl = ''
  97. uni.showToast({
  98. title: res.data.value || '操作超时,请重新点击登录',
  99. icon: 'none'
  100. })
  101. uni.reLaunch({
  102. url: '/pages/login/index'
  103. });
  104. }
  105. }
  106. })
  107. },
  108. clearTimer() {
  109. if (this.ssoTimer) {
  110. clearInterval(this.ssoTimer)
  111. this.ssoTimer = null
  112. }
  113. }
  114. }
  115. }
  116. </script>