loginMobile.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. if (this.appId === 'mall') {
  76. window.location.href = `/register/personalRegistration${this.$store.state.option.fullPath}`
  77. } else {
  78. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  79. }
  80. },
  81. getUrl () {
  82. this.appId = this.$store.state.option.appId
  83. this.returnUrl = this.$store.state.option.returnUrl
  84. this.baseUrl = this.$store.state.option.baseUrl
  85. },
  86. getCode () {
  87. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  88. },
  89. checkLogin (flag) {
  90. if (!this.login.username) {
  91. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  92. } else if (!this.login.password) {
  93. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  94. } else {
  95. this.toLogin(flag)
  96. }
  97. },
  98. codeCount () {
  99. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  100. .then(response => {
  101. if (response.data.success) {
  102. let count = response.data.content || ''
  103. if (count >= 3 && count < 5) {
  104. this.showCheckCode = true
  105. this.getCode()
  106. this.$toast({
  107. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  108. iconClass: 'el-icon-warning'
  109. })
  110. } else if (count === 5) {
  111. this.$toast({
  112. message: '密码错误次数已达上限,今日无法登陆',
  113. iconClass: 'el-icon-warning'
  114. })
  115. }
  116. } else {
  117. this.$toast({
  118. message: response.data.errMsg,
  119. iconClass: 'el-icon-warning'
  120. })
  121. }
  122. }).catch(err => {
  123. this.$toast({
  124. message: err.errMsg,
  125. iconClass: 'el-icon-warning'
  126. })
  127. })
  128. },
  129. toLogin (flag) {
  130. this.$indicator.open('登录中...')
  131. let param = new FormData()
  132. param.append('username', this.login.username)
  133. param.append('password', this.login.password)
  134. param.append('captcha', this.login.captcha)
  135. param.append('appId', this.appId)
  136. param.append('returnUrl', this.returnUrl)
  137. param.append('baseUrl', this.baseUrl)
  138. param.append('spaceUU', this.login.spaceUU)
  139. let config = {
  140. headers: {'Content-Type': 'multipart/form-data'}
  141. }
  142. this.$http.post('/sso/login', param, config)
  143. .then(response => {
  144. this.$indicator.close()
  145. if (response.data.success) {
  146. // 弹框用户选择企业
  147. if (response.data.content.spaces) {
  148. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  149. this.popupVisible = flag
  150. } else if (response.data.content.loginUrls) {
  151. // 遍历登录url循环让各个应用登录
  152. let param = response.data.content.data
  153. let a = ''
  154. for (let n in param) {
  155. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  156. }
  157. let params = a.substr(0, a.length - 1)
  158. this.$indicator.open('跳转中...')
  159. if (response.data.content.currentUrl) {
  160. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  161. name: 'successCallback',
  162. timeout: 5000
  163. }, (err, data) => {
  164. if (err) {
  165. this.$indicator.close()
  166. this.$toast({
  167. message: '登录超时,请重试',
  168. iconClass: 'el-icon-error'
  169. })
  170. this.login.spaceUU = ''
  171. throw err
  172. } else {
  173. this.loginOther(response, params)
  174. }
  175. })
  176. } else {
  177. this.loginOther(response, params, 3000)
  178. }
  179. }
  180. } else {
  181. this.login.password = ''
  182. this.$toast({
  183. message: response.data.errMsg,
  184. iconClass: 'el-icon-error'
  185. })
  186. let count = response.data.errorCount
  187. if (count >= 3 && count < 5) {
  188. this.showCheckCode = true
  189. this.getCode()
  190. let _this = this
  191. setTimeout(function () {
  192. _this.getCode()
  193. }, 100)
  194. this.$toast({
  195. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  196. iconClass: 'el-icon-warning'
  197. })
  198. }
  199. }
  200. }).catch(err => {
  201. this.$toast({
  202. message: err.errMsg,
  203. iconClass: 'el-icon-error'
  204. })
  205. })
  206. },
  207. getJsonp: function (url, timeout = 500) {
  208. return new Promise((resolve, reject) => {
  209. this.$jsonp(url, {
  210. name: 'successCallback',
  211. timeout: timeout
  212. }, function (err, data) {
  213. if (err) {
  214. reject(err)
  215. throw err
  216. } else {
  217. resolve(data)
  218. }
  219. })
  220. })
  221. },
  222. crossAfter (url) {
  223. try {
  224. window.location.href = url
  225. } catch (err) {
  226. console.log(err)
  227. }
  228. },
  229. loginOther (response, a, timeout) {
  230. const crossAfter = this.crossAfter
  231. let promises = []
  232. for (let i in response.data.content.loginUrls) {
  233. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  234. }
  235. Promise.all(promises).then(() => {
  236. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  237. }).catch(() => {
  238. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  239. })
  240. }
  241. }
  242. }
  243. </script>