loginMobile.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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"></mt-field>
  8. </div>
  9. <template v-if="showCheckCode">
  10. <div class="page-part">
  11. <mt-field placeholder="验证码" v-model="login.captcha">
  12. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  13. </mt-field>
  14. </div>
  15. </template>
  16. <div class="page-part">
  17. <mt-button size="large" type="primary" @click="checkLogin(true)">登录</mt-button>
  18. </div>
  19. <div class="login-btn">
  20. <p>还没有优软云账号?</p>
  21. <mt-button size="large" plain type="primary" @click="jump">立即注册</mt-button>
  22. </div>
  23. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  24. <ul style="height:100vh;overflow-y:auto">
  25. <li class="listitem itemgreen">选择您要登录的公司:</li>
  26. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  27. </ul>
  28. </mt-popup>
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. name: 'loginMobile',
  34. data () {
  35. return {
  36. loading: false,
  37. popupVisible: false,
  38. imgSrc: '',
  39. showCheckCode: false,
  40. login: {
  41. username: '',
  42. password: '',
  43. spaceUU: '',
  44. captcha: ''
  45. },
  46. appId: '',
  47. returnUrl: '',
  48. baseUrl: ''
  49. }
  50. },
  51. mounted () {
  52. this.$nextTick(() => {
  53. this.getUrl()
  54. })
  55. },
  56. computed: {
  57. enterprise () {
  58. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  59. }
  60. },
  61. methods: {
  62. selectEnterprise (flag, type) {
  63. this.login.spaceUU = type
  64. this.toLogin(flag)
  65. },
  66. jump () {
  67. if (this.appId === 'mall') {
  68. window.location.href = `/register/personalRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  69. } else {
  70. window.location.href = `/register/enterpriseRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  71. }
  72. },
  73. getUrl () {
  74. let url = window.location.search
  75. let request = {}
  76. if (url.indexOf('?' !== -1)) {
  77. let str = url.substr(1)
  78. let strs = str.split('&')
  79. for (let i = 0; i < strs.length; i++) {
  80. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  81. }
  82. }
  83. this.appId = request['appId'] || ''
  84. this.returnUrl = request['returnUrl'] || ''
  85. this.baseUrl = request['baseUrl'] || ''
  86. },
  87. getCode () {
  88. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  89. },
  90. checkLogin (flag) {
  91. if (!this.login.username) {
  92. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  93. } else if (!this.login.password) {
  94. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  95. } else {
  96. this.toLogin(flag)
  97. }
  98. },
  99. codeCount () {
  100. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  101. .then(response => {
  102. if (response.data.success) {
  103. let count = response.data.content || ''
  104. if (count >= 3 && count < 5) {
  105. this.showCheckCode = true
  106. let _this = this
  107. setTimeout(function () {
  108. _this.getCode()
  109. }, 100)
  110. this.$toast({
  111. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  112. iconClass: 'el-icon-warning'
  113. })
  114. }
  115. }
  116. return Promise.reject(response.data)
  117. }).catch(() => {
  118. this.$indicator.close()
  119. })
  120. },
  121. toLogin (flag) {
  122. this.$indicator.open('登录中...')
  123. let param = new FormData()
  124. param.append('username', this.login.username)
  125. param.append('password', this.login.password)
  126. param.append('captcha', this.login.captcha)
  127. param.append('appId', this.appId)
  128. param.append('returnUrl', this.returnUrl)
  129. param.append('baseUrl', this.baseUrl)
  130. param.append('spaceUU', this.login.spaceUU)
  131. let config = {
  132. headers: {'Content-Type': 'multipart/form-data'}
  133. }
  134. this.$http.post('/sso/login', param, config)
  135. .then(response => {
  136. this.$indicator.close()
  137. if (response.data.success) {
  138. // 弹框用户选择企业
  139. if (response.data.content.spaces) {
  140. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  141. this.popupVisible = flag
  142. } else if (response.data.content.loginUrls) {
  143. // 遍历登录url循环让各个应用登录
  144. for (let i in response.data.content.loginUrls) {
  145. this.$jsonp(`${response.data.content.loginUrls[i]}`, function (err) {
  146. if (err) throw err
  147. })
  148. }
  149. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  150. }
  151. }
  152. return Promise.reject(response.data)
  153. }).catch(err => {
  154. this.$toast({
  155. message: err.errMsg,
  156. iconClass: 'el-icon-error'
  157. })
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style type="text/scss" lang="scss">
  164. ::-webkit-scrollbar {
  165. width: 0;
  166. height: 1px;
  167. }
  168. ::-webkit-scrollbar-thumb {
  169. border-radius: 5px;
  170. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  171. background: rgba(0, 0, 0, 0.2);
  172. }
  173. .itemgreen{
  174. color:#2d8cf0;
  175. }
  176. .listitem {
  177. height: 1rem;
  178. line-height: 1rem;
  179. border-bottom: solid 1px #eee;
  180. text-align: center;
  181. &:first-child {
  182. border-top: solid 1px #eee;
  183. }
  184. }
  185. .mint-popup {
  186. width: 100%;
  187. height: 100%;
  188. background-color: #fff;
  189. }
  190. .mint-popup .mint-button {
  191. position: absolute;
  192. width: 90%;
  193. top: 50%;
  194. left: 5%;
  195. transform: translateY(-50%);
  196. }
  197. .mint-button .mint-button-text{
  198. margin: 0;
  199. font-weight: normal;
  200. }
  201. .login-btn{
  202. margin-top:.9rem;
  203. border-top:1px solid #bfbfbf;
  204. text-align: center;
  205. padding-top:.3rem;
  206. p{
  207. color:#a1a1a1;
  208. font-size: .26rem;
  209. margin-bottom:.4rem;
  210. }
  211. }
  212. </style>