index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div>
  3. <div class="logout">
  4. <loading/>
  5. <p>跳转中,请稍后...</p>
  6. </div>
  7. <template v-if="isMobile">
  8. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  9. <ul style="height:100vh;overflow-y:auto">
  10. <li class="listitem itemgreen">选择您要登录的公司:</li>
  11. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  12. </ul>
  13. </mt-popup>
  14. </template>
  15. </div>
  16. </template>
  17. <script>
  18. import Loading from '~components/common/loading/Loading.vue'
  19. export default {
  20. name: 'agency',
  21. layout: 'mobile',
  22. data () {
  23. return {
  24. popupVisible: false,
  25. spaceUU: ''
  26. }
  27. },
  28. components: {
  29. Loading
  30. },
  31. mounted () {
  32. this.$nextTick(() => {
  33. this.agency(true)
  34. })
  35. },
  36. computed: {
  37. isMobile () {
  38. return this.$store.state.option.isMobile
  39. },
  40. enterprise () {
  41. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  42. }
  43. },
  44. methods: {
  45. selectEnterprise (flag, type) {
  46. // console.log('type', type)
  47. this.spaceUU = type
  48. this.popupVisible = flag
  49. this.agency(flag)
  50. },
  51. agency (flag) {
  52. let param = new FormData()
  53. param.append('returnUrl', this.$route.query.returnURL || '')
  54. param.append('appId', this.$route.query.appId || '')
  55. param.append('token', this.$route.query.token || '')
  56. param.append('baseUrl', this.$route.query.baseURL || '')
  57. param.append('spaceUU', this.spaceUU || this.$route.query.spaceUU || '')
  58. param.append('isLoginAll', this.$route.query.isLoginAll || '')
  59. let config = {
  60. headers: {'Content-Type': 'multipart/form-data'}
  61. }
  62. let url = this.$store.state.option.isMobile ? '/sso/login/mobile/proxy' : '/sso/login/proxy'
  63. this.$http.post(url, param, config)
  64. .then(response => {
  65. if (response.data.success) {
  66. // console.log('res', response.data.content)
  67. if (response.data.content.spaces) {
  68. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  69. this.popupVisible = flag
  70. } else if (response.data.content.loginUrls) {
  71. // 遍历登录url循环让各应用登录(需要跨域)
  72. let param = response.data.content.data
  73. let a = ''
  74. for (let n in param) {
  75. a += (n + '=' + param[n] + '&')
  76. }
  77. if (response.data.content.currentUrl) {
  78. this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
  79. name: 'successCallback',
  80. timeout: 5000
  81. }, (err, data) => {
  82. const crossAfter = this.crossAfter
  83. if (err) {
  84. this.$indicator.close()
  85. this.$toast({
  86. message: '登录超时,即将跳转...',
  87. iconClass: 'el-icon-error'
  88. })
  89. setTimeout(() => {
  90. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  91. }, 1000)
  92. throw err
  93. } else {
  94. this.loginOther(response, a)
  95. }
  96. })
  97. } else {
  98. this.loginOther(response, a, 3000)
  99. }
  100. } else {
  101. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  102. }
  103. } else {
  104. return Promise.reject(response.data)
  105. }
  106. }).catch(err => {
  107. this.$message.error(err.errMsg)
  108. })
  109. },
  110. getJsonp: function (url, timeout = 500) {
  111. return new Promise((resolve, reject) => {
  112. this.$jsonp(url, {
  113. name: 'successCallback',
  114. timeout: timeout
  115. }, function (err, data) {
  116. if (err) {
  117. reject(err)
  118. throw err
  119. } else {
  120. resolve(data)
  121. }
  122. })
  123. })
  124. },
  125. crossAfter (url) {
  126. try {
  127. window.location.href = url
  128. } catch (err) {
  129. console.log(err)
  130. }
  131. },
  132. loginOther (response, a, timeout) {
  133. const crossAfter = this.crossAfter
  134. let promises = []
  135. for (let i in response.data.content.loginUrls) {
  136. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
  137. }
  138. Promise.all(promises).then(() => {
  139. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  140. }).catch(() => {
  141. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  142. })
  143. }
  144. }
  145. }
  146. </script>
  147. <style type="text/scss" lang="scss" scoped>
  148. .logout{
  149. p{
  150. position: fixed;
  151. left: 0;
  152. right:0;
  153. top: 54%;
  154. z-index: 1000;
  155. text-align: center;
  156. font-size: 14px;
  157. color:#333;
  158. }
  159. }
  160. </style>