Login.vue 17 KB

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