index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div class="login-container">
  3. <div class="bg" v-if="erp"><img :src="bg" alt=""></div>
  4. <div class="logo" v-if="erp">
  5. <img :src="logo" alt="">
  6. <span class="logo_txt">东信综合安防管理系统</span>
  7. </div>
  8. <el-form class="login-form" auto-complete="on" ref="loginForm" :model="loginForm" :rules="loginRules" v-if="erp">
  9. <h3 class="title">用户登录 <span>LOGIN</span></h3>
  10. <el-form-item prop="username" width="460px">
  11. <el-input v-model="loginForm.username"
  12. ref="username"
  13. placeholder="请输入用户名"
  14. name="username"
  15. @keyup.enter.native="login_info()"
  16. type="text" auto-complete="off" >
  17. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item prop="password">
  21. <el-input
  22. class="inputs"
  23. ref="password"
  24. placeholder="请输入密码"
  25. name="password"
  26. @keyup.enter.native="login_info()"
  27. :type="passwordtxt"
  28. v-model="loginForm.password" >
  29. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  30. <svg-icon slot="prefix" icon-class="eye" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" v-show="passwordtxt =='password'" />
  31. <svg-icon slot="prefix" icon-class="eye-open" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" v-show="passwordtxt =='text'" />
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item prop="code">
  35. <el-input
  36. v-model="loginForm.code"
  37. auto-complete="off"
  38. placeholder="验证码"
  39. style="width: 63%"
  40. >
  41. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  42. </el-input>
  43. <div class="login-code">
  44. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  45. </div>
  46. </el-form-item>
  47. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  48. <el-button
  49. type="primary"
  50. @click.native.prevent="login_info()"
  51. @keyup.enter = "login_info()"
  52. >
  53. <span v-if="!loading" >登 录</span>
  54. <span v-else>登 录 中...</span></el-button
  55. >
  56. </el-form>
  57. <div id="loader-wrapper" v-if="ERPloading">
  58. <div id="loader"></div>
  59. <div class="loader-section section-left"></div>
  60. <div class="loader-section section-right"></div>
  61. <div class="load_title">正在加载系统资源,请耐心等待</div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. // import { validUsername } from "@/utils/validate";
  67. import { getCodeImg } from '@/api/user'
  68. import TimeMenu from "@/components/TimeMenu";
  69. import navHeader from "../index/components/navHeader";
  70. import $ from 'jquery'
  71. // import {Menu_List} from "../../router/index";
  72. import bgImg from "../../assets/bg-login.png";
  73. import logoImg from "../../assets/logo-b.png";
  74. import Cookies from "js-cookie";
  75. import { encrypt, decrypt } from '../../utils/jsencrypt';
  76. export default {
  77. name: 'Login',
  78. components: {
  79. TimeMenu,
  80. navHeader,
  81. },
  82. data() {
  83. return {
  84. erp:false,
  85. ERPloading:true,
  86. loading:false,
  87. passwordtxt:"password",
  88. bg:bgImg,
  89. logo:logoImg,
  90. codeUrl: "",
  91. cookiePassword: "",
  92. show_num:[],
  93. // 验证码开关
  94. // captchaOnOff: true,
  95. loginForm: {
  96. username: "",
  97. password: "",
  98. rememberMe: true,
  99. code: "",
  100. uuid: ""
  101. },
  102. loginRules: {
  103. username: [
  104. { required: true, trigger: "blur", message: "请输入您的账号" }
  105. ],
  106. password: [
  107. { required: true, trigger: "blur", message: "请输入您的密码" }
  108. ],
  109. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  110. },
  111. };
  112. },
  113. mounted(){
  114. $('.el-menu').css("display","none");
  115. $('.right-menu').css("display","none");
  116. },
  117. created() {
  118. this.keyupEnter()
  119. this.getUrl()
  120. },
  121. methods: {
  122. getUrl(){
  123. let url = this.$route.query
  124. if(url.id && url.name){
  125. let data = {id:url.id,name:url.name}
  126. this.handleLoginERP(data)
  127. }else{
  128. this.erp = true
  129. this.ERPloading = false
  130. this.getCode();
  131. this.getCookie();
  132. this.zddl();//自动登录
  133. }
  134. },
  135. keyupEnter(){
  136. let _this = this
  137. document.onkeydown = function(e){
  138. var key = window.event.keyCode;
  139. if(key == 13){
  140. _this.login_info()
  141. }
  142. }
  143. },
  144. eyeTab(){//密码显示开关
  145. if(this.passwordtxt == "password"){
  146. this.passwordtxt = "text"
  147. }else{
  148. this.passwordtxt = "password"
  149. }
  150. },
  151. getCode() {//获取验证码
  152. getCodeImg().then(res => {
  153. this.codeUrl = "data:image/gif;base64," + res.data.img;
  154. this.loginForm.uuid = res.data.uuid;
  155. });
  156. },
  157. getCookie() {//缓存数据
  158. const username = Cookies.get("username");
  159. const password = Cookies.get("password");
  160. const rememberMe = Cookies.get('rememberMe')
  161. this.loginForm = {
  162. username: username === undefined ? this.loginForm.username : username,
  163. password: password === undefined ? this.loginForm.password : decrypt(password),
  164. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  165. };
  166. },
  167. login_info() {//登录
  168. this.$refs.loginForm.validate(valid => {
  169. if (valid) {
  170. this.loading = true;
  171. if (this.loginForm.rememberMe) {
  172. Cookies.set("username429", this.loginForm.username, { expires: 300 });
  173. Cookies.set("password429", encrypt(this.loginForm.password), { expires: 300 });
  174. Cookies.set('rememberMe429', this.loginForm.rememberMe, { expires: 300 });
  175. } else {
  176. Cookies.remove("username429");
  177. Cookies.remove("password429");
  178. Cookies.remove('rememberMe429');
  179. }
  180. this.$store.dispatch('login', this.loginForm).then(() => {
  181. this.$router.push('/index?name='+this.loginForm.username)
  182. window.localStorage.setItem('key',this.loginForm.username)
  183. this.loading=false
  184. }).catch(err => {
  185. this.loading=false
  186. this.getCode()
  187. this.$message.error(err); //登录失败提示错误
  188. });
  189. }
  190. });
  191. },
  192. handleLoginERP(data) {//erp登录
  193. Cookies.set("username429", data.name);
  194. this.$store.dispatch("LoginERP", data).then((res) => {
  195. this.$router.push({ path: "/index"}).catch(()=>{});
  196. }).catch((err) => {
  197. location.href = '/#/';
  198. });
  199. },
  200. zddl(){//自动登录
  201. if(Cookies.get("vue_admin_template_token1708") && localStorage.getItem("key")){
  202. this.$router.push('/index?name=' + localStorage.getItem("key"))
  203. }
  204. }
  205. },
  206. watch:{
  207. password:function(){
  208. this.password=this.password.replace(/[\W]/g,'');
  209. },
  210. username:function(){
  211. this.username=this.username.replace(/[\W]/g,'');
  212. },
  213. code:function(){
  214. this.code=this.code.replace(/[\W]/g,'');
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. .code-verify {
  221. top: 3px;
  222. position: absolute;
  223. right: -108px;
  224. width: 82px;
  225. }
  226. .bg{
  227. width:100%;
  228. height:100%;
  229. overflow: hidden;
  230. position: fixed;
  231. top:0;
  232. left:0;
  233. z-index: -1;
  234. .bgimg{
  235. width:100%;
  236. height:100%;
  237. position: absolute;
  238. top:0;
  239. left:0;
  240. z-index: -1;
  241. }
  242. }
  243. .logo{
  244. width:100%;
  245. position: fixed;
  246. top:0;
  247. img{
  248. width:152px;
  249. margin:10px 20px 0 20px;
  250. vertical-align: middle;
  251. }
  252. .logo_txt{
  253. font-size: 20px;
  254. color:#fff;
  255. vertical-align: middle;
  256. letter-spacing: 4px;
  257. }
  258. }
  259. .login-form {
  260. border-radius: 6px;
  261. background: #ffffff;
  262. width: 456px;
  263. padding: 63px 35px;
  264. position: absolute;
  265. top:25%;
  266. left:50%;
  267. margin-left:-228px;
  268. .title {
  269. margin: 0px auto 30px auto;
  270. text-align: left;
  271. color: #000000;
  272. font-size: 20px;
  273. span{
  274. margin-left:10px;
  275. opacity: 0.25;
  276. }
  277. }
  278. .el-input {
  279. height: 40px;
  280. input {
  281. height:100%;
  282. padding:10px 0;
  283. display: inline-block;
  284. }
  285. }
  286. .input-icon {
  287. height: 39px;
  288. width: 14px;
  289. margin-left: 2px;
  290. }
  291. }
  292. .el-form-item__content{
  293. height:40px;
  294. }
  295. .login-tip {
  296. font-size: 13px;
  297. text-align: center;
  298. color: #bfbfbf;
  299. }
  300. .login-code {
  301. width: 33%;
  302. height: 38px;
  303. float: right;
  304. margin-top:-2px;
  305. text-align: right;
  306. img {
  307. cursor: pointer;
  308. vertical-align: middle;
  309. }
  310. }
  311. .el-login-footer {
  312. height: 40px;
  313. line-height: 40px;
  314. position: fixed;
  315. bottom: 0;
  316. width: 100%;
  317. text-align: center;
  318. color: #fff;
  319. font-family: Arial;
  320. font-size: 12px;
  321. letter-spacing: 1px;
  322. }
  323. .login-code-img {
  324. height: 38px;
  325. }
  326. .el-button--primary{
  327. width:100%;
  328. margin-top:10px;
  329. color: #fff;
  330. background-color: #1890ff;
  331. border-color: #1890ff;
  332. border-radius: 4px;
  333. }
  334. body,html{
  335. width:100%;
  336. height:100%;
  337. background: #7171C6;
  338. }
  339. #loader-wrapper {
  340. position: fixed;
  341. top: 0;
  342. left: 0;
  343. width: 100%;
  344. height: 100%;
  345. z-index: 999999;
  346. }
  347. #loader {
  348. display: block;
  349. position: relative;
  350. left: 50%;
  351. top: 50%;
  352. width: 150px;
  353. height: 150px;
  354. margin: -75px 0 0 -75px;
  355. border-radius: 50%;
  356. border: 3px solid transparent;
  357. border-top-color: #FFF;
  358. -webkit-animation: spin 2s linear infinite;
  359. -ms-animation: spin 2s linear infinite;
  360. -moz-animation: spin 2s linear infinite;
  361. -o-animation: spin 2s linear infinite;
  362. animation: spin 2s linear infinite;
  363. z-index: 1001;
  364. }
  365. #loader:before {
  366. content: "";
  367. position: absolute;
  368. top: 5px;
  369. left: 5px;
  370. right: 5px;
  371. bottom: 5px;
  372. border-radius: 50%;
  373. border: 3px solid transparent;
  374. border-top-color: #FFF;
  375. -webkit-animation: spin 3s linear infinite;
  376. -moz-animation: spin 3s linear infinite;
  377. -o-animation: spin 3s linear infinite;
  378. -ms-animation: spin 3s linear infinite;
  379. animation: spin 3s linear infinite;
  380. }
  381. #loader:after {
  382. content: "";
  383. position: absolute;
  384. top: 15px;
  385. left: 15px;
  386. right: 15px;
  387. bottom: 15px;
  388. border-radius: 50%;
  389. border: 3px solid transparent;
  390. border-top-color: #FFF;
  391. -moz-animation: spin 1.5s linear infinite;
  392. -o-animation: spin 1.5s linear infinite;
  393. -ms-animation: spin 1.5s linear infinite;
  394. -webkit-animation: spin 1.5s linear infinite;
  395. animation: spin 1.5s linear infinite;
  396. }
  397. @-webkit-keyframes spin {
  398. 0% {
  399. -webkit-transform: rotate(0deg);
  400. -ms-transform: rotate(0deg);
  401. transform: rotate(0deg);
  402. }
  403. 100% {
  404. -webkit-transform: rotate(360deg);
  405. -ms-transform: rotate(360deg);
  406. transform: rotate(360deg);
  407. }
  408. }
  409. @keyframes spin {
  410. 0% {
  411. -webkit-transform: rotate(0deg);
  412. -ms-transform: rotate(0deg);
  413. transform: rotate(0deg);
  414. }
  415. 100% {
  416. -webkit-transform: rotate(360deg);
  417. -ms-transform: rotate(360deg);
  418. transform: rotate(360deg);
  419. }
  420. }
  421. #loader-wrapper .loader-section {
  422. position: fixed;
  423. top: 0;
  424. width: 51%;
  425. height: 100%;
  426. background: #7171C6;
  427. z-index: 1000;
  428. -webkit-transform: translateX(0);
  429. -ms-transform: translateX(0);
  430. transform: translateX(0);
  431. }
  432. #loader-wrapper .loader-section.section-left {
  433. left: 0;
  434. }
  435. #loader-wrapper .loader-section.section-right {
  436. right: 0;
  437. }
  438. .loaded #loader-wrapper .loader-section.section-left {
  439. -webkit-transform: translateX(-100%);
  440. -ms-transform: translateX(-100%);
  441. transform: translateX(-100%);
  442. -webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  443. transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  444. }
  445. .loaded #loader-wrapper .loader-section.section-right {
  446. -webkit-transform: translateX(100%);
  447. -ms-transform: translateX(100%);
  448. transform: translateX(100%);
  449. -webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  450. transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  451. }
  452. .loaded #loader {
  453. opacity: 0;
  454. -webkit-transition: all 0.3s ease-out;
  455. transition: all 0.3s ease-out;
  456. }
  457. .loaded #loader-wrapper {
  458. visibility: hidden;
  459. -webkit-transform: translateY(-100%);
  460. -ms-transform: translateY(-100%);
  461. transform: translateY(-100%);
  462. -webkit-transition: all 0.3s 1s ease-out;
  463. transition: all 0.3s 1s ease-out;
  464. }
  465. .no-js #loader-wrapper {
  466. display: none;
  467. }
  468. .no-js h1 {
  469. color: #222222;
  470. }
  471. #loader-wrapper .load_title {
  472. font-family: 'Open Sans';
  473. color: #FFF;
  474. font-size: 19px;
  475. width: 100%;
  476. text-align: center;
  477. z-index: 9999999999999;
  478. position: absolute;
  479. top: 60%;
  480. opacity: 1;
  481. line-height: 30px;
  482. }
  483. #loader-wrapper .load_title span {
  484. font-weight: normal;
  485. font-style: italic;
  486. font-size: 13px;
  487. color: #FFF;
  488. opacity: 0.5;
  489. }
  490. </style>
  491. <style>
  492. .el-input__inner{
  493. height:40px;
  494. }
  495. </style>