Login.vue 20 KB

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