loginMobile.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div class="login">
  3. <div class="page-part">
  4. <mt-field auto-complete="off" placeholder="手机号/邮箱/账号ID" v-model="login.username" @blur.native.capture="codeCount"></mt-field>
  5. </div>
  6. <div class="page-part">
  7. <mt-field placeholder="密码" v-model="login.password" type="password"></mt-field>
  8. <template>
  9. <p class="passwd"><a @click="forgetPwd" class="rgba">忘记密码?</a></p>
  10. </template>
  11. </div>
  12. <template v-if="showCheckCode">
  13. <div class="page-part">
  14. <mt-field placeholder="验证码" v-model="login.captcha">
  15. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  16. </mt-field>
  17. </div>
  18. </template>
  19. <div class="page-part">
  20. <mt-button size="large" type="primary" @click="checkLogin(true)">登录</mt-button>
  21. </div>
  22. <div class="login-btn">
  23. <p>还没有优软云账号?</p>
  24. <mt-button size="large" plain type="primary" @click="jump">立即注册</mt-button>
  25. </div>
  26. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  27. <ul style="height:100vh;overflow-y:auto">
  28. <li class="listitem itemgreen">选择您要登录的公司:</li>
  29. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  30. </ul>
  31. </mt-popup>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'loginMobile',
  37. data () {
  38. return {
  39. loading: false,
  40. popupVisible: false,
  41. imgSrc: '',
  42. showCheckCode: false,
  43. login: {
  44. username: '',
  45. password: '',
  46. spaceUU: '',
  47. captcha: ''
  48. },
  49. appId: '',
  50. returnUrl: '',
  51. baseUrl: ''
  52. }
  53. },
  54. mounted () {
  55. this.$nextTick(() => {
  56. this.getUrl()
  57. })
  58. },
  59. computed: {
  60. enterprise () {
  61. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  62. }
  63. },
  64. methods: {
  65. selectEnterprise (flag, type) {
  66. this.login.spaceUU = type
  67. this.popupVisible = flag
  68. this.toLogin(flag)
  69. },
  70. // 忘记密码
  71. forgetPwd () {
  72. window.location.href = `/reset/forgetPasswordValidationAccount${this.$store.state.option.fullPath}`
  73. },
  74. jump () {
  75. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  76. },
  77. getUrl () {
  78. this.appId = this.$store.state.option.appId
  79. this.returnUrl = this.$store.state.option.returnUrl
  80. this.baseUrl = this.$store.state.option.baseUrl
  81. },
  82. getCode () {
  83. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  84. },
  85. checkLogin (flag) {
  86. if (!this.login.username) {
  87. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  88. } else if (!this.login.password) {
  89. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  90. } else {
  91. this.toLogin(flag)
  92. }
  93. },
  94. codeCount () {
  95. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  96. .then(response => {
  97. if (response.data.success) {
  98. let count = response.data.content || ''
  99. if (count >= 3 && count < 5) {
  100. this.showCheckCode = true
  101. this.getCode()
  102. this.$toast({
  103. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  104. iconClass: 'el-icon-warning'
  105. })
  106. } else if (count === 5) {
  107. this.$toast({
  108. message: '密码错误次数已达上限,今日无法登陆',
  109. iconClass: 'el-icon-warning'
  110. })
  111. }
  112. } else {
  113. this.$toast({
  114. message: response.data.errMsg,
  115. iconClass: 'el-icon-warning'
  116. })
  117. }
  118. }).catch(err => {
  119. this.$toast({
  120. message: err.errMsg,
  121. iconClass: 'el-icon-warning'
  122. })
  123. })
  124. },
  125. toLogin (flag) {
  126. this.$indicator.open('登录中...')
  127. let param = new FormData()
  128. param.append('username', this.login.username)
  129. param.append('password', this.login.password)
  130. param.append('captcha', this.login.captcha)
  131. param.append('appId', this.appId)
  132. param.append('returnUrl', this.returnUrl)
  133. param.append('baseUrl', this.baseUrl)
  134. param.append('spaceUU', this.login.spaceUU)
  135. let config = {
  136. headers: {'Content-Type': 'multipart/form-data'}
  137. }
  138. this.$http.post('/sso/login', param, config)
  139. .then(response => {
  140. this.$indicator.close()
  141. if (response.data.success) {
  142. // 弹框用户选择企业
  143. if (response.data.content.spaces) {
  144. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  145. this.popupVisible = flag
  146. } else if (response.data.content.loginUrls) {
  147. // 遍历登录url循环让各个应用登录
  148. let param = response.data.content.data
  149. let a = ''
  150. for (let n in param) {
  151. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  152. }
  153. let params = a.substr(0, a.length - 1)
  154. this.$indicator.open('跳转中...')
  155. if (response.data.content.currentUrl) {
  156. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  157. name: 'successCallback',
  158. timeout: 5000
  159. }, (err, data) => {
  160. if (err) {
  161. this.$indicator.close()
  162. this.$toast({
  163. message: '登录超时,请重试',
  164. iconClass: 'el-icon-error'
  165. })
  166. this.login.spaceUU = ''
  167. throw err
  168. } else {
  169. this.loginOther(response, params)
  170. }
  171. })
  172. } else {
  173. this.loginOther(response, params, 3000)
  174. }
  175. }
  176. } else {
  177. this.login.password = ''
  178. this.$toast({
  179. message: response.data.errMsg,
  180. iconClass: 'el-icon-error'
  181. })
  182. let count = response.data.errorCount
  183. if (count >= 3 && count < 5) {
  184. this.showCheckCode = true
  185. this.getCode()
  186. let _this = this
  187. setTimeout(function () {
  188. _this.getCode()
  189. }, 100)
  190. this.$toast({
  191. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  192. iconClass: 'el-icon-warning'
  193. })
  194. }
  195. }
  196. }).catch(err => {
  197. this.$toast({
  198. message: err.errMsg,
  199. iconClass: 'el-icon-error'
  200. })
  201. })
  202. },
  203. getJsonp: function (url, timeout = 500) {
  204. return new Promise((resolve, reject) => {
  205. this.$jsonp(url, {
  206. name: 'successCallback',
  207. timeout: timeout
  208. }, function (err, data) {
  209. if (err) {
  210. reject(err)
  211. throw err
  212. } else {
  213. resolve(data)
  214. }
  215. })
  216. })
  217. },
  218. crossAfter (url) {
  219. try {
  220. window.location.href = url
  221. } catch (err) {
  222. console.log(err)
  223. }
  224. },
  225. loginOther (response, a, timeout) {
  226. const crossAfter = this.crossAfter
  227. let promises = []
  228. for (let i in response.data.content.loginUrls) {
  229. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  230. }
  231. Promise.all(promises).then(() => {
  232. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  233. }).catch(() => {
  234. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  235. })
  236. }
  237. }
  238. }
  239. </script>