vue做一个锁屏禁止页面前进后退

1.在router.beforeEach()路由首首位加上以下代码

javascript 复制代码
	 /**
	 * 判断锁屏
	 */
	 //登录的时候存的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));

把解锁的密码存到本都对象存储里面,这样路由就好做处理。

javascript 复制代码
	<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>
相关推荐
旭久11 分钟前
vue-计算两个日期之前的天数小方法
前端·javascript·vue.js
游王子15 分钟前
Vue.js组件(6):echarts组件
前端·vue.js·echarts
Smile_Gently42 分钟前
Ubuntu环境 nginx.conf详解(二)
运维·服务器·前端·nginx·ubuntu
m0_748233881 小时前
黑马程序员JavaWeb开发教程(前端部分) ---笔记分享
前端·笔记
温轻舟1 小时前
前端开发 -- 自定义鼠标指针样式
开发语言·前端·javascript·css·html·温轻舟
天天打码2 小时前
ThinkPHP项目如何关闭runtime下Log日志文件记录
android·java·javascript
冰镇屎壳郎2 小时前
前端安全 常见的攻击类型及防御措施
前端·安全·前端安全
2401_857617622 小时前
“无缝购物体验”:跨平台网上购物商城的设计与实现
java·开发语言·前端·安全·架构·php
2401_857439692 小时前
智慧社区电商系统:提升用户体验的界面设计
前端·javascript·php·ux
我是高手高手高高手2 小时前
ThinkPHP8多应用配置及不同域名访问不同应用的配置
linux·服务器·前端·php