1.在router.beforeEach()路由首首位加上以下代码
/** * 判断锁屏 */ //登录的时候存的md5加密的密码 let oldPasswordld = localStorage.getItem("lockPassword"); //锁屏页面的md5加密密码 let newlockPassword = localStorage.getItem("newlockPassword"); console.log(oldPasswordld,newlockPassword) if (newlockPassword !== oldPasswordld && to.path !== '/screen') { next('/screen') }
2.书写锁屏页面和相关路由
下面代码为screen/index.js 为锁屏的页面 首先进入这个页面 默认执行一次 unlock方法里面的localStorage.setItem(“newlockPassword”, md5(this.userForm.newPw));
把解锁的密码存到本都对象存储里面,这样路由就好做处理。
<template> <div class="app"> <el-form class="userInfo"> <div class="body-icon"> </div> <div class="title-icon"> </div> <div class="box"> <img src="../../assets/logo/logo.png" class="lock-avatar" /> </div> <el-form-item> <el-row style="margin-left: 100px"> <el-col :span="2"> </el-col> <el-col :span="12" class="lock-nickName">{{ nickName }}</el-col> </el-row> </el-form-item> <el-form-item> <el-input v-model="userForm.newPw" placeholder="请输入登陆密码" type="password" auto-complete="off" @keyup.enter.native="unLock()" show-password > <div slot="prefix" style="margin-left: 3px"> <i class="el-icon-lock"></i></div ></el-input> </el-form-item> <el-form-item> <div style="text-align: center; color: #1890ff"> <a @click="logout">退屏重新登录</a> </div> </el-form-item> <el-form-item> <el-button :loading="loading" size="medium" type="primary" style="width: 100%" @click="unLock" ><i class="el-icon-unlock"></i>解锁</el-button > <!-- <el-button circle type="primary" plain icon="el-icon-unlock" @click="unLock" ></el-button> --> </el-form-item> </el-form> </div> </template> <script> import md5 from "js-md5"; export default { data() { return { userForm: { newPw: "", user: "", }, loading: false, }; }, methods: { unLock() { let oldAuct = localStorage.getItem("lockPassword"); localStorage.setItem("newlockPassword", md5(this.userForm.newPw)); console.log(oldAuct, localStorage.getItem("newlockPassword"), "999990"); if (this.userForm.newPw === "" || this.userForm.newPw === undefined) { return; } else if (md5(this.userForm.newPw) != oldAuct) { this.userForm.newPw = ""; this.$notify.error({ title: "错误", message: "解锁密码错误,请输入登陆密码解锁", duration: 1500, }); return; } else { setTimeout(() => { this.$notify.success({ title: "解锁成功", duration: 1500, }); this.$router.push("/index"); this.userForm.newPw = ""; }, 500); } }, async logout() { this.$confirm("确定注销并退出系统吗?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", }).then(() => { let password = localStorage.getItem("lockPassword"); localStorage.setItem("newlockPassword", password); this.$store.dispatch("LogOut").then(() => { location.href = "/login"; }); }); }, }, mounted() { this.unLock(); }, }; </script> <style lang="scss" scoped> .app { // background-image: url("../../assets/images/back.png"); background-size: 100%; // 背景图片大小最大 height: 100%; //宽、高也最大 width: 100%; background-repeat: no-repeat; background-attachment: fixed; background-position: center; background-color: skyblue; //一定要设置背景颜色 position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: auto; margin: 0; display: flex; justify-content: center; align-items: center; z-index: 1500; .userInfo { // display: flex; background: #ffffff; // height: 300px; width: 400px; padding: 25px 25px 5px 25px; .title-icon { width: 120px; height: 20px; margin-bottom: 22px; } .body-icon { width: 500px; height: 120px; position: absolute; margin-left: -152px; margin-top: -166px; } .box { display: flex; justify-content: center; align-items: center; .lock-avatar { width: 100px; height: 100px; border-radius: 100px; } } .lock-nickName { margin-top: -2px; font-size: 14px; font-weight: 560; text-align: center; } .el-input { height: 38px; input { height: 38px; } } } } </style>