Login.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <div>
  3. <!--头部-->
  4. <nav class="x-navbar">
  5. <div class="container">
  6. <div class="navbar-header">
  7. <input type="hidden" name="iconUrl" value="/static/img/icon_mall_index.png">
  8. <a class="navbar-brand" id="navbar-brand" href="https://www.usoftmall.com/">
  9. 欢迎登录
  10. </a>
  11. </div>
  12. <div class="collapse navbar-collapse navbar-right">
  13. <a href="http://www.ubtob.com">优软云首页</a> <a href="http://uas.ubtob.com/serve#/">帮助</a>
  14. </div>
  15. </div>
  16. </nav>
  17. <div class="x-container">
  18. <!-- background slider -->
  19. <div class="x-banner-wrap">
  20. <div class="x-banner">
  21. <ul class="list-unstyled">
  22. <li id="bgStyle">
  23. <a>
  24. <div class="inner">
  25. <div class="x-title x-text-0"></div>
  26. <div class="x-subtitle x-text-0"></div>
  27. <div class="x-btn-group">
  28. </div>
  29. </div>
  30. </a>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. <div class="x-login-wrap">
  36. <div class="x-login">
  37. <!-- user & pwd login wrap -->
  38. <div id="form-wrap" class="x-login-form">
  39. <div>
  40. <el-form :model="login" :rules="rules2" ref="login" class="demo-ruleForm login-form">
  41. <el-form-item prop="username">
  42. <el-input type="text" v-model="login.username" auto-complete="off" placeholder="手机号/邮箱/账号ID"></el-input>
  43. <i class="fa fa-user"></i>
  44. </el-form-item>
  45. <el-form-item prop="password">
  46. <el-input type="password" v-model="login.password" auto-complete="off" placeholder="密码"></el-input>
  47. <i class="fa fa-lock"></i>
  48. </el-form-item>
  49. <el-form-item prop="captcha" class="captcha" v-show="showCheckCode">
  50. <el-input type="text" v-model="login.captcha" auto-complete="off" class="code-input"></el-input>
  51. <img id="captchaImage" class="code-img" src="/sso/login/checkCode"/>
  52. <a class="code-click" @click="getCode">看不清换一张</a>
  53. </el-form-item>
  54. <el-form-item class="text-right">
  55. <a class="forget" id='forget' @click="goForgetPassword">忘记密码?</a>
  56. </el-form-item>
  57. <el-form-item>
  58. <a class="btn login"
  59. @click="isLogin(true)"
  60. :disabled="isLoginDisabled">登录</a>
  61. </el-form-item>
  62. </el-form>
  63. </div>
  64. <div class="warn-text-area">
  65. 为确保您账户的安全及正常使用,依《网络安全法》相关要求,6月1日起会员账户需绑定手机、设置密码保护。感谢您的理解和支持!
  66. </div>
  67. <div class="link-go">
  68. <a href="appeals/changeManagerAppeal" class="first">更换管理员</a>
  69. <a id="register" @click="goRegister" class="second">
  70. <i class="fa fa-arrow-circle-o-right"></i>免费注册</a>
  71. </div>
  72. </div>
  73. <!-- qrcode login wrap -->
  74. <div id="qrcode-wrap" class="x-login-qrcode">
  75. <div class="x-qrcode-help">
  76. <span>打开手机客户端,扫描下面的二维码</span>
  77. </div>
  78. <div class="x-qrcode-img">
  79. <img src="/images/all/qrcode.jpg">
  80. </div>
  81. <div class="x-qrcode-ex">
  82. <ul class="list-unstyled list-inline">
  83. <li><i class="iconfont icon-left icon-input"></i><span>免输入</span></li>
  84. <li><i class="iconfont icon-left icon-fast"></i><span>更快捷</span></li>
  85. <li><i class="iconfont icon-left icon-safe"></i><span>更安全</span></li>
  86. </ul>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <!--选择企业弹出框-->
  92. <div>
  93. <el-dialog class="dialog"
  94. :visible.sync="dialogVisible"
  95. size="tiny">
  96. <div class="x-floating x-list" v-show="dialogVisible">
  97. <div class="x-list-header">您要登录的公司是:</div>
  98. <ul class="list-unstyled" v-for="space in this.enterprise">
  99. <li v-text="space.name" @click="chooseOneEnterprise(false, space.id)">华商龙科技有限公司</li>
  100. </ul>
  101. </div>
  102. </el-dialog>
  103. </div>
  104. <loading v-show="isShowLoading"/>
  105. </div>
  106. </div>
  107. </template>
  108. <script>
  109. import Loading from '~components/common/loading/Loading.vue'
  110. export default {
  111. name: 'login',
  112. components: {
  113. Loading
  114. },
  115. data () {
  116. var validateUsername = (rule, value, callback) => {
  117. if (value === '') {
  118. this.checkUsername = false
  119. this.showCheckCode = false
  120. } else {
  121. if (this.login.username !== '') {
  122. // 获取密码输错次数
  123. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  124. .then(response => {
  125. if (response.data) {
  126. this.showCheckCode = false
  127. let getPasswordErrorCount = response.data.content || ''
  128. if (getPasswordErrorCount >= 5) {
  129. this.$message.error('密码错误次数已达上限,今日无法登陆')
  130. this.isLoginDisabled = true
  131. this.showCheckCode = false
  132. } else if (getPasswordErrorCount < 3) {
  133. this.isLoginDisabled = false
  134. this.checkUsername = true
  135. this.showCheckCode = false
  136. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  137. if (getPasswordErrorCount === 3) {
  138. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  139. }
  140. this.isLoginDisabled = false
  141. this.checkUsername = true
  142. this.showCheckCode = true
  143. } else {
  144. this.checkUsername = false
  145. this.showCheckCode = false
  146. }
  147. }
  148. }, err => {
  149. this.$message.error(err)
  150. })
  151. }
  152. callback()
  153. }
  154. }
  155. var validatePassword = (rule, value, callback) => {
  156. if (value === '') {
  157. this.checkPassword = false
  158. } else {
  159. if (this.login.password !== '') {
  160. this.checkPassword = true
  161. }
  162. callback()
  163. }
  164. }
  165. return {
  166. login: {
  167. username: '',
  168. password: '',
  169. captcha: '',
  170. spaceUU: ''
  171. },
  172. isShowLoading: false,
  173. checkUsername: false,
  174. checkPassword: false,
  175. showCheckCode: false,
  176. isLoginDisabled: false,
  177. dialogVisible: false,
  178. rules2: {
  179. username: [
  180. {validator: validateUsername, trigger: 'blur'}
  181. ],
  182. password: [
  183. {validator: validatePassword, trigger: 'blur'}
  184. ]
  185. }
  186. }
  187. },
  188. mounted () {
  189. this.$nextTick(() => {
  190. this.getUrl()
  191. })
  192. this.$nextTick(() => {
  193. this.getLoginStyle()
  194. })
  195. },
  196. computed: {
  197. enterprise () {
  198. let chooseEnterprise = this.$store.state.login.chooseRegisterEnterprise.choose.data
  199. return chooseEnterprise
  200. }
  201. // loginUrl () {
  202. // console.log(this.$store.state.login.loginStyle.loginStyle.data)
  203. // return this.$store.state.login.loginStyle.loginStyle.data
  204. // }
  205. },
  206. methods: {
  207. // 获取url参数
  208. getUrl () {
  209. var url = window.location.search
  210. var request = {}
  211. if (url.indexOf('?' !== -1)) {
  212. var str = url.substr(1)
  213. var strs = str.split('&')
  214. for (var i = 0; i < strs.length; i++) {
  215. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  216. }
  217. }
  218. this.appId = request['appId'] || ''
  219. this.returnUrl = request['returnUrl'] || ''
  220. this.baseUrl = request['baseUrl'] || ''
  221. },
  222. // 获取后台返回的数据
  223. getLoginStyle () {
  224. this.$http.get(`/sso/login/page/style`, {params: {appId: this.appId}})
  225. .then(response => {
  226. if (response.data.success) {
  227. let logoUrlStyle = response.data.content.logoUrl
  228. let bgUrl = response.data.content.bgUrl
  229. let bgColor = response.data.content.bgColor
  230. let bgLink = response.data.content.bgLink
  231. document.getElementById('navbar-brand').style.backgroundImage = 'url(' + logoUrlStyle + ')'
  232. let bg = document.getElementById('bgStyle')
  233. bg.style.backgroundImage = 'url(' + bgUrl + ')'
  234. bg.style.backgroundColor = bgColor
  235. if (bgLink) {
  236. bg.onclick = function () {
  237. window.location.href = bgLink
  238. }
  239. }
  240. } else {
  241. return Promise.reject(response.data)
  242. }
  243. }).catch(err => {
  244. console.log(err)
  245. })
  246. },
  247. // 忘记密码
  248. goForgetPassword () {
  249. let url = `/reset/forgetPasswordValidationAccount?appId=${this.appId}&returnUrl=${this.returnUrl}`
  250. document.getElementById('forget').href = url
  251. },
  252. // 去注册
  253. goRegister () {
  254. if (this.appId === 'mall') {
  255. var registerurl = `/register/personalRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  256. } else {
  257. registerurl = `/register/enterpriseRegistration?appId=${this.appId}&returnUrl=${this.returnUrl}`
  258. }
  259. document.getElementById('register').href = registerurl
  260. },
  261. // 获取验证码
  262. getCode () {
  263. var imgSrc = document.getElementById('captchaImage')
  264. imgSrc.setAttribute('src', '/sso/login/checkCode?timestamp=' + (new Date()).valueOf())
  265. },
  266. // 登录
  267. isLogin (flag) {
  268. this.isShowLoading = true
  269. if (!this.checkUsername) {
  270. this.$message.error('请填写账号')
  271. } else if (!this.checkPassword) {
  272. this.$message.error('请填写密码')
  273. } else {
  274. let param = new FormData()
  275. param.append('username', this.login.username)
  276. param.append('password', this.login.password)
  277. param.append('captcha', this.login.captcha)
  278. param.append('appId', this.appId)
  279. param.append('returnUrl', this.returnUrl)
  280. param.append('baseUrl', this.baseUrl)
  281. param.append('spaceUU', this.login.spaceUU)
  282. let config = {
  283. headers: {'Content-Type': 'multipart/form-data'}
  284. }
  285. this.$http.post('/sso/login', param, config)
  286. .then(response => {
  287. if (response.data.success) {
  288. this.isShowLoading = false
  289. // console.log(response.data.content)
  290. if (response.data.content.spaces) {
  291. // 弹框让用户选择企业
  292. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  293. this.dialogVisible = flag
  294. } else if (response.data.content.loginUrls) {
  295. // 遍历登录url循环让各应用登录(需要跨域)
  296. for (var i in response.data.content.loginUrls) {
  297. this.$jsonp(`response.data.content.loginUrls${[i]}`, function (err, data) {
  298. if (err) throw err
  299. console.log(data)
  300. })
  301. }
  302. window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  303. }
  304. } else {
  305. this.$message.error(response.data)
  306. var count = response.data.errorCount
  307. if (count < 3) {
  308. this.showCheckCode = false
  309. this.isLoginDisabled = false
  310. } else if (count >= 5) {
  311. this.$message.error('密码错误次数已达上限,今日无法登陆')
  312. this.isLoginDisabled = true
  313. this.showCheckCode = false
  314. } else if (count >= 3 && count < 5) {
  315. this.getCode()
  316. if (count === 3) {
  317. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  318. }
  319. this.showCheckCode = true
  320. this.isLoginDisabled = false
  321. }
  322. return Promise.reject(response.data)
  323. }
  324. }).catch(err => {
  325. this.isShowLoading = false
  326. let _this = this
  327. setTimeout(function () {
  328. _this.getCode()
  329. }, 100)
  330. this.$message.error(err.errMsg)
  331. })
  332. }
  333. },
  334. chooseOneEnterprise (flag, spaceUU) {
  335. this.login.spaceUU = spaceUU
  336. this.isLogin(flag)
  337. }
  338. }
  339. }
  340. </script>
  341. <style lang="scss" scoped>
  342. @import '~assets/scss/mixins';
  343. @import '~assets/scss/variables';
  344. .x-navbar{
  345. height: 80px;
  346. line-height: 80px;
  347. margin: 0;
  348. .container{
  349. position: relative;
  350. width: 990px!important;
  351. a.navbar-brand{
  352. padding: 0 0 0 85px;
  353. height: inherit;
  354. line-height: inherit;
  355. font-family: "\5FAE\8F6F\96C5\9ED1";
  356. font-size: 24px;
  357. font-weight: 400;
  358. color: #888;
  359. background: url(/images/all/icon_brand.png) left center no-repeat;
  360. }
  361. .collapse{
  362. a{
  363. padding-left: 12px;
  364. margin-right: 10px;
  365. color: #666;
  366. outline: 0;
  367. border-left: 1px solid #ddd;
  368. &:first-child{
  369. border-width: 0;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. .x-container{
  376. position: relative;
  377. height: 475px;
  378. div.link-go {
  379. text-align: right;
  380. margin-top: 7px;
  381. a{
  382. color: #2d8cf0;
  383. background: 0 0;
  384. text-decoration: none;
  385. outline: 0;
  386. cursor: pointer;
  387. transition: color .2s ease;
  388. }
  389. a.first{
  390. float: left;
  391. margin-top: 3px;
  392. font-size: 12px;
  393. }
  394. }
  395. /*登录弹出框*/
  396. .x-floating {
  397. position: fixed;
  398. top: 80px;
  399. left: 50%;
  400. z-index: 100000;
  401. opacity: 1;
  402. -webkit-transition: all .5s;
  403. -moz-transition: all .5s;
  404. transition: all .5s;
  405. }
  406. .x-list {
  407. width: 306px;
  408. margin-left: -153px;
  409. background: #fff;
  410. border-top: 1px solid #e7e7e7;
  411. cursor: pointer;
  412. .x-list-header {
  413. padding: 10px 20px;
  414. background: #e0e0e0;
  415. width: 306px;
  416. height: 42px;
  417. line-height: 21px;
  418. font-size: 14px;
  419. font-weight: 700;
  420. color: #505050;
  421. }
  422. ul{
  423. margin-bottom: 0;
  424. li{
  425. padding: 10px 20px;
  426. width: 306px;
  427. height: 42px;
  428. line-height: 21px;
  429. font-size: 12px;
  430. color: #505050;
  431. border-bottom: 1px solid #e7e7e7;
  432. &:hover{
  433. background: #e7e7e7;
  434. }
  435. }
  436. }
  437. .x-list .x-list-header, .x-list li {
  438. padding: 10px 20px;
  439. border-bottom: 1px solid #e7e7e7;
  440. }
  441. }
  442. .x-floating.in {
  443. top: 80px;
  444. opacity: 1;
  445. }
  446. .x-banner-wrap {
  447. position: absolute;
  448. left: 0;
  449. top: 0;
  450. width: 100%;
  451. height: 475px;
  452. .x-banner {
  453. position: relative;
  454. overflow: auto;
  455. height: 475px;
  456. text-align: center;
  457. li{
  458. width: 100%;
  459. height: 475px;
  460. background: url(/images/all/banner.jpg) center center / auto 100% no-repeat rgb(202, 202, 214);
  461. }
  462. }
  463. }
  464. .x-login-wrap{
  465. position: absolute;
  466. top: 10px;
  467. right: 50%;
  468. margin-right: -495px;
  469. height: 475px;
  470. z-index: 5;
  471. .x-login {
  472. position: relative;
  473. top: 40px;
  474. width: 346px;
  475. background: #fff;
  476. overflow: visible;
  477. z-index: 4;
  478. .x-login-form, .x-login-qrcode {
  479. padding: 20px;
  480. .btn{
  481. background: #5078cb;
  482. color: #fff;
  483. font-weight: 700;
  484. letter-spacing: 4px;
  485. border-radius: 0;
  486. }
  487. .x-has-feedback-right {
  488. float: right;
  489. display: inline-block;
  490. a{
  491. color: #5078cb;
  492. }
  493. }
  494. .x-has-feedback-left {
  495. position: relative;
  496. .x-input {
  497. padding-left: 30px;
  498. line-height: 18px;
  499. color: #555;
  500. border-color: #ccc;
  501. border-radius: 0;
  502. box-shadow: none;
  503. }
  504. i.fa{
  505. position: absolute;
  506. top: 2px;
  507. left: 0;
  508. z-index: 2;
  509. display: block;
  510. width: 30px;
  511. height: 34px;
  512. line-height: 34px;
  513. text-align: center;
  514. pointer-events: none;
  515. color: #999;
  516. font-size: 18px;
  517. }
  518. }
  519. i.fa-keyboard-o{
  520. position: absolute;
  521. right: 10px;
  522. top: 10px;
  523. }
  524. i.fa-arrow-circle-o-right{
  525. margin-right: 5px;
  526. font-size: 14px;
  527. color: #5078cb;
  528. }
  529. .warn-text-area{
  530. margin-top: 5px;
  531. font-size: 13px;
  532. color: #000;
  533. }
  534. }
  535. .x-login-qrcode{
  536. display: none;
  537. }
  538. }
  539. }
  540. }
  541. </style>