index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
  78. name: 'successCallback',
  79. timeout: 5000
  80. }, (err, data) => {
  81. if (err) {
  82. this.$indicator.close()
  83. this.$toast({
  84. message: '登录超时,即将跳转...',
  85. iconClass: 'el-icon-error'
  86. })
  87. setTimeout(() => {
  88. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  89. }, 1000)
  90. throw err
  91. } else {
  92. const crossAfter = this.crossAfter
  93. let promises = []
  94. for (let i in response.data.content.loginUrls) {
  95. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
  96. }
  97. Promise.all(promises).then(() => {
  98. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  99. }).catch(() => {
  100. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  101. })
  102. }
  103. })
  104. // for (let i in response.data.content.loginUrls) {
  105. // this.$jsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1), function (err, data) {
  106. // if (err) throw err
  107. // console.log(data)
  108. // })
  109. // }
  110. // setTimeout(function () {
  111. // window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  112. // }, 3000)
  113. } else {
  114. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  115. }
  116. } else {
  117. return Promise.reject(response.data)
  118. }
  119. }).catch(err => {
  120. this.$message.error(err.errMsg)
  121. })
  122. },
  123. getJsonp: function (url) {
  124. return new Promise((resolve, reject) => {
  125. this.$jsonp(url, {
  126. name: 'successCallback',
  127. timeout: 500
  128. }, function (err, data) {
  129. if (err) {
  130. reject(err)
  131. throw err
  132. } else {
  133. resolve(data)
  134. }
  135. })
  136. })
  137. },
  138. crossAfter (url) {
  139. try {
  140. window.location.href = url
  141. } catch (err) {
  142. console.log(err)
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style type="text/scss" lang="scss" scoped>
  149. .logout{
  150. p{
  151. position: fixed;
  152. left: 0;
  153. right:0;
  154. top: 54%;
  155. z-index: 1000;
  156. text-align: center;
  157. font-size: 14px;
  158. color:#333;
  159. }
  160. }
  161. </style>