index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <template>
  2. <div class="login-container">
  3. <div class="flexBox">
  4. <div>
  5. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on"
  6. label-position="left" @submit.native.prevent="handleLogin">
  7. <div class="flex">
  8. <div class="image-container">
  9. <div class="empty-height2 fiexlay">
  10. <img v-if="companyList[0] && companyList[0].logo" class="logo" :src="companyList[0].logo"
  11. alt />
  12. {{ companyList[0] && companyList[0].sysName ? companyList[0].sysName : '' }}
  13. </div>
  14. <el-carousel :interval="5000" arrow="always" height="440px" class="carousel">
  15. <el-carousel-item v-for="item in banner" :key="item.id">
  16. <el-image :z-index="1" :src="item.imgCarouselUrl" />
  17. </el-carousel-item>
  18. </el-carousel>
  19. </div>
  20. <div class="right-container">
  21. <div class="empty-height" />
  22. <div class="form-container">
  23. <div class="title">售修宝平台</div>
  24. <el-form-item prop="username">
  25. <span class="svg-container">
  26. <svg-icon icon-class="user" />
  27. </span>
  28. <el-input ref="username" v-model="loginForm.username" placeholder="请输入用户名" name="username" type="text"
  29. tabindex="1" auto-complete="on" />
  30. </el-form-item>
  31. <el-form-item prop="password">
  32. <span class="svg-container">
  33. <svg-icon icon-class="password" />
  34. </span>
  35. <el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType"
  36. placeholder="请输入密码" name="password" tabindex="2" auto-complete="off"
  37. />
  38. <span class="show-pwd" @click="showPwd">
  39. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  40. </span>
  41. </el-form-item>
  42. <el-form-item prop="codeValue">
  43. <span class="svg-container">
  44. <svg-icon icon-class="password" />
  45. </span>
  46. <el-input ref="codeValue" v-model="loginForm.codeValue" placeholder="请输入验证码" name="codeValue"
  47. type="text" tabindex="3" auto-complete="off" />
  48. <div class="code" @click="getCode"><img :src="'data:image/jpeg;base64,' + codeImage" alt="" /></div>
  49. </el-form-item>
  50. <el-checkbox v-model="isRemenberPw">记住密码</el-checkbox>
  51. <div class="button-container">
  52. <el-button :loading="loading" type="primary" @click.native.prevent="handleLogin">登录</el-button>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </el-form>
  58. </div>
  59. <div v-if="companyList && companyList.length" class="info">
  60. <div class="info-item">
  61. <el-link :href="companyList[0].icpRecordLink" :underline="false" target="_blank">{{
  62. companyList[0].icpRecord
  63. }}</el-link>
  64. <div v-if="companyList[0].companyName && companyList[0].icpRecordLink" style="margin: 0 20px">|</div>
  65. <el-link :href="companyList[0].pubSecurityRecordLink" :underline="false" target="_blank">
  66. <el-image style="width: 14px; height: 16px" :src="require('@/assets/login/icon_0001.png')" />
  67. {{ companyList[0].pubSecurityRecord }}
  68. </el-link>
  69. </div>
  70. <div class="info-item">
  71. <el-link href="https://www.zfire.top/#/" :underline="false" target="_blank">
  72. {{ companyList[0] && companyList[0].companyName ? companyList[0].companyName : '' }}
  73. </el-link>
  74. </div>
  75. <div class="link_gs">
  76. <span v-if="dictList.length > 0" :underline="false" target="_blank">友链:</span>
  77. <el-link style="margin-left: 10px" v-for="(v, i) in dictList" :key="i" :href="v.amityUrl" :underline="false"
  78. target="_blank">
  79. <el-image style="width: 14px; height: 16px" :src=" v.amityUrlLogo"></el-image>
  80. {{ v.amityUrlName }}</el-link>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { validUsername } from '@/utils/validate'
  88. import Cookies from 'js-cookie'
  89. import { getCode, getList, getCompanyList, recordAmityList2 } from '@/api/user'
  90. export default {
  91. name: 'Login',
  92. data() {
  93. const validateUsername = (rule, value, callback) => {
  94. if (value.length <= 0) {
  95. callback(new Error('请输入用户名'))
  96. } else {
  97. callback()
  98. }
  99. }
  100. const validatePassword = (rule, value, callback) => {
  101. if (value.length <= 0) {
  102. callback(new Error('请输入密码'))
  103. } else {
  104. callback()
  105. }
  106. }
  107. const validateCode = (rule, value, callback) => {
  108. if (value.length <= 0) {
  109. callback(new Error('请输入验证码'))
  110. } else {
  111. callback()
  112. }
  113. }
  114. return {
  115. loginForm: {
  116. username: '',
  117. password: '',
  118. code: '',
  119. codeValue: ''
  120. },
  121. loginRules: {
  122. username: [{ required: true, trigger: 'change', validator: validateUsername }],
  123. password: [{ required: true, trigger: 'change', validator: validatePassword }],
  124. codeValue: [{ required: true, trigger: 'change', validator: validateCode }]
  125. },
  126. loading: false,
  127. passwordType: 'password',
  128. redirect: undefined,
  129. isRemenberPw: false,
  130. codeImage: '',
  131. banner: [],
  132. companyList: [],
  133. dictList: []
  134. }
  135. },
  136. watch: {
  137. $route: {
  138. handler: function (route) {
  139. this.redirect = route.query && route.query.redirect
  140. },
  141. immediate: true
  142. }
  143. },
  144. created() {
  145. // 获取缓存信息
  146. if (localStorage.getItem('greemall_login')) {
  147. let storageData = JSON.parse(localStorage.getItem('greemall_login'))
  148. this.loginForm.username = storageData.username
  149. this.isRemenberPw = storageData.isRemenberPw
  150. }
  151. if (this.isRemenberPw) {
  152. this.getCookie()
  153. }
  154. this.getCode()
  155. this.getList()
  156. this.getCompanyList()
  157. this.getDictAmityPage()
  158. },
  159. methods: {
  160. // 获取轮播图
  161. getList() {
  162. getList().then(res => {
  163. this.banner = res.data
  164. })
  165. },
  166. //获取友情链接列表
  167. getDictAmityPage() {
  168. recordAmityList2().then(res => {
  169. this.dictList = res.data
  170. })
  171. },
  172. // 获取备案信息
  173. getCompanyList() {
  174. getCompanyList().then(res => {
  175. this.companyList = res.data
  176. })
  177. },
  178. // 获取验证码
  179. getCode() {
  180. getCode().then(res => {
  181. this.loginForm.code = res.data.code
  182. this.codeImage = res.data.pic
  183. })
  184. },
  185. // 显示隐藏密码
  186. showPwd() {
  187. if (this.passwordType === 'password') {
  188. this.passwordType = ''
  189. } else {
  190. this.passwordType = 'password'
  191. }
  192. this.$nextTick(() => {
  193. this.$refs.password.focus()
  194. })
  195. },
  196. // 登录
  197. handleLogin() {
  198. this.$refs.loginForm.validate(valid => {
  199. if (valid) {
  200. this.loading = true
  201. this.$store
  202. .dispatch('user/login', this.loginForm)
  203. .then(() => {
  204. this.$router.push({ path: this.redirect || '/' })
  205. this.saveUnAndPw()
  206. this.loading = false
  207. })
  208. .catch(() => {
  209. this.getCode()
  210. this.loginForm.codeValue = ''
  211. this.loading = false
  212. })
  213. } else {
  214. console.log('error submit!!')
  215. return false
  216. }
  217. })
  218. },
  219. // 处理账号密码的储存
  220. saveUnAndPw() {
  221. let storageData = {
  222. username: this.loginForm.username,
  223. isRemenberPw: this.isRemenberPw
  224. }
  225. localStorage.setItem('greemall_login', JSON.stringify(storageData))
  226. if (this.isRemenberPw) {
  227. this.setCookie(this.loginForm.username, this.loginForm.password, 7)
  228. }
  229. },
  230. //设置cookie
  231. setCookie(c_name, c_pwd, exdays) {
  232. var exdate = new Date() //获取时间
  233. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays) //保存的天数
  234. //字符串拼接cookie
  235. window.document.cookie = 'greemall_username' + '=' + c_name + ';path=/;expires=' + exdate.toGMTString()
  236. window.document.cookie = 'greemall_password' + '=' + c_pwd + ';path=/;expires=' + exdate.toGMTString()
  237. },
  238. //读取cookie
  239. getCookie: function () {
  240. if (document.cookie.length > 0) {
  241. var arr = document.cookie.split('; ') //这里显示的格式需要切割一下自己可输出看下
  242. for (var i = 0; i < arr.length; i++) {
  243. var arr2 = arr[i].split('=') //再次切割
  244. //判断查找相对应的值
  245. if (arr2[0] == 'greemall_username') {
  246. this.loginForm.username = arr2[1] //保存到保存数据的地方
  247. } else if (arr2[0] == 'greemall_password') {
  248. this.loginForm.password = arr2[1]
  249. }
  250. }
  251. }
  252. },
  253. //清除cookie
  254. clearCookie: function () {
  255. this.setCookie('', '', -1) //修改2值都为空,天数为负1天就好了
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. /* 修复input 背景不协调 和光标变色 */
  262. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  263. $bg: #283443;
  264. $light_gray: #fff;
  265. $cursor: #fff;
  266. $back: #333;
  267. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  268. .login-container .el-input input {
  269. color: $cursor;
  270. }
  271. }
  272. .info-item .el-link--inner {
  273. color: #ffffff;
  274. }
  275. /* reset element-ui css */
  276. .login-container {
  277. background: url('~@/assets/login/background.png') center center;
  278. background-size: cover;
  279. height: 100vh;
  280. .el-input {
  281. display: inline-block;
  282. height: 47px;
  283. width: 85%;
  284. input {
  285. background: transparent;
  286. border: 0px;
  287. -webkit-appearance: none;
  288. border-radius: 0px;
  289. padding: 12px 5px 12px 15px;
  290. color: $back;
  291. height: 47px;
  292. caret-color: $back;
  293. border-bottom: none !important;
  294. &:-webkit-autofill {
  295. box-shadow: 0 0 0px 1000px $cursor inset !important;
  296. -webkit-text-fill-color: $back !important;
  297. }
  298. }
  299. }
  300. .el-carousel__arrow--left,
  301. .el-carousel__arrow--right {
  302. display: none;
  303. }
  304. .carousel {
  305. border-top-left-radius: 15px;
  306. border-bottom-left-radius: 15px;
  307. overflow: hidden;
  308. }
  309. .el-form-item {
  310. border: 1px solid rgba(255, 255, 255, 0.1);
  311. border-radius: 5px;
  312. color: #454545;
  313. margin-bottom: 25px !important;
  314. }
  315. .el-checkbox__input {
  316. display: none;
  317. }
  318. .el-form-item__error {
  319. left: 30px;
  320. }
  321. .el-form-item__content {
  322. display: flex;
  323. align-items: center;
  324. line-height: 0;
  325. }
  326. .show-pwd {
  327. line-height: 40px;
  328. }
  329. .el-checkbox__input.is-checked+.el-checkbox__label {
  330. color: #4684f4db;
  331. }
  332. .checkbox {
  333. position: relative;
  334. display: flex;
  335. align-items: center;
  336. margin-left: 1px;
  337. .check-yes {
  338. position: relative;
  339. line-height: 0;
  340. }
  341. .yes {
  342. position: absolute;
  343. left: 50%;
  344. top: 50%;
  345. transform: translate(-50%, -50%);
  346. }
  347. .el-checkbox {
  348. margin: 0 !important;
  349. }
  350. }
  351. /* 可以设置不同的进入和离开动画 */
  352. /* 设置持续时间和动画函数 */
  353. .slide-fade-enter-active {
  354. transition: all 0.3s ease;
  355. }
  356. .slide-fade-leave-active {
  357. transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
  358. }
  359. .slide-fade-leave-active {
  360. transform: translateX(10px);
  361. opacity: 0;
  362. }
  363. .wei {
  364. display: flex;
  365. flex-direction: column;
  366. justify-content: center;
  367. align-items: center;
  368. margin-top: 30px;
  369. text-align: center;
  370. text-align-last: center;
  371. &-item-tip {
  372. height: 19px;
  373. font-size: 20px;
  374. margin-top: 17px;
  375. }
  376. &-item-text {
  377. height: 12px;
  378. font-size: 14px;
  379. margin-top: 17px;
  380. color: #999;
  381. }
  382. }
  383. }
  384. </style>
  385. <style lang="scss" scoped>
  386. $bg: #2d3a4b;
  387. $dark_gray: #889aa4;
  388. $light_gray: #eee;
  389. .flex {
  390. display: flex;
  391. align-items: center;
  392. }
  393. .info {
  394. display: flex;
  395. align-items: center;
  396. flex-direction: column;
  397. justify-content: center;
  398. width: 1080px;
  399. margin-top: 50px;
  400. line-height: 30px;
  401. text-align: center;
  402. text-align-last: center;
  403. color: #fff;
  404. z-index: 999;
  405. }
  406. .link_gs {
  407. font-size: 14px;
  408. }
  409. ::v-deep .link_gs .el-link--inner {
  410. color: #fff;
  411. font-weight: initial;
  412. }
  413. .info-item {
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. }
  418. .title-item {
  419. display: flex;
  420. flex-direction: column;
  421. justify-content: center;
  422. align-items: center;
  423. margin: 0 30px;
  424. cursor: pointer;
  425. font-size: 22px;
  426. color: #666666;
  427. line-height: 40px;
  428. border-bottom: 3px solid #ffffff;
  429. }
  430. .acitve {
  431. font-weight: bold;
  432. color: #4684f4;
  433. border-bottom: 3px solid #4684f4;
  434. }
  435. .flexBox {
  436. display: flex;
  437. padding-top: calc(50vh - 230px);
  438. justify-content: space-between;
  439. flex-direction: column;
  440. align-items: center;
  441. }
  442. .input-box {
  443. position: relative;
  444. width: 360px;
  445. height: 50px;
  446. margin-bottom: 25px;
  447. background: #ffffff;
  448. border: 1px solid #e6e6e6 !important;
  449. border-radius: 4px;
  450. }
  451. .input-box:last-child {
  452. margin-bottom: 10px;
  453. }
  454. .flex {
  455. display: flex;
  456. flex-direction: row;
  457. }
  458. .empty-height {
  459. font-size: 30px;
  460. font-weight: bolder;
  461. height: 46px;
  462. margin: 15px 0;
  463. color: #fff;
  464. }
  465. .empty-height2 {
  466. font-size: 30px;
  467. font-weight: bolder;
  468. height: 42px;
  469. margin: 15px 0;
  470. color: #fff;
  471. }
  472. .fiexlay {
  473. width: auto;
  474. height: 46px;
  475. display: flex;
  476. align-items: center;
  477. }
  478. .logo {
  479. height: 42px;
  480. margin-right: 5px;
  481. }
  482. .el-carousel__item:nth-child(2n) {
  483. background-color: #99a9bf;
  484. }
  485. .el-carousel__item:nth-child(2n + 1) {
  486. background-color: #d3dce6;
  487. }
  488. .login-container {
  489. min-height: 100%;
  490. width: 100%;
  491. height: 100vh;
  492. background-color: $bg;
  493. overflow: hidden;
  494. .login-form {
  495. position: relative;
  496. width: 1920px;
  497. max-width: 100%;
  498. height: 100%;
  499. display: flex;
  500. flex-direction: column;
  501. align-items: center;
  502. }
  503. .image-container {
  504. width: 700px;
  505. height: 516px;
  506. // overflow: hidden;
  507. }
  508. .right-container {
  509. width: 440px;
  510. height: 516px;
  511. .form-container {
  512. height: 440px;
  513. padding: 20px 30px 27px 40px;
  514. background: #fff;
  515. border-radius: 0 15px 15px 0;
  516. .title {
  517. justify-content: center;
  518. letter-spacing: 4px;
  519. text-align: center;
  520. margin-bottom: 35px;
  521. }
  522. }
  523. }
  524. .tips {
  525. font-size: 14px;
  526. color: #fff;
  527. margin-bottom: 10px;
  528. span {
  529. &:first-of-type {
  530. margin-right: 16px;
  531. }
  532. }
  533. }
  534. .svg-container {
  535. margin: 0 0 0 14px;
  536. // padding: 6px 5px 6px 5px;
  537. color: #33aef7;
  538. vertical-align: middle;
  539. width: 30px;
  540. display: inline-block;
  541. }
  542. .title-container {
  543. border-radius: 15px 15px 0 0;
  544. overflow: hidden;
  545. img {
  546. width: 100%;
  547. display: block;
  548. }
  549. }
  550. .show-pwd {
  551. position: absolute;
  552. right: 30px;
  553. top: 7px;
  554. font-size: 16px;
  555. color: $dark_gray;
  556. cursor: pointer;
  557. user-select: none;
  558. }
  559. .code {
  560. position: absolute;
  561. right: 30px;
  562. top: 7px;
  563. z-index: 99;
  564. cursor: pointer;
  565. img {
  566. height: 30px;
  567. }
  568. }
  569. .code2 {
  570. position: absolute;
  571. right: 0;
  572. top: -1px;
  573. .el-button {
  574. height: 50px;
  575. }
  576. }
  577. .button-container {
  578. text-align: center;
  579. margin-top: 20px;
  580. button {
  581. font-size: 16px;
  582. width: 100%;
  583. height: 45px;
  584. border-radius: 4px;
  585. background: #4684f4;
  586. box-shadow: 2px 3px 8px 0px #4684f46b;
  587. }
  588. }
  589. }
  590. .float_right {
  591. position: absolute;
  592. right: 0;
  593. font-size: 14px;
  594. cursor: pointer;
  595. }
  596. ::v-deep .el-form-item__error {
  597. color: #f56c6c;
  598. font-size: 12px;
  599. line-height: 1;
  600. padding-top: 6px;
  601. position: absolute;
  602. top: 100%;
  603. left: 0;
  604. }
  605. .el-link.el-link--default:hover {
  606. color: #4684f4;
  607. }
  608. @media only screen and (max-width: 600px) {
  609. .image-container {
  610. display: none;
  611. }
  612. .form-container {
  613. border-radius: 15px !important;
  614. }
  615. }
  616. </style>