login.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <div class="login-page scrollbar-box" v-show="showType">
  3. <!--<img class="logo-img" src="@/assets/image/logo@1x.png">-->
  4. <img class="logo-img" :src="rectangleLogo">
  5. <div class="title-img-box">
  6. <div>
  7. <img class="title-img" src="@/assets/image/login/title_icon.png">
  8. </div>
  9. </div>
  10. <div class="login-form-box">
  11. <p class="form-title-p">登录</p>
  12. <el-form ref="loginForm" :model="loginForm" class="login-form">
  13. <div class="username-input-box" :class="userTypeCode == 1||userTypeCode == 4?'username-input-box-code':''">
  14. <img src="@/assets/image/login/icon_dl_zh.png" alt="">
  15. <input type="text" v-model="loginForm.username" placeholder="请输入账号" maxlength="20" @keyup.enter="handleLogin()">
  16. </div>
  17. <div class="password-input-box" :class="userTypeCode == 2||userTypeCode == 4?'username-input-box-code':''">
  18. <img src="@/assets/image/login/icon_dl_mm.png" alt="">
  19. <input type="password" v-model="loginForm.password" placeholder="请输入密码" maxlength="20" @keyup.enter="handleLogin()">
  20. </div>
  21. <p class="text-p">{{text}}</p>
  22. <div class="code-input-box">
  23. <div class="code-input-left-box" :class="userTypeCode == 3||userTypeCode == 5?'username-input-box-code':''">
  24. <img src="@/assets/image/login/icon_dl_yzm.png" alt="">
  25. <input type="text" v-model="loginForm.code" placeholder="请输入验证码" maxlength="4" @keyup.enter="handleLogin()">
  26. </div>
  27. <div class="login-code">
  28. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  29. </div>
  30. </div>
  31. <el-form-item>
  32. <el-button
  33. class="form-button-p"
  34. :loading="loading"
  35. size="medium"
  36. height="50"
  37. @click.native.prevent="handleLogin()"
  38. >
  39. <span v-if="!loading">登 录</span>
  40. <span v-else>登 录 中...</span>
  41. </el-button>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. <p class="introduction-p">技术支持:江苏忠江智能科技有限公司</p>
  46. </div>
  47. </template>
  48. <script>
  49. import md5 from 'js-md5';
  50. import Cookies from "js-cookie";
  51. import { login,authInfo,getCodeImg,getConfigByType,configInfo,getInfo } from "@/api/login";
  52. import {Decrypt} from "@/utils/secret";
  53. import { setToken,getToken,removeToken } from '@/utils/auth'
  54. export default {
  55. name: "Login",
  56. data() {
  57. return {
  58. codeUrl: "",
  59. cookiePassword: "",
  60. type:1,
  61. loginForm: {
  62. username: "",
  63. password: "",
  64. rememberMe: false,
  65. code: "",
  66. uuid: "",
  67. },
  68. loading: false,
  69. // 验证码开关
  70. captchaOnOff: true,
  71. // 注册开关
  72. register: false,
  73. redirect: undefined,
  74. text:"",
  75. userTypeCode:"",
  76. rectangleLogo:localStorage.getItem('rectangleLogo'),
  77. //手机登录
  78. loginType:1,
  79. loginFormTwo:{
  80. username:"",
  81. password:"",
  82. },
  83. loginRulesTwo:{
  84. username: [
  85. { required: true, message: "请输入手机号码", trigger: "blur" },
  86. { required: true, message: "请输入手机号码", validator: this.spaceJudgment, trigger: "blur" }
  87. ],
  88. password: [
  89. { required: true, message: "请输入验证码", trigger: "blur" },
  90. { required: true, message: "请输入验证码", validator: this.spaceJudgment, trigger: "blur" }
  91. ],
  92. },
  93. textTwo:"",
  94. codeNum:"",
  95. timer:null,
  96. codeButtonType:true,
  97. showType:false,
  98. };
  99. },
  100. watch: {
  101. $route: {
  102. handler: function(route) {
  103. this.redirect = route.query && route.query.redirect;
  104. },
  105. immediate: true
  106. }
  107. },
  108. created() {
  109. let self = this;
  110. if(getToken()){
  111. this.$set(this,'showType',false);
  112. Promise.all([
  113. this.getExploitConfig(),
  114. this.getInfo(),
  115. this.fullScreen(),
  116. ]).then((result)=>{
  117. setTimeout(function(){
  118. self.$router.push({path:'/home'});
  119. },300);
  120. }).catch((error) => {})
  121. }else{
  122. this.$set(this,'showType',true);
  123. this.getCode();
  124. }
  125. },
  126. mounted(){
  127. this.configInfo();
  128. },
  129. methods: {
  130. //获取公共配置数据
  131. configInfo(){
  132. let self = this;
  133. configInfo({ type: '1,2,3' }).then(response => {
  134. let list = JSON.parse(response.data)
  135. let newData = {};
  136. list.forEach((item) => {
  137. let obj = JSON.parse(item.configValue)
  138. newData = {...newData,...obj}
  139. })
  140. setTimeout(function(){
  141. self.$set(self,'rectangleLogo',newData.rectangleLogo);
  142. localStorage.setItem('schoolName',newData.schoolName)
  143. localStorage.setItem('circularLogo',newData.circularLogo)
  144. localStorage.setItem('rectangleLogo',newData.rectangleLogo)
  145. localStorage.setItem('videoCover',newData.videoCover)
  146. localStorage.setItem('setSmartAlarmType',newData.smartLock)
  147. },200);
  148. });
  149. },
  150. //获取开发配置
  151. getExploitConfig(){
  152. getConfigByType({ category: 2, configType: 5 }).then(response => {
  153. let obj = JSON.parse(response.data.configValue);
  154. //判定http或者https
  155. let urlText = window.location.href.split('://')[0]+'://';
  156. let outerNet = window.location.href.indexOf(obj.ipIdentify) == -1//true外网 false 内网
  157. if(outerNet){//外网
  158. //MQTT地址
  159. localStorage.setItem('mqttUrl','wss://'+Decrypt(obj.mqttExtranetUrl))
  160. //MQTT账号
  161. localStorage.setItem('mqttUser',Decrypt(obj.mqttExtranetUser))
  162. //MQTT密码
  163. localStorage.setItem('mqttPassword',Decrypt(obj.mqttExtranetPassword))
  164. //PC端回跳地址
  165. localStorage.setItem('pcUrl',urlText+obj.pcExtranetUrl)
  166. localStorage.setItem('fileBrowseEnvironment',urlText+Decrypt(obj.fileBrowseEnvironmentExtranet))
  167. localStorage.setItem('fileBrowseEnvironmentExtranet',urlText+Decrypt(obj.fileBrowseEnvironmentExtranet))
  168. }else{
  169. //MQTT地址
  170. localStorage.setItem('mqttUrl','ws://'+Decrypt(obj.mqttIntranetUrl))
  171. //MQTT账号
  172. localStorage.setItem('mqttUser',Decrypt(obj.mqttIntranetUser))
  173. //MQTT密码
  174. localStorage.setItem('mqttPassword',Decrypt(obj.mqttIntranetPassword))
  175. //PC端回跳地址
  176. localStorage.setItem('pcUrl',urlText+obj.pcIntranetUrl)
  177. localStorage.setItem('fileBrowseEnvironment',urlText+Decrypt(obj.fileBrowseEnvironment))
  178. localStorage.setItem('fileBrowseEnvironmentExtranet',urlText+Decrypt(obj.fileBrowseEnvironmentExtranet))
  179. }
  180. });
  181. },
  182. getCode() {
  183. getCodeImg().then(res => {
  184. this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  185. if (this.captchaOnOff) {
  186. this.codeUrl = "data:image/gif;base64," + res.data.image;
  187. this.loginForm.uuid = res.data.uuid;
  188. }
  189. });
  190. },
  191. getInfo() {
  192. getInfo().then(res => {
  193. localStorage.setItem('deptName',res.data.userInfo.deptName)
  194. localStorage.setItem('deptId',res.data.userInfo.deptId)
  195. });
  196. },
  197. handleLogin() {
  198. let self = this;
  199. //账号登录
  200. if(this.loginForm.username.length<1){
  201. this.text = "*请输入账号";
  202. this.userTypeCode = "1";
  203. return
  204. }else if(this.loginForm.password.length<1){
  205. this.text = "*请输入密码";
  206. this.userTypeCode = "2";
  207. return
  208. }else if(!this.loginForm.code||this.loginForm.code.length<1){
  209. this.text = "*请输入验证码";
  210. this.userTypeCode = "3";
  211. return
  212. }
  213. this.text = "";
  214. this.userTypeCode = "";
  215. this.$refs.loginForm.validate(valid => {
  216. if (valid) {
  217. this.loading = true;
  218. if (this.loginForm.rememberMe) {
  219. Cookies.set("username", this.loginForm.username, { expires: 30 });
  220. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  221. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  222. } else {
  223. Cookies.remove("username");
  224. Cookies.remove("password");
  225. Cookies.remove('rememberMe');
  226. }
  227. this.login(this.loginForm);
  228. }
  229. });
  230. },
  231. login(userInfo){
  232. localStorage.setItem('entranceJumpType','SCHOOL');
  233. let self = this;
  234. const account = userInfo.username.trim()
  235. const password = md5(userInfo.password);
  236. const code = userInfo.code
  237. const uuid = userInfo.uuid
  238. const userType = userInfo.userType
  239. login(account, password, code, uuid, userType).then(res => {
  240. if(res.code == 200){
  241. if(res.data.userType != 3){
  242. this.text = "* 非院级大屏账号,无权登录本系统.";
  243. this.loading = false;
  244. this.getCode();
  245. }else{
  246. localStorage.setItem('userId',res.data.userId);
  247. localStorage.setItem('instituteToken',res.data.token);
  248. setToken(res.data.token)
  249. //身份字段规则转义 原定11老师 22学生 新版本后0系统1老师2学生,这里身份字段转义为旧版本规则
  250. localStorage.setItem('userType',res.data.userType)
  251. //等待配置与字段获取到后跳转
  252. Promise.all([
  253. this.getExploitConfig(),
  254. this.getInfo(),
  255. this.fullScreen(),
  256. ]).then((result)=>{
  257. setTimeout(function(){
  258. self.$router.push({path:'/home'});
  259. },300);
  260. }).catch((error) => {})
  261. }
  262. }else{
  263. if(res.code == 5007){
  264. this.userTypeCode = "4";
  265. }else if(res.code == 500){
  266. this.userTypeCode = "5";
  267. }
  268. this.text = res.message;
  269. this.loading = false;
  270. this.getCode();
  271. }
  272. });
  273. },
  274. //全屏
  275. fullScreen() {
  276. var element = document.documentElement;
  277. if (element.requestFullscreen) {
  278. element.requestFullscreen();
  279. } else if (element.msRequestFullscreen) {
  280. element.msRequestFullscreen();
  281. } else if (element.mozRequestFullScreen) {
  282. element.mozRequestFullScreen();
  283. } else if (element.webkitRequestFullscreen) {
  284. element.webkitRequestFullscreen();
  285. }
  286. },
  287. //退出全屏
  288. exitFullscreen() {
  289. if (document.exitFullscreen) {
  290. document.exitFullscreen();
  291. } else if (document.msExitFullscreen) {
  292. document.msExitFullscreen();
  293. } else if (document.mozCancelFullScreen) {
  294. document.mozCancelFullScreen();
  295. } else if (document.webkitExitFullscreen) {
  296. document.webkitExitFullscreen();
  297. }
  298. },
  299. /*******************手机登录*******************/
  300. loginTypeClick(type){
  301. if(type!=this.loginType){
  302. this.loginType = type;
  303. }
  304. },
  305. getCodeOne() {
  306. if(this.checkPhone(this.loginFormTwo.username)){
  307. if(this.codeButtonType){
  308. sendCode(this.loginFormTwo.username).then(response => {
  309. if(response.code != 200){
  310. this.textTwo = "*"+response.message;
  311. if(response.code == 530){
  312. this.textTwo = "*"+response.message;
  313. }
  314. }else {
  315. this.textTwo = "";
  316. // this.msgSuccess('发送成功');
  317. this.codeButtonType = false;
  318. this.time();
  319. }
  320. });
  321. }
  322. }
  323. },
  324. //定时器
  325. time(){
  326. let self = this;
  327. let time = 30;
  328. self.codeNum = parseInt(time);
  329. this.timer = window.setInterval(refreshCount, 1000);
  330. function refreshCount() {
  331. if(time<=0){
  332. self.codeNum = parseInt(time);
  333. self.codeButtonType = true;
  334. window.clearInterval(self.timer);
  335. }else{
  336. time--;
  337. self.codeNum = parseInt(time);
  338. }
  339. }
  340. },
  341. //手机号验证
  342. checkPhone(value) {
  343. if (!value) {
  344. this.textTwo = '*手机号不能为空哦~';
  345. return false
  346. } else {
  347. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/;
  348. if (reg.test(value)) {
  349. this.textTwo = '';
  350. return true
  351. } else {
  352. this.textTwo = '*请输入正确的手机号码';
  353. return false
  354. }
  355. }
  356. },
  357. },
  358. beforeDestroy() {
  359. //清除定时器
  360. clearInterval(this.timer);
  361. },
  362. destroyed() {
  363. //清除定时器
  364. clearInterval(this.timer);
  365. }
  366. };
  367. </script>
  368. <style rel="stylesheet/scss" lang="scss">
  369. .login-page{
  370. height: 100%;
  371. width:100%;
  372. background-image: url("../assets/image/login/icon_dl_bbg.png");
  373. background-repeat:no-repeat;
  374. background-size: cover;
  375. -webkit-background-size: cover;
  376. -o-background-size: cover;
  377. position: relative;
  378. *{
  379. margin:0;
  380. }
  381. .forgotPasswordBox{
  382. margin-top:5px;
  383. display: flex;
  384. .forgotPasswordNull{
  385. flex:1;
  386. }
  387. .forgotPassword{
  388. text-align: center;
  389. color:#ffffff;
  390. font-size:14px;
  391. cursor: pointer;
  392. }
  393. .forgotPassword:hover{
  394. color:#00ffff;
  395. }
  396. }
  397. .logo-img{
  398. position: absolute;
  399. top:29px;
  400. left:52px;
  401. width:250px;
  402. height:55px;
  403. }
  404. .title-img-box{
  405. position: absolute;
  406. top:74px;
  407. left:50%;
  408. margin-left:-580px;
  409. width:1180px;
  410. height:230px;
  411. div{
  412. position: relative;
  413. img{
  414. width:1180px;
  415. height:230px;
  416. }
  417. p{
  418. position: absolute;
  419. top:72px;
  420. right:300px;
  421. width:50px;
  422. height:26px;
  423. line-height:26px;
  424. text-align: center;
  425. background: #0045AF;
  426. color:#fff;
  427. font-size:14px;
  428. border-radius:70px;
  429. }
  430. }
  431. }
  432. .login-form-box{
  433. width:680px;
  434. height:520px;
  435. background-image: url("../assets/image/login/img_dlk_bg.png");
  436. position: absolute;
  437. top:290px;
  438. left:50%;
  439. margin-left:-340px;
  440. .form-title-p{
  441. line-height:52px;
  442. font-size:24px;
  443. text-align: center;
  444. color:#fff;
  445. font-weight:700;
  446. }
  447. .username-input-box-code:hover{
  448. box-shadow: 0 0 4px 1px rgba(255,39,39,1)!important;
  449. }
  450. .username-input-box-code{
  451. border: 1px solid #FF6A6A!important;
  452. }
  453. .username-input-box:hover{
  454. box-shadow: 0 0 4px 1px rgba(0, 255, 252, 1);
  455. }
  456. .username-input-box{
  457. width:480px;
  458. height:60px;
  459. border: 1px solid #00FFFC;
  460. border-radius: 10px;
  461. background: rgba(0, 13, 41, 0.2);
  462. margin: 40px auto 32px;
  463. display: flex;
  464. overflow: hidden;
  465. img{
  466. height:20px;
  467. width:20px;
  468. margin:20px;
  469. }
  470. input:-webkit-autofill {
  471. -webkit-box-shadow : 0 0 0 1000px rgba(1,25,67,1) inset !important;
  472. -webkit-text-fill-color: #FFFFFF !important;
  473. }
  474. input{
  475. flex:1;
  476. border:none;
  477. outline:none;
  478. background-color: transparent !important;
  479. color: #dedede;
  480. font-size:16px;
  481. }
  482. ::placeholder{
  483. color:#999999 ;
  484. font-size:16px;
  485. }
  486. }
  487. .password-input-box:hover{
  488. box-shadow: 0 0 4px 1px rgba(0, 255, 252, 1);
  489. }
  490. .password-input-box{
  491. width:480px;
  492. height:60px;
  493. border: 1px solid #00FFFC;
  494. border-radius: 10px;
  495. background: rgba(0, 13, 41, 0.2);
  496. margin: 0 auto;
  497. display: flex;
  498. overflow: hidden;
  499. img{
  500. height:20px;
  501. width:20px;
  502. margin:20px;
  503. }
  504. input:-webkit-autofill {
  505. -webkit-box-shadow : 0 0 0 1000px rgba(1,25,67,1) inset !important;
  506. -webkit-text-fill-color: #FFFFFF !important;
  507. }
  508. input{
  509. flex:1;
  510. border:none;
  511. outline:none;
  512. background-color: transparent !important;
  513. color: #dedede;
  514. font-size:16px;
  515. }
  516. ::placeholder{
  517. color:#999999 ;
  518. font-size:16px;
  519. }
  520. }
  521. .text-p{
  522. width:480px;
  523. height:59px;
  524. line-height: 59px;
  525. margin: 0 auto;
  526. font-size: 14px;
  527. font-family: Microsoft YaHei;
  528. color: #DC1616;
  529. }
  530. .code-input-box{
  531. width:480px;
  532. height:60px;
  533. display: flex;
  534. margin: 0 auto;
  535. .code-input-left-box:hover{
  536. box-shadow: 0 0 4px 1px rgba(0, 255, 252, 1);
  537. }
  538. .code-input-left-box{
  539. width:330px;
  540. height:60px;
  541. border: 1px solid #00FFFC;
  542. border-radius: 10px;
  543. background: rgba(0, 13, 41, 0.2);
  544. display: flex;
  545. overflow: hidden;
  546. img{
  547. height:20px;
  548. width:20px;
  549. margin:20px;
  550. }
  551. input:-webkit-autofill {
  552. -webkit-box-shadow: 0 0 0 1000px white inset !important;
  553. }
  554. input{
  555. flex:1;
  556. border:none;
  557. outline:none;
  558. background-color: transparent !important;
  559. color: #dedede;
  560. font-size:16px;
  561. }
  562. ::placeholder{
  563. color:#999999 ;
  564. font-size:16px;
  565. }
  566. }
  567. .login-code{
  568. width:124px;
  569. height:50px;
  570. margin:6px 0 0 25px;
  571. img {
  572. width:124px;
  573. height:50px;
  574. cursor: pointer;
  575. vertical-align: middle;
  576. }
  577. }
  578. }
  579. .form-button-p{
  580. font-size:16px!important;
  581. display: block!important;
  582. width:480px!important;
  583. height: 60px!important;
  584. background: #0045AF!important;
  585. color:#fff!important;
  586. border:none!important;
  587. border-radius: 10px!important;
  588. margin:34px auto 0!important;
  589. }
  590. }
  591. .introduction-p{
  592. width:100%;
  593. text-align: center;
  594. color:#fff;
  595. font-size:16px;
  596. line-height:44px;
  597. position: absolute;
  598. left:0;
  599. bottom:0;
  600. }
  601. }
  602. </style>