loginMobile.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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="pwd"><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.toLogin(flag)
  68. },
  69. jump () {
  70. if (this.appId === 'mall') {
  71. window.location.href = `/register/personalRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  72. } else {
  73. window.location.href = `/register/enterpriseRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  74. }
  75. },
  76. getUrl () {
  77. this.appId = this.$store.state.option.appId
  78. this.returnUrl = this.$store.state.option.returnUrl
  79. this.baseUrl = this.$store.state.option.baseUrl
  80. },
  81. getCode () {
  82. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  83. },
  84. checkLogin (flag) {
  85. if (!this.login.username) {
  86. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  87. } else if (!this.login.password) {
  88. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  89. } else {
  90. this.toLogin(flag)
  91. }
  92. },
  93. codeCount () {
  94. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  95. .then(response => {
  96. if (response.data.success) {
  97. let count = response.data.content || ''
  98. if (count >= 3 && count < 5) {
  99. this.showCheckCode = true
  100. this.getCode()
  101. this.$toast({
  102. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  103. iconClass: 'el-icon-warning'
  104. })
  105. } else if (count === 5) {
  106. this.$toast({
  107. message: '密码错误次数已达上限,今日无法登陆',
  108. iconClass: 'el-icon-warning'
  109. })
  110. }
  111. } else {
  112. this.$toast({
  113. message: response.data.errMsg,
  114. iconClass: 'el-icon-warning'
  115. })
  116. }
  117. }).catch(err => {
  118. this.$toast({
  119. message: err.errMsg,
  120. iconClass: 'el-icon-warning'
  121. })
  122. })
  123. },
  124. toLogin (flag) {
  125. this.$indicator.open('登录中...')
  126. let param = new FormData()
  127. param.append('username', this.login.username)
  128. param.append('password', this.login.password)
  129. param.append('captcha', this.login.captcha)
  130. param.append('appId', this.appId)
  131. param.append('returnUrl', this.returnUrl)
  132. param.append('baseUrl', this.baseUrl)
  133. param.append('spaceUU', this.login.spaceUU)
  134. let config = {
  135. headers: {'Content-Type': 'multipart/form-data'}
  136. }
  137. this.$http.post('/sso/login', param, config)
  138. .then(response => {
  139. this.$indicator.close()
  140. if (response.data.success) {
  141. // 弹框用户选择企业
  142. if (response.data.content.spaces) {
  143. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  144. this.popupVisible = flag
  145. } else if (response.data.content.loginUrls) {
  146. // 遍历登录url循环让各个应用登录
  147. let param = response.data.content.data
  148. let a = ''
  149. for (let n in param) {
  150. a += (n + '=' + param[n] + '&')
  151. }
  152. for (let i in response.data.content.loginUrls) {
  153. this.$jsonp(`${response.data.content.loginUrls[i]}`, {param: a.substr(0, a.length - 1)}, function (err) {
  154. if (err) throw err
  155. })
  156. }
  157. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  158. }
  159. } else {
  160. this.login.password = ''
  161. this.$toast({
  162. message: response.data.errMsg,
  163. iconClass: 'el-icon-error'
  164. })
  165. let count = response.data.errorCount
  166. if (count >= 3 && count < 5) {
  167. this.showCheckCode = true
  168. this.getCode()
  169. let _this = this
  170. setTimeout(function () {
  171. _this.getCode()
  172. }, 100)
  173. this.$toast({
  174. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  175. iconClass: 'el-icon-warning'
  176. })
  177. }
  178. }
  179. }).catch(err => {
  180. this.$toast({
  181. message: err.errMsg,
  182. iconClass: 'el-icon-error'
  183. })
  184. })
  185. }
  186. }
  187. }
  188. </script>
  189. <style type="text/scss" lang="scss">
  190. ::-webkit-scrollbar {
  191. width: 0;
  192. height: 1px;
  193. }
  194. ::-webkit-scrollbar-thumb {
  195. border-radius: 5px;
  196. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  197. background: rgba(0, 0, 0, 0.2);
  198. }
  199. .pwd {
  200. font-size: .14rem;
  201. color: #a0a0a0;
  202. margin: .2rem auto;
  203. text-align: right;
  204. }
  205. .itemgreen{
  206. color:#2d8cf0;
  207. }
  208. .listitem {
  209. height: 1rem;
  210. line-height: 1rem;
  211. border-bottom: solid 1px #eee;
  212. text-align: center;
  213. &:first-child {
  214. border-top: solid 1px #eee;
  215. }
  216. }
  217. .mint-popup {
  218. width: 100%;
  219. height: 100%;
  220. background-color: #fff;
  221. }
  222. .mint-popup .mint-button {
  223. position: absolute;
  224. width: 90%;
  225. top: 50%;
  226. left: 5%;
  227. transform: translateY(-50%);
  228. }
  229. .mint-button .mint-button-text{
  230. margin: 0;
  231. font-weight: normal;
  232. }
  233. .login-btn{
  234. margin-top:.9rem;
  235. border-top:1px solid #bfbfbf;
  236. text-align: center;
  237. padding-top:.3rem;
  238. p{
  239. color:#a1a1a1;
  240. font-size: .26rem;
  241. margin-bottom:.4rem;
  242. }
  243. }
  244. </style>