index.vue 4.6 KB

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