Login.vue 23 KB

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