Login.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. if (response.data.content.currentUrl) {
  357. this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
  358. name: 'successCallback',
  359. timeout: 3000
  360. }, (err, data) => {
  361. if (err) {
  362. this.$message.error('登录超时,请重试')
  363. this.isShowLoading = false
  364. throw err
  365. } else {
  366. this.loginOther(response, a)
  367. }
  368. })
  369. } else {
  370. this.loginOther(response, a, 3000)
  371. }
  372. }
  373. } else {
  374. this.$message.error(response.data)
  375. var count = response.data.errorCount
  376. if (count < 3) {
  377. this.showCheckCode = false
  378. this.isLoginDisabled = false
  379. } else if (count >= 5) {
  380. this.$message.error('密码错误次数已达上限,今日无法登陆')
  381. this.isLoginDisabled = true
  382. this.showCheckCode = false
  383. } else if (count >= 3 && count < 5) {
  384. this.getCode()
  385. if (count === 3) {
  386. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  387. }
  388. this.showCheckCode = true
  389. this.isLoginDisabled = false
  390. }
  391. return Promise.reject(response.data)
  392. }
  393. }).catch(err => {
  394. this.isShowLoading = false
  395. let _this = this
  396. setTimeout(function () {
  397. _this.getCode()
  398. }, 100)
  399. this.$message.error(err.errMsg)
  400. })
  401. }
  402. },
  403. chooseOneEnterprise (flag, spaceUU) {
  404. this.login.spaceUU = spaceUU
  405. this.dialogVisible = false
  406. this.isLogin(flag)
  407. },
  408. getJsonp: function (url, timeout = 500) {
  409. return new Promise((resolve, reject) => {
  410. this.$jsonp(url, {
  411. name: 'successCallback',
  412. timeout: timeout
  413. }, function (err, data) {
  414. if (err) {
  415. reject(err)
  416. throw err
  417. } else {
  418. resolve(data)
  419. }
  420. })
  421. })
  422. },
  423. crossAfter (url) {
  424. try {
  425. window.location.href = url
  426. } catch (err) {
  427. console.log(err)
  428. }
  429. },
  430. loginOther (response, a, timeout) {
  431. const crossAfter = this.crossAfter
  432. let promises = []
  433. for (let i in response.data.content.loginUrls) {
  434. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
  435. }
  436. Promise.all(promises).then(() => {
  437. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  438. }).catch(() => {
  439. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  440. })
  441. },
  442. // 设置cookie
  443. setCookie (cName, cPwd, exdays) {
  444. let exdate = new Date()
  445. // let len = cPwd.substring(0)
  446. // cPwd = cPwd.replace(len, '***')
  447. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays)
  448. window.document.cookie = 'userName' + '=' + cName + ';path=/;expires=' + exdate.toGMTString()
  449. window.document.cookie = 'userPwd' + '=' + cPwd + ';path=/;expires=' + exdate.toGMTString()
  450. },
  451. // 读取cookies
  452. getCookie () {
  453. if (document.cookie.length > 0) {
  454. let arr = document.cookie.split(';')
  455. for (var i = 0; i < arr.length; i++) {
  456. let arr2 = arr[i].split('=')
  457. if (arr2[0].trim() === 'userName') {
  458. this.login.username = arr2[1]
  459. // console.log('get', this.login.username)
  460. }
  461. if (arr2[0].trim() === 'userPwd') {
  462. this.login.password = arr2[1]
  463. // console.log('get', this.login.password)
  464. }
  465. if (this.login.username && this.login.username) {
  466. this.checked = true
  467. }
  468. }
  469. }
  470. },
  471. // 清除cookie
  472. clearCookie () {
  473. this.setCookie('', '', -1)
  474. },
  475. }
  476. }
  477. </script>
  478. <style lang="scss" scoped type="text/scss">
  479. @import '~assets/scss/mixins';
  480. @import '~assets/scss/variables';
  481. .x-navbar{
  482. height: 80px;
  483. line-height: 80px;
  484. margin: 0;
  485. .container{
  486. position: relative;
  487. width: 990px!important;
  488. a.navbar-brand{
  489. padding: 0 0 0 85px;
  490. height: inherit;
  491. line-height: inherit;
  492. font-family: "\5FAE\8F6F\96C5\9ED1";
  493. font-size: 24px;
  494. font-weight: 400;
  495. color: #888;
  496. background: url(/images/all/icon_brand.png) left center no-repeat;
  497. }
  498. .collapse{
  499. a{
  500. padding-left: 12px;
  501. margin-right: 10px;
  502. color: #666;
  503. outline: 0;
  504. border-left: 1px solid #ddd;
  505. &:first-child{
  506. border-width: 0;
  507. }
  508. }
  509. }
  510. }
  511. }
  512. .x-container{
  513. position: relative;
  514. height: 475px;
  515. div.link-go {
  516. text-align: right;
  517. margin-top: 7px;
  518. a{
  519. color: #2d8cf0;
  520. background: 0 0;
  521. text-decoration: none;
  522. outline: 0;
  523. cursor: pointer;
  524. transition: color .2s ease;
  525. }
  526. a.first{
  527. float: left;
  528. margin-top: 3px;
  529. font-size: 12px;
  530. }
  531. }
  532. /*登录弹出框*/
  533. .x-floating {
  534. position: fixed;
  535. top: 80px;
  536. left: 50%;
  537. z-index: 100000;
  538. opacity: 1;
  539. -webkit-transition: all .5s;
  540. -moz-transition: all .5s;
  541. transition: all .5s;
  542. }
  543. .x-list {
  544. width: 60%;
  545. height:420px;
  546. margin-left: -30%;
  547. background: #fff;
  548. border-top: 1px solid #e7e7e7;
  549. cursor: pointer;
  550. .x-list-header {
  551. padding: 10px 20px;
  552. background: #e0e0e0;
  553. height: 42px;
  554. line-height: 21px;
  555. font-size: 14px;
  556. font-weight: 700;
  557. color: #505050;
  558. }
  559. .x-list-content{
  560. overflow-y: auto;
  561. height:375px;
  562. ul{
  563. margin-bottom: 0;
  564. li{
  565. display:inline-block;
  566. padding: 10px 20px;
  567. width: 33%;
  568. overflow: hidden;
  569. white-space: nowrap;
  570. text-overflow: ellipsis;
  571. height: 42px;
  572. line-height: 21px;
  573. font-size: 12px;
  574. color: #505050;
  575. border-bottom: 1px solid #e7e7e7;
  576. &:hover{
  577. background: #e7e7e7;
  578. }
  579. }
  580. }
  581. }
  582. .x-list .x-list-header, .x-list li {
  583. padding: 10px 20px;
  584. border-bottom: 1px solid #e7e7e7;
  585. }
  586. }
  587. .x-floating.in {
  588. top: 80px;
  589. opacity: 1;
  590. }
  591. .x-banner-wrap {
  592. position: absolute;
  593. left: 0;
  594. top: 0;
  595. width: 100%;
  596. height: 475px;
  597. .x-banner {
  598. position: relative;
  599. overflow: auto;
  600. height: 475px;
  601. text-align: center;
  602. li{
  603. width: 100%;
  604. height: 475px;
  605. background: url(/images/all/banner.jpg) center center / auto 100% no-repeat rgb(202, 202, 214);
  606. }
  607. }
  608. }
  609. .x-login-wrap{
  610. position: absolute;
  611. top: 10px;
  612. right: 50%;
  613. margin-right: -495px;
  614. height: 475px;
  615. z-index: 5;
  616. .x-login {
  617. position: relative;
  618. top: 40px;
  619. width: 346px;
  620. background: #fff;
  621. overflow: visible;
  622. z-index: 4;
  623. .x-login-form, .x-login-qrcode {
  624. padding: 20px;
  625. .btn{
  626. background: #5078cb;
  627. color: #fff;
  628. font-weight: 700;
  629. letter-spacing: 4px;
  630. border-radius: 0;
  631. }
  632. .x-has-feedback-right {
  633. float: right;
  634. display: inline-block;
  635. a{
  636. color: #5078cb;
  637. }
  638. }
  639. .x-has-feedback-left {
  640. position: relative;
  641. .x-input {
  642. padding-left: 30px;
  643. line-height: 18px;
  644. color: #555;
  645. border-color: #ccc;
  646. border-radius: 0;
  647. box-shadow: none;
  648. }
  649. i.fa{
  650. position: absolute;
  651. top: 2px;
  652. left: 0;
  653. z-index: 2;
  654. display: block;
  655. width: 30px;
  656. height: 34px;
  657. line-height: 34px;
  658. text-align: center;
  659. pointer-events: none;
  660. color: #999;
  661. font-size: 18px;
  662. }
  663. }
  664. i.fa-keyboard-o{
  665. position: absolute;
  666. right: 10px;
  667. top: 10px;
  668. }
  669. i.fa-arrow-circle-o-right{
  670. margin-right: 5px;
  671. font-size: 14px;
  672. color: #5078cb;
  673. }
  674. .warn-text-area{
  675. margin-top: 5px;
  676. font-size: 13px;
  677. color: #000;
  678. }
  679. .text-position {
  680. overflow: hidden;
  681. .page-part {
  682. float: left;
  683. margin-bottom: 0;
  684. .el-checkbox {
  685. margin: 0;
  686. span.el-checkbox__inner{
  687. width: 14px;
  688. height: 14px;
  689. }
  690. }
  691. }
  692. .forget {
  693. float: right;
  694. color: #2d8cf0;
  695. }
  696. }
  697. }
  698. .x-login-qrcode{
  699. display: none;
  700. }
  701. }
  702. }
  703. }
  704. </style>