Login.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. const crossAfter = this.crossAfter
  333. let promises = []
  334. for (let i in response.data.content.loginUrls) {
  335. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
  336. }
  337. Promise.all(promises).then(() => {
  338. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  339. }).catch(() => {
  340. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
  341. })
  342. this.isShowLoading = true
  343. // setTimeout(function () {
  344. // window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
  345. // }, 3000)
  346. }
  347. } else {
  348. this.$message.error(response.data)
  349. var count = response.data.errorCount
  350. if (count < 3) {
  351. this.showCheckCode = false
  352. this.isLoginDisabled = false
  353. } else if (count >= 5) {
  354. this.$message.error('密码错误次数已达上限,今日无法登陆')
  355. this.isLoginDisabled = true
  356. this.showCheckCode = false
  357. } else if (count >= 3 && count < 5) {
  358. this.getCode()
  359. if (count === 3) {
  360. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  361. }
  362. this.showCheckCode = true
  363. this.isLoginDisabled = false
  364. }
  365. return Promise.reject(response.data)
  366. }
  367. }).catch(err => {
  368. this.isShowLoading = false
  369. let _this = this
  370. setTimeout(function () {
  371. _this.getCode()
  372. }, 100)
  373. this.$message.error(err.errMsg)
  374. })
  375. }
  376. },
  377. chooseOneEnterprise (flag, spaceUU) {
  378. this.login.spaceUU = spaceUU
  379. this.dialogVisible = false
  380. this.isLogin(flag)
  381. },
  382. getJsonp: function (url) {
  383. return new Promise((resolve, reject) => {
  384. this.$jsonp(url, {
  385. name: 'successCallback',
  386. timeout: 800
  387. }, function (err, data) {
  388. if (err) {
  389. reject(err)
  390. throw err
  391. } else {
  392. resolve(data)
  393. }
  394. })
  395. })
  396. },
  397. crossAfter (url) {
  398. try {
  399. window.location.href = url
  400. } catch (err) {
  401. console.log(err)
  402. }
  403. }
  404. }
  405. }
  406. </script>
  407. <style lang="scss" scoped type="text/scss">
  408. @import '~assets/scss/mixins';
  409. @import '~assets/scss/variables';
  410. .x-navbar{
  411. height: 80px;
  412. line-height: 80px;
  413. margin: 0;
  414. .container{
  415. position: relative;
  416. width: 990px!important;
  417. a.navbar-brand{
  418. padding: 0 0 0 85px;
  419. height: inherit;
  420. line-height: inherit;
  421. font-family: "\5FAE\8F6F\96C5\9ED1";
  422. font-size: 24px;
  423. font-weight: 400;
  424. color: #888;
  425. background: url(/images/all/icon_brand.png) left center no-repeat;
  426. }
  427. .collapse{
  428. a{
  429. padding-left: 12px;
  430. margin-right: 10px;
  431. color: #666;
  432. outline: 0;
  433. border-left: 1px solid #ddd;
  434. &:first-child{
  435. border-width: 0;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. .x-container{
  442. position: relative;
  443. height: 475px;
  444. div.link-go {
  445. text-align: right;
  446. margin-top: 7px;
  447. a{
  448. color: #2d8cf0;
  449. background: 0 0;
  450. text-decoration: none;
  451. outline: 0;
  452. cursor: pointer;
  453. transition: color .2s ease;
  454. }
  455. a.first{
  456. float: left;
  457. margin-top: 3px;
  458. font-size: 12px;
  459. }
  460. }
  461. /*登录弹出框*/
  462. .x-floating {
  463. position: fixed;
  464. top: 80px;
  465. left: 50%;
  466. z-index: 100000;
  467. opacity: 1;
  468. -webkit-transition: all .5s;
  469. -moz-transition: all .5s;
  470. transition: all .5s;
  471. }
  472. .x-list {
  473. width: 60%;
  474. height:420px;
  475. margin-left: -30%;
  476. background: #fff;
  477. border-top: 1px solid #e7e7e7;
  478. cursor: pointer;
  479. .x-list-header {
  480. padding: 10px 20px;
  481. background: #e0e0e0;
  482. height: 42px;
  483. line-height: 21px;
  484. font-size: 14px;
  485. font-weight: 700;
  486. color: #505050;
  487. }
  488. .x-list-content{
  489. overflow-y: auto;
  490. height:375px;
  491. ul{
  492. margin-bottom: 0;
  493. li{
  494. display:inline-block;
  495. padding: 10px 20px;
  496. width: 33%;
  497. overflow: hidden;
  498. white-space: nowrap;
  499. text-overflow: ellipsis;
  500. height: 42px;
  501. line-height: 21px;
  502. font-size: 12px;
  503. color: #505050;
  504. border-bottom: 1px solid #e7e7e7;
  505. &:hover{
  506. background: #e7e7e7;
  507. }
  508. }
  509. }
  510. }
  511. .x-list .x-list-header, .x-list li {
  512. padding: 10px 20px;
  513. border-bottom: 1px solid #e7e7e7;
  514. }
  515. }
  516. .x-floating.in {
  517. top: 80px;
  518. opacity: 1;
  519. }
  520. .x-banner-wrap {
  521. position: absolute;
  522. left: 0;
  523. top: 0;
  524. width: 100%;
  525. height: 475px;
  526. .x-banner {
  527. position: relative;
  528. overflow: auto;
  529. height: 475px;
  530. text-align: center;
  531. li{
  532. width: 100%;
  533. height: 475px;
  534. background: url(/images/all/banner.jpg) center center / auto 100% no-repeat rgb(202, 202, 214);
  535. }
  536. }
  537. }
  538. .x-login-wrap{
  539. position: absolute;
  540. top: 10px;
  541. right: 50%;
  542. margin-right: -495px;
  543. height: 475px;
  544. z-index: 5;
  545. .x-login {
  546. position: relative;
  547. top: 40px;
  548. width: 346px;
  549. background: #fff;
  550. overflow: visible;
  551. z-index: 4;
  552. .x-login-form, .x-login-qrcode {
  553. padding: 20px;
  554. .btn{
  555. background: #5078cb;
  556. color: #fff;
  557. font-weight: 700;
  558. letter-spacing: 4px;
  559. border-radius: 0;
  560. }
  561. .x-has-feedback-right {
  562. float: right;
  563. display: inline-block;
  564. a{
  565. color: #5078cb;
  566. }
  567. }
  568. .x-has-feedback-left {
  569. position: relative;
  570. .x-input {
  571. padding-left: 30px;
  572. line-height: 18px;
  573. color: #555;
  574. border-color: #ccc;
  575. border-radius: 0;
  576. box-shadow: none;
  577. }
  578. i.fa{
  579. position: absolute;
  580. top: 2px;
  581. left: 0;
  582. z-index: 2;
  583. display: block;
  584. width: 30px;
  585. height: 34px;
  586. line-height: 34px;
  587. text-align: center;
  588. pointer-events: none;
  589. color: #999;
  590. font-size: 18px;
  591. }
  592. }
  593. i.fa-keyboard-o{
  594. position: absolute;
  595. right: 10px;
  596. top: 10px;
  597. }
  598. i.fa-arrow-circle-o-right{
  599. margin-right: 5px;
  600. font-size: 14px;
  601. color: #5078cb;
  602. }
  603. .warn-text-area{
  604. margin-top: 5px;
  605. font-size: 13px;
  606. color: #000;
  607. }
  608. }
  609. .x-login-qrcode{
  610. display: none;
  611. }
  612. }
  613. }
  614. }
  615. </style>