Login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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" id='forget' @click="goForgetPassword">忘记密码?</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 id="register" @click="goRegister">
  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. <loading v-show="isShowLoading"/>
  89. </div>
  90. </template>
  91. <script>
  92. import Loading from '~components/common/loading/Loading.vue'
  93. export default {
  94. name: 'login',
  95. components: {
  96. Loading
  97. },
  98. data () {
  99. var validateUsername = (rule, value, callback) => {
  100. if (value === '') {
  101. this.checkUsername = false
  102. this.showCheckCode = false
  103. } else {
  104. if (this.login.username !== '') {
  105. // 获取密码输错次数
  106. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  107. .then(response => {
  108. if (response.data) {
  109. this.showCheckCode = false
  110. let getPasswordErrorCount = response.data.content || ''
  111. if (getPasswordErrorCount >= 5) {
  112. this.$message.error('密码错误次数已达上限,今日无法登陆')
  113. this.isLoginDisabled = true
  114. this.showCheckCode = false
  115. } else if (getPasswordErrorCount < 3) {
  116. this.isLoginDisabled = false
  117. this.checkUsername = true
  118. this.showCheckCode = false
  119. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  120. if (getPasswordErrorCount === 3) {
  121. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  122. }
  123. this.isLoginDisabled = false
  124. this.checkUsername = true
  125. this.showCheckCode = true
  126. } else {
  127. this.checkUsername = false
  128. this.showCheckCode = false
  129. }
  130. }
  131. }, err => {
  132. this.$message.error(err)
  133. })
  134. }
  135. callback()
  136. }
  137. }
  138. var validatePassword = (rule, value, callback) => {
  139. if (value === '') {
  140. this.checkPassword = false
  141. } else {
  142. if (this.login.password !== '') {
  143. this.checkPassword = true
  144. }
  145. callback()
  146. }
  147. }
  148. return {
  149. login: {
  150. username: '',
  151. password: '',
  152. captcha: '',
  153. spaceUU: ''
  154. },
  155. isShowLoading: false,
  156. checkUsername: false,
  157. checkPassword: false,
  158. showCheckCode: false,
  159. isLoginDisabled: false,
  160. dialogVisible: false,
  161. rules2: {
  162. username: [
  163. {validator: validateUsername, trigger: 'blur'}
  164. ],
  165. password: [
  166. {validator: validatePassword, trigger: 'blur'}
  167. ]
  168. }
  169. }
  170. },
  171. mounted () {
  172. this.$nextTick(() => {
  173. this.getUrl()
  174. })
  175. },
  176. computed: {
  177. enterprise () {
  178. let chooseEnterprise = this.$store.state.login.chooseRegisterEnterprise.choose.data
  179. // console.log(chooseEnterprise)
  180. return chooseEnterprise
  181. }
  182. },
  183. methods: {
  184. // 获取url参数
  185. getUrl () {
  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. this.appId = request['appId'] || ''
  196. this.returnUrl = request['returnUrl'] || ''
  197. this.baseUrl = request['baseUrl'] || ''
  198. },
  199. // 忘记密码
  200. goForgetPassword () {
  201. let url = `/reset/forgetPasswordValidationAccount?appId=${this.appId}&returnUrl=${this.returnUrl}`
  202. document.getElementById('forget').href = url
  203. },
  204. // 去注册
  205. goRegister () {
  206. if (this.appId === 'mall') {
  207. var registerurl = `/register/personalRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  208. } else {
  209. registerurl = `/register/enterpriseRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  210. }
  211. document.getElementById('register').href = registerurl
  212. },
  213. // 获取验证码
  214. getCode () {
  215. var imgSrc = document.getElementById('captchaImage')
  216. imgSrc.setAttribute('src', '/sso/login/checkCode?timestamp=' + (new Date()).valueOf())
  217. },
  218. // 登录
  219. isLogin (flag) {
  220. this.isShowLoading = true
  221. if (!this.checkUsername) {
  222. this.$message.error('请填写账号')
  223. } else if (!this.checkPassword) {
  224. this.$message.error('请填写密码')
  225. } else {
  226. let param = new FormData()
  227. param.append('username', this.login.username)
  228. param.append('password', this.login.password)
  229. param.append('captcha', this.login.captcha)
  230. param.append('appId', this.appId)
  231. param.append('returnUrl', this.returnUrl)
  232. param.append('baseUrl', this.baseUrl)
  233. param.append('spaceUU', this.login.spaceUU)
  234. let config = {
  235. headers: {'Content-Type': 'multipart/form-data'}
  236. }
  237. this.$http.post('/sso/login', param, config)
  238. .then(response => {
  239. if (response.data.success) {
  240. this.isShowLoading = false
  241. // console.log(response.data.content)
  242. if (response.data.content.spaces) {
  243. // 弹框让用户选择企业
  244. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  245. this.dialogVisible = flag
  246. } else if (response.data.content.loginUrls) {
  247. // 遍历登录url循环让各应用登录(需要跨域)
  248. for (var i in response.data.content.loginUrls) {
  249. // this.$http.post(response.data.content.loginUrls[i], response.data.content.data)
  250. this.$jsonp(`response.data.content.loginUrls${[i]}`, function (err, data) {
  251. if (err) throw err
  252. console.log(data)
  253. })
  254. }
  255. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  256. }
  257. } else {
  258. this.$message.error(response.data)
  259. var count = response.data.errorCount
  260. if (count < 3) {
  261. this.showCheckCode = false
  262. this.isLoginDisabled = false
  263. } else if (count >= 5) {
  264. this.$message.error('密码错误次数已达上限,今日无法登陆')
  265. this.isLoginDisabled = true
  266. this.showCheckCode = false
  267. } else if (count >= 3 && count < 5) {
  268. this.getCode()
  269. if (count === 3) {
  270. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  271. }
  272. this.showCheckCode = true
  273. this.isLoginDisabled = false
  274. }
  275. return Promise.reject(response.data)
  276. }
  277. }).catch(err => {
  278. this.isShowLoading = false
  279. let _this = this
  280. setTimeout(function () {
  281. _this.getCode()
  282. }, 100)
  283. this.$message.error(err.errMsg)
  284. })
  285. }
  286. },
  287. chooseOneEnterprise (flag, spaceUU) {
  288. this.login.spaceUU = spaceUU
  289. this.isLogin(flag)
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .x-container{
  296. position: relative;
  297. height: 475px;
  298. /*登录弹出框*/
  299. .x-floating {
  300. position: fixed;
  301. top: 80px;
  302. left: 50%;
  303. z-index: 100000;
  304. opacity: 1;
  305. -webkit-transition: all .5s;
  306. -moz-transition: all .5s;
  307. transition: all .5s;
  308. }
  309. .x-list {
  310. width: 306px;
  311. margin-left: -153px;
  312. background: #fff;
  313. border-top: 1px solid #e7e7e7;
  314. cursor: pointer;
  315. .x-list-header {
  316. padding: 10px 20px;
  317. background: #e0e0e0;
  318. width: 306px;
  319. height: 42px;
  320. line-height: 21px;
  321. font-size: 14px;
  322. font-weight: 700;
  323. color: #505050;
  324. }
  325. ul{
  326. margin-bottom: 0;
  327. li{
  328. padding: 10px 20px;
  329. width: 306px;
  330. height: 42px;
  331. line-height: 21px;
  332. font-size: 12px;
  333. color: #505050;
  334. border-bottom: 1px solid #e7e7e7;
  335. &:hover{
  336. background: #e7e7e7;
  337. }
  338. }
  339. }
  340. .x-list .x-list-header, .x-list li {
  341. padding: 10px 20px;
  342. border-bottom: 1px solid #e7e7e7;
  343. }
  344. }
  345. .x-floating.in {
  346. top: 80px;
  347. opacity: 1;
  348. }
  349. .x-banner-wrap {
  350. position: absolute;
  351. left: 0;
  352. top: 0;
  353. width: 100%;
  354. height: 475px;
  355. .x-banner {
  356. position: relative;
  357. overflow: auto;
  358. height: 475px;
  359. text-align: center;
  360. li{
  361. width: 100%;
  362. height: 475px;
  363. background: url(/images/all/banner.jpg) center center / auto 100% no-repeat rgb(202, 202, 214);
  364. }
  365. }
  366. }
  367. .x-login-wrap{
  368. position: absolute;
  369. top: 10px;
  370. right: 50%;
  371. margin-right: -495px;
  372. height: 475px;
  373. z-index: 5;
  374. .x-login {
  375. position: relative;
  376. top: 40px;
  377. width: 346px;
  378. background: #fff;
  379. overflow: visible;
  380. z-index: 4;
  381. .x-login-form, .x-login-qrcode {
  382. padding: 20px;
  383. .btn{
  384. background: #5078cb;
  385. color: #fff;
  386. font-weight: 700;
  387. letter-spacing: 4px;
  388. border-radius: 0;
  389. }
  390. .x-has-feedback-right {
  391. float: right;
  392. display: inline-block;
  393. a{
  394. color: #5078cb;
  395. }
  396. }
  397. .x-has-feedback-left {
  398. position: relative;
  399. .x-input {
  400. padding-left: 30px;
  401. line-height: 18px;
  402. color: #555;
  403. border-color: #ccc;
  404. border-radius: 0;
  405. box-shadow: none;
  406. }
  407. i.fa{
  408. position: absolute;
  409. top: 2px;
  410. left: 0;
  411. z-index: 2;
  412. display: block;
  413. width: 30px;
  414. height: 34px;
  415. line-height: 34px;
  416. text-align: center;
  417. pointer-events: none;
  418. color: #999;
  419. font-size: 18px;
  420. }
  421. }
  422. i.fa-keyboard-o{
  423. position: absolute;
  424. right: 10px;
  425. top: 10px;
  426. }
  427. i.fa-arrow-circle-o-right{
  428. margin-right: 5px;
  429. font-size: 14px;
  430. color: #5078cb;
  431. }
  432. .warn-text-area{
  433. margin-top: 5px;
  434. font-size: 13px;
  435. color: #000;
  436. }
  437. }
  438. .x-login-qrcode{
  439. display: none;
  440. }
  441. }
  442. }
  443. }
  444. </style>