index.vue 5.4 KB

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