Login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <div class="x-container">
  3. <!-- background slider -->
  4. <div class="x-banner-wrap">
  5. <div class="x-banner">
  6. <ul class="list-unstyled">
  7. <li>
  8. <a>
  9. <div class="inner">
  10. <div class="x-title x-text-0"></div>
  11. <div class="x-subtitle x-text-0"></div>
  12. <div class="x-btn-group">
  13. </div>
  14. </div>
  15. </a>
  16. </li>
  17. </ul>
  18. </div>
  19. </div>
  20. <div class="x-login-wrap">
  21. <div class="x-login">
  22. <!-- user & pwd login wrap -->
  23. <div id="form-wrap" class="x-login-form">
  24. <div>
  25. <el-form :model="login" :rules="rules2" ref="login" class="demo-ruleForm login-form">
  26. <el-form-item prop="username">
  27. <el-input type="text" v-model="login.username" auto-complete="off" placeholder="手机号/邮箱/账号ID"></el-input>
  28. <i class="fa fa-user"></i>
  29. </el-form-item>
  30. <el-form-item prop="password">
  31. <el-input type="password" v-model="login.password" auto-complete="off" placeholder="密码"></el-input>
  32. <i class="fa fa-lock"></i>
  33. </el-form-item>
  34. <el-form-item prop="captcha" class="captcha" v-show="showCheckCode">
  35. <el-input type="text" v-model="login.captcha" auto-complete="off" class="code-input"></el-input>
  36. <img id="captchaImage" class="code-img" src="/sso/login/checkCode"/>
  37. <a class="code-click" @click="getCode">看不清换一张</a>
  38. </el-form-item>
  39. <el-form-item class="text-right">
  40. <a class="forget">忘记密码?</a>
  41. </el-form-item>
  42. <el-form-item>
  43. <a class="btn login"
  44. @click="isLogin(true)"
  45. :disabled="isLoginDisabled">登录</a>
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <div class="warn-text-area">
  50. 为确保您账户的安全及正常使用,依《网络安全法》相关要求,6月1日起会员账户需绑定手机、设置密码保护。感谢您的理解和支持!
  51. </div>
  52. <div style="text-align: right;">
  53. <a href="sso/register_mall?appId=home&amp;returnURL=https%3A%2F%2Fwww.ubtob.com%2F">
  54. <i class="fa fa-arrow-circle-o-right"></i>免费注册</a>
  55. </div>
  56. </div>
  57. <!-- qrcode login wrap -->
  58. <div id="qrcode-wrap" class="x-login-qrcode">
  59. <div class="x-qrcode-help">
  60. <span>打开手机客户端,扫描下面的二维码</span>
  61. </div>
  62. <div class="x-qrcode-img">
  63. <img src="/images/all/qrcode.jpg">
  64. </div>
  65. <div class="x-qrcode-ex">
  66. <ul class="list-unstyled list-inline">
  67. <li><i class="iconfont icon-left icon-input"></i><span>免输入</span></li>
  68. <li><i class="iconfont icon-left icon-fast"></i><span>更快捷</span></li>
  69. <li><i class="iconfont icon-left icon-safe"></i><span>更安全</span></li>
  70. </ul>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <!--选择企业弹出框-->
  76. <div>
  77. <el-dialog class="dialog"
  78. :visible.sync="dialogVisible"
  79. size="tiny">
  80. <div class="x-floating x-list">
  81. <div class="x-list-header">您要登录的公司是:</div>
  82. <ul class="list-unstyled" v-for="space in this.enterprise">
  83. <li v-text="space.name" @click="chooseOneEnterprise(false, space.id)">华商龙科技有限公司</li>
  84. </ul>
  85. </div>
  86. </el-dialog>
  87. </div>
  88. </div>
  89. </template>
  90. <script>
  91. export default {
  92. name: 'login',
  93. data () {
  94. var validateUsername = (rule, value, callback) => {
  95. if (value === '') {
  96. this.checkUsername = false
  97. this.showCheckCode = false
  98. } else {
  99. if (this.login.username !== '') {
  100. // 获取密码输错次数
  101. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  102. .then(response => {
  103. if (response.data) {
  104. this.showCheckCode = false
  105. let getPasswordErrorCount = response.data.content || ''
  106. if (getPasswordErrorCount >= 5) {
  107. this.$message.error('密码错误次数已达上限,今日无法登陆')
  108. this.isLoginDisabled = true
  109. this.showCheckCode = false
  110. } else if (getPasswordErrorCount < 3) {
  111. this.isLoginDisabled = false
  112. this.checkUsername = true
  113. this.showCheckCode = false
  114. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  115. if (getPasswordErrorCount === 3) {
  116. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  117. }
  118. this.isLoginDisabled = false
  119. this.checkUsername = true
  120. this.showCheckCode = true
  121. } else {
  122. this.checkUsername = false
  123. this.showCheckCode = false
  124. }
  125. }
  126. }, err => {
  127. this.$message.error(err)
  128. console.log(err)
  129. })
  130. }
  131. callback()
  132. }
  133. }
  134. var validatePassword = (rule, value, callback) => {
  135. if (value === '') {
  136. this.checkPassword = false
  137. } else {
  138. if (this.login.password !== '') {
  139. this.checkPassword = true
  140. }
  141. callback()
  142. }
  143. }
  144. return {
  145. login: {
  146. username: '',
  147. password: '',
  148. captcha: '',
  149. spaceUU: ''
  150. },
  151. checkUsername: false,
  152. checkPassword: false,
  153. showCheckCode: false,
  154. isLoginDisabled: false,
  155. dialogVisible: false,
  156. rules2: {
  157. username: [
  158. {validator: validateUsername, trigger: 'blur'}
  159. ],
  160. password: [
  161. {validator: validatePassword, trigger: 'blur'}
  162. ]
  163. }
  164. }
  165. },
  166. computed: {
  167. enterprise () {
  168. let chooseEnterprise = this.$store.state.login.chooseRegisterEnterprise.choose.data
  169. // console.log(chooseEnterprise)
  170. return chooseEnterprise
  171. }
  172. },
  173. methods: {
  174. // 获取验证码
  175. getCode () {
  176. var imgSrc = document.getElementById('captchaImage')
  177. imgSrc.setAttribute('src', '/sso/login/checkCode?timestamp=' + (new Date()).valueOf())
  178. },
  179. // 登录
  180. isLogin (flag) {
  181. if (!this.checkUsername) {
  182. this.$message.error('请填写账号')
  183. } else if (!this.checkPassword) {
  184. this.$message.error('请填写密码')
  185. } else {
  186. var url = window.location.search
  187. var request = {}
  188. if (url.indexOf('?' !== -1)) {
  189. var str = url.substr(1)
  190. var strs = str.split('&')
  191. for (var i = 0; i < strs.length; i++) {
  192. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  193. }
  194. }
  195. var appId = request['appId'] || ''
  196. var returnUrl = request['returnUrl'] || ''
  197. var baseUrl = request['baseUrl'] || ''
  198. let param = new FormData()
  199. param.append('username', this.login.username)
  200. param.append('password', this.login.password)
  201. param.append('captcha', this.login.captcha)
  202. param.append('appId', appId)
  203. param.append('returnUrl', returnUrl)
  204. param.append('baseUrl', baseUrl)
  205. param.append('spaceUU', this.login.spaceUU)
  206. let config = {
  207. headers: {'Content-Type': 'multipart/form-data'}
  208. }
  209. this.$http.post('/sso/login', param, config)
  210. .then(response => {
  211. if (response.data.success) {
  212. console.log(response.data.content)
  213. if (response.data.content.spaces) {
  214. // 弹框让用户选择企业
  215. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  216. this.dialogVisible = flag
  217. } else if (response.data.content.loginUrls) {
  218. // 遍历登录url循环让各应用登录(需要跨域)
  219. for (var i in response.data.content.loginUrls) {
  220. this.$http.post(response.data.content.loginUrls[i], response.data.content.data)
  221. }
  222. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  223. }
  224. } else {
  225. this.$message.error(response.data)
  226. var count = response.data.errorCount
  227. if (count < 3) {
  228. this.showCheckCode = false
  229. this.isLoginDisabled = false
  230. } else if (count >= 5) {
  231. this.$message.error('密码错误次数已达上限,今日无法登陆')
  232. this.isLoginDisabled = true
  233. this.showCheckCode = false
  234. } else if (count >= 3 && count < 5) {
  235. this.getCode()
  236. if (count === 3) {
  237. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  238. }
  239. this.showCheckCode = true
  240. this.isLoginDisabled = false
  241. }
  242. return Promise.reject(response.data)
  243. }
  244. }).catch(err => {
  245. let _this = this
  246. setTimeout(function () {
  247. _this.getCode()
  248. }, 100)
  249. this.$message.error(err.errMsg)
  250. })
  251. }
  252. },
  253. chooseOneEnterprise (flag, spaceUU) {
  254. this.login.spaceUU = spaceUU
  255. this.isLogin(flag)
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .x-container{
  262. position: relative;
  263. height: 475px;
  264. /*登录弹出框*/
  265. .x-floating {
  266. position: fixed;
  267. top: 80px;
  268. left: 50%;
  269. z-index: 100000;
  270. opacity: 1;
  271. -webkit-transition: all .5s;
  272. -moz-transition: all .5s;
  273. transition: all .5s;
  274. }
  275. .x-list {
  276. width: 306px;
  277. margin-left: -153px;
  278. background: #fff;
  279. border-top: 1px solid #e7e7e7;
  280. cursor: pointer;
  281. .x-list-header {
  282. padding: 10px 20px;
  283. background: #e0e0e0;
  284. width: 306px;
  285. height: 42px;
  286. line-height: 21px;
  287. font-size: 14px;
  288. font-weight: 700;
  289. color: #505050;
  290. }
  291. ul{
  292. margin-bottom: 0;
  293. li{
  294. padding: 10px 20px;
  295. width: 306px;
  296. height: 42px;
  297. line-height: 21px;
  298. font-size: 12px;
  299. color: #505050;
  300. border-bottom: 1px solid #e7e7e7;
  301. &:hover{
  302. background: #e7e7e7;
  303. }
  304. }
  305. }
  306. .x-list .x-list-header, .x-list li {
  307. padding: 10px 20px;
  308. border-bottom: 1px solid #e7e7e7;
  309. }
  310. }
  311. .x-floating.in {
  312. top: 80px;
  313. opacity: 1;
  314. }
  315. .x-banner-wrap {
  316. position: absolute;
  317. left: 0;
  318. top: 0;
  319. width: 100%;
  320. height: 475px;
  321. .x-banner {
  322. position: relative;
  323. overflow: auto;
  324. height: 475px;
  325. text-align: center;
  326. li{
  327. width: 100%;
  328. height: 475px;
  329. background: url(/images/all/banner.jpg) center center / auto 100% no-repeat rgb(202, 202, 214);
  330. }
  331. }
  332. }
  333. .x-login-wrap{
  334. position: absolute;
  335. top: 10px;
  336. right: 50%;
  337. margin-right: -495px;
  338. height: 475px;
  339. z-index: 5;
  340. .x-login {
  341. position: relative;
  342. top: 40px;
  343. width: 346px;
  344. background: #fff;
  345. overflow: visible;
  346. z-index: 4;
  347. .x-login-form, .x-login-qrcode {
  348. padding: 20px;
  349. .btn{
  350. background: #5078cb;
  351. color: #fff;
  352. font-weight: 700;
  353. letter-spacing: 4px;
  354. border-radius: 0;
  355. }
  356. .x-has-feedback-right {
  357. float: right;
  358. display: inline-block;
  359. a{
  360. color: #5078cb;
  361. }
  362. }
  363. .x-has-feedback-left {
  364. position: relative;
  365. .x-input {
  366. padding-left: 30px;
  367. line-height: 18px;
  368. color: #555;
  369. border-color: #ccc;
  370. border-radius: 0;
  371. box-shadow: none;
  372. }
  373. i.fa{
  374. position: absolute;
  375. top: 2px;
  376. left: 0;
  377. z-index: 2;
  378. display: block;
  379. width: 30px;
  380. height: 34px;
  381. line-height: 34px;
  382. text-align: center;
  383. pointer-events: none;
  384. color: #999;
  385. font-size: 18px;
  386. }
  387. }
  388. i.fa-keyboard-o{
  389. position: absolute;
  390. right: 10px;
  391. top: 10px;
  392. }
  393. i.fa-arrow-circle-o-right{
  394. margin-right: 5px;
  395. font-size: 14px;
  396. color: #5078cb;
  397. }
  398. .warn-text-area{
  399. margin-top: 5px;
  400. font-size: 13px;
  401. color: #000;
  402. }
  403. }
  404. .x-login-qrcode{
  405. display: none;
  406. }
  407. }
  408. }
  409. }
  410. </style>