loginMobile.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 + '=' + param[n] + '&')
  156. }
  157. // for (let i in response.data.content.loginUrls) {
  158. // this.$jsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1), function (err) {
  159. // if (err) throw err
  160. // })
  161. // }
  162. this.$indicator.open('跳转中...')
  163. const crossAfter = this.crossAfter
  164. let promises = []
  165. for (let i in response.data.content.loginUrls) {
  166. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
  167. }
  168. Promise.all(promises).then(() => {
  169. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  170. }).catch(() => {
  171. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  172. })
  173. // setTimeout(function () {
  174. // window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  175. // }, 3000)
  176. }
  177. } else {
  178. this.login.password = ''
  179. this.$toast({
  180. message: response.data.errMsg,
  181. iconClass: 'el-icon-error'
  182. })
  183. let count = response.data.errorCount
  184. if (count >= 3 && count < 5) {
  185. this.showCheckCode = true
  186. this.getCode()
  187. let _this = this
  188. setTimeout(function () {
  189. _this.getCode()
  190. }, 100)
  191. this.$toast({
  192. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  193. iconClass: 'el-icon-warning'
  194. })
  195. }
  196. }
  197. }).catch(err => {
  198. this.$toast({
  199. message: err.errMsg,
  200. iconClass: 'el-icon-error'
  201. })
  202. })
  203. },
  204. getJsonp: function (url) {
  205. return new Promise((resolve, reject) => {
  206. this.$jsonp(url, {
  207. name: 'successCallback',
  208. timeout: 200
  209. }, function (err, data) {
  210. if (err) {
  211. reject(err)
  212. throw err
  213. } else {
  214. resolve(data)
  215. }
  216. })
  217. })
  218. },
  219. crossAfter (url) {
  220. try {
  221. window.location.href = url
  222. } catch (err) {
  223. console.log(err)
  224. }
  225. }
  226. }
  227. }
  228. </script>