Login.vue 19 KB

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