loginMobile.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 href="/reset/forgetPasswordValidationAccount" 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. jump () {
  71. if (this.appId === 'mall') {
  72. window.location.href = `/register/personalRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  73. } else {
  74. window.location.href = `/register/enterpriseRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  75. }
  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 + '=' + param[n] + '&')
  152. }
  153. for (let i in response.data.content.loginUrls) {
  154. this.$jsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1), function (err) {
  155. if (err) throw err
  156. })
  157. }
  158. this.$indicator.open('跳转中...')
  159. setTimeout(function () {
  160. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  161. }, 3000)
  162. }
  163. } else {
  164. this.login.password = ''
  165. this.$toast({
  166. message: response.data.errMsg,
  167. iconClass: 'el-icon-error'
  168. })
  169. let count = response.data.errorCount
  170. if (count >= 3 && count < 5) {
  171. this.showCheckCode = true
  172. this.getCode()
  173. let _this = this
  174. setTimeout(function () {
  175. _this.getCode()
  176. }, 100)
  177. this.$toast({
  178. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  179. iconClass: 'el-icon-warning'
  180. })
  181. }
  182. }
  183. }).catch(err => {
  184. this.$toast({
  185. message: err.errMsg,
  186. iconClass: 'el-icon-error'
  187. })
  188. })
  189. }
  190. }
  191. }
  192. </script>