最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

element-vue實(shí)現(xiàn)網(wǎng)頁(yè)鎖屏功能(示例代碼)

 更新時(shí)間:2023年11月28日 09:38:09   作者:YJ_Root  
這篇文章主要介紹了element-vue實(shí)現(xiàn)網(wǎng)頁(yè)鎖屏功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

element-vue實(shí)現(xiàn)網(wǎng)頁(yè)鎖屏功能

1.寫一個(gè)鎖屏頁(yè)面,這里比較簡(jiǎn)單,自己定義一下,需要放到底層HTML中哦,比如index.html

<div id="appIndex">
    <el-dialog title="請(qǐng)輸入密碼解鎖屏幕" :visible.sync="lockScreenFlag" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false" :append-to-body="true"
               width="500px" center>
        <el-form :model="form" :rules="rules" ref="form">
            <el-form-item label="用戶名" prop="loginName">
                <el-input v-model="form.loginName" autocomplete="off" :disabled="true" prefix-icon="el-icon-user-solid"></el-input>
            </el-form-item>
            <el-form-item label="密碼" prop="password">
<!--                <el-input type="password" v-model="form.password" autocomplete="off" prefix-icon="el-icon-lock"></el-input>-->
                <el-input prefix-icon="el-icon-lock" placeholder="請(qǐng)輸入密碼" :type="inputType?'text':'password'" v-model="form.password">
                    <i slot="suffix" :class="inputType?'el-icon-minus':'el-icon-view'" style="margin-top:8px;font-size:18px;" autocomplete="auto" @click="inputType=!inputType"></i>
                </el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: right; padding-right: 5px;">
            <el-button type="primary" @click="submitPassword" size="small">確 定</el-button>
        </div>
    </el-dialog>
</div>

2.里面需要結(jié)合Vue雙向綁定的成分

//用戶信息
let user = [[${user}]]
//過(guò)期事件,
    let lockScreenTime = 30
    let app = new Vue({
        el: '#appIndex',
        data: function () {
            var passwordSuccess = (rule, value, callback) => {
                request.post(ctx+"system/user/checkLoginNameAndPassword",Qs.stringify(this.form)).then(res=>{
                    if (res.data == 0){
                        callback();
                    }
                    else if (res.data == 1){
                        callback(new Error("輸入的密碼錯(cuò)誤或輸入了非法用戶名"));
                    }
                    else {
                        callback(new Error(res.data.msg));
                    }
                })
            }
            return {
                lockScreenFlag: false,
                timer: undefined,
                time: parseFloat(lockScreenTime)*1000*60,
                form:{
                    loginName:user.loginName,
                    password: '',
                },
                inputType: false,
                rules: {
                    password: [
                        {required: true, message: '請(qǐng)輸入用戶名密碼', trigger: 'blur'},
                        {validator: passwordSuccess, trigger: 'blur'},
                    ],
                },
            }
        },
        created: function () {
            if (window.localStorage.getItem("lockScreenFlag")!=undefined){
                let lockScreenFlag = window.localStorage.getItem("lockScreenFlag");
                if (lockScreenFlag == '0'){
                    this.lockScreenFlag = false;
                    $("#wrapper").css("pointer-events","auto")
                }else {
                    $("#wrapper").css("pointer-events","none")
                    this.lockScreenFlag = true;
                }
            }
            this.move();
        },
        mounted(){
            let _this = this;
            window.document.onmousemove = function () {
                _this.move();
            }
            window.move = this.move;
            window.openScreen = this.openScreen;
        },
        methods: {
            submitPassword(){
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        this.lockScreenFlag = false;
                        $("#wrapper").css("pointer-events","auto")
                        window.localStorage.setItem("lockScreenFlag",'0')
                    }
                })
            },
            lockScreen(){
                window.clearTimeout(this.timer)
                this.timer = window.setTimeout(this.openScreen,this.time)
            },
            openScreen(){
                if (!this.lockScreenFlag){
                    this.lockScreenFlag = true;
                    $("#wrapper").css("pointer-events","none")
                    window.localStorage.setItem("lockScreenFlag",'1')
                }
            },
            move(){
                if (!this.lockScreenFlag){
                    this.lockScreen()
                }
            }
        }
    })

擴(kuò)展

前端(vue)鎖屏功能實(shí)現(xiàn),解決刷新會(huì)退出鎖屏、重新進(jìn)入顯示鎖屏頁(yè)面等問(wèn)題

背景

設(shè)計(jì)一個(gè)鎖屏頁(yè)面供用戶離開(手動(dòng)點(diǎn)擊)或者長(zhǎng)時(shí)間未操作時(shí)使用

場(chǎng)景

  • 用戶一段時(shí)間沒有操作或者手動(dòng)點(diǎn)擊鎖屏按鈕時(shí),顯示鎖屏頁(yè)面
  • 在鎖屏頁(yè)面強(qiáng)制刷新時(shí),需保持在顯示鎖屏頁(yè)面或者跳轉(zhuǎn)到登錄頁(yè)面(通過(guò)判斷token是否有效決定是否跳轉(zhuǎn)到登錄)
  • 如果當(dāng)前窗口已經(jīng)鎖屏,重開一個(gè)該地址的新窗口;或者關(guān)閉當(dāng)前窗口時(shí)是鎖屏狀態(tài),重新打開窗口時(shí),新窗口直接跳到登錄頁(yè)面。

實(shí)現(xiàn)

  • 鎖屏頁(yè)面的實(shí)現(xiàn)
    鎖屏頁(yè)面通過(guò)fixed布局的方式覆蓋整個(gè)窗口(也可以通過(guò)路由的方式,但是路由的方式不方便解鎖后的路由返回),(setIsLock方法在下文)

LockPage組件

<template>
  <div class="lock-container">
    自定義鎖屏內(nèi)容
  </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'Lock',
  data () {
    return {
    }
  },
  computed: {
  },
  methods: {
    ...mapActions({
      // 設(shè)置是否鎖屏
      setIsLock: 'systemLock/setIsLock'
    }),
    handleLogin () {
      // 省略解鎖邏輯
      this.setIsLock(false)
    }
  },
  components: {}
}
</script>
<style lang="scss" scoped>
.lock-container {
  z-index: 1001;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
}
</style>

2.APP.vue中使用鎖屏組件

app.vue中只包含簡(jiǎn)單的鎖屏組件和路由視圖,通過(guò)isLock和是否登錄(islogon)判斷鎖屏是否顯示。
3.isLock的設(shè)置
使用的vuex的狀態(tài)管理來(lái)存儲(chǔ)isLock
點(diǎn)擊鎖屏按鈕、設(shè)定時(shí)間內(nèi)未操作(鼠標(biāo)未移動(dòng))則設(shè)置isLock=true,當(dāng)isLock為false,且設(shè)定時(shí)間內(nèi)為設(shè)置isLock則認(rèn)為是未操作設(shè)置其為true

vuex設(shè)置isLock的方法

setIsLock ({ commit, state }, isLock) {
    commit('SET_ISLOCK', isLock)
    if (!isLock) {
      clearTimeout(timeOut)
      //設(shè)置時(shí)間內(nèi)未操作,則設(shè)置鎖屏狀態(tài)為true
      timeOut = setTimeout(() => {
        commit('SET_ISLOCK', true)
      }, 1000 * 30 * 60)
    }
  }

APP.vue中監(jiān)聽鼠標(biāo)移動(dòng),移動(dòng)則讓isLock為false(vuex重新計(jì)時(shí))

 // 在登錄后且未鎖屏狀態(tài)監(jiān)聽用戶是否操作(鼠標(biāo)移動(dòng))
 wacth:{
	isLock: {
      handler: function (newVal, oldVal) {
        if (this.isLock) {
          window.removeEventListener('mousemove', this.mousemove)
        } else if (this.islogon) {
          // 未鎖屏且已經(jīng)登錄的情況監(jiān)聽用戶操作
          window.addEventListener('mousemove', this.mousemove)
        }
      },
      immediate: false
    },
 },
 methods: {
    ...mapActions({
      setIsLock: 'systemLock/setIsLock',
    }),
    mousemove () {
      _.throttle(() => {
        this.setIsLock(false)
      }, 1000 * 60, {
        leading: true,
        trailing: false
      })
    }
  },

問(wèn)題1:鎖屏?xí)r刷新頁(yè)面,vuex的內(nèi)容被初始化,從而退出鎖屏頁(yè)面,不滿足需求
解決:同時(shí)使用localStorage來(lái)存儲(chǔ)isLock

1.用localSotrage來(lái)初始化vuex

在這里插入圖片描述

2.isLock變化時(shí)同時(shí)設(shè)置localStorage
跳轉(zhuǎn)isLock的watch方法調(diào)整:

watch:{
	isLock: {
      handler: function (newVal, oldVal) {
        if (this.isLock) {
          window.removeEventListener('mousemove', this.mousemove)
          localStorage.setItem('isLock', 'isLock')
        } else {
          localStorage.removeItem('isLock')
          if (this.islogon) {
            window.addEventListener('mousemove', this.mousemove)
          }
        }
      },
      immediate: false
    },
}

問(wèn)題2:如果使用localStorage來(lái)初始化vuex,若在鎖屏?xí)r關(guān)閉窗口,后面再打開網(wǎng)站時(shí)會(huì)直接進(jìn)入鎖屏頁(yè)面,不合理,應(yīng)該直接到登錄頁(yè)面
解決
使用sessionStorage來(lái)判斷當(dāng)前的操作是第一次進(jìn)入系統(tǒng)還是刷新系統(tǒng)(sessionStorage只在當(dāng)前窗口有效)。第一次進(jìn)入系統(tǒng)時(shí)如果localStorage的isLock=‘isLock’則不要用localStorage初始化vuex,直接跳轉(zhuǎn)到登錄頁(yè)面;若為刷新操作,則用localSotrage來(lái)初始化vuex。

1.vuex中isLock初始化值設(shè)置為false

在這里插入圖片描述

2.在sessionStorage設(shè)置initialized字段代表是否已經(jīng)初始化。在APP.vue的created中手動(dòng)初始化vuex的isLock

 created () {
    if (localStorage.getItem('isLock') === 'isLock') {
      // 刷新時(shí)(非首次進(jìn)入),如果是鎖屏狀態(tài),則繼續(xù)顯示鎖屏頁(yè)面
      if (sessionStorage.getItem('initialized') === 'initialized') {
        this.setIsLock(true)
      } else {
      	this.$router.push('/login')
        localStorage.removeItem('isLock')
      }
    }
}

附:
vuex完整代碼:

let timeOut = null
const _state = {
  lockTime: 1000 * 30 * 60,
  isShowLock: false,
  isLock: false
}
const getters = {
  lockTime: state => state.lockTime,
  isShowLock: state => state.isShowLock,
  isLock: state => state.isLock
}
const mutations = {
  SET_ISLOCK: (state, isLock) => {
    state.isLock = isLock
  },
  SET_LOCKTIME: (state, lockTime) => {
    state.lockTime = lockTime
  },
  SET_ISSHOWLOCK: (state, isShowLock) => {
    state.isShowLock = isShowLock
  }
}
const actions = {
  setLockTime ({ commit }, lockTime) {
    commit('SET_LOCKTIME', lockTime * 1000 * 60)
  },
  setIsShowLock ({ commit }, isShowLock) {
    commit('SET_ISSHOWLOCK', isShowLock)
  },
  setIsLock ({ commit, state }, isLock) {
    commit('SET_ISLOCK', isLock)
    if (!isLock) {
      clearTimeout(timeOut)
      timeOut = setTimeout(() => {
        commit('SET_ISLOCK', true)
      }, state.lockTime)
    }
  }
}
export default {
  namespaced: true,
  getters,
  state: _state,
  mutations,
  actions
}

到此這篇關(guān)于element-vue實(shí)現(xiàn)網(wǎng)頁(yè)鎖屏功能的文章就介紹到這了,更多相關(guān)element-vue網(wǎng)頁(yè)鎖屏內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue使用自定義指令實(shí)現(xiàn)一鍵復(fù)制功能

    vue使用自定義指令實(shí)現(xiàn)一鍵復(fù)制功能

    在Vue中,通過(guò)自定義指令v-copy和document.execCommand方法,可以實(shí)現(xiàn)點(diǎn)擊按鈕復(fù)制內(nèi)容到剪貼板的功能,適用于處理長(zhǎng)文本或多行文本的復(fù)制需求,而readonly屬性可避免內(nèi)容被修改和移動(dòng)設(shè)備上的虛擬鍵盤干擾,感興趣的朋友一起看看吧
    2024-09-09
  • Vue3+Vite多項(xiàng)目多dist打包操作實(shí)現(xiàn)方式

    Vue3+Vite多項(xiàng)目多dist打包操作實(shí)現(xiàn)方式

    本文介紹了如何使用Vue3和Vite搭建多項(xiàng)目環(huán)境,并在打包時(shí)生成多個(gè)dist包,通過(guò)創(chuàng)建主項(xiàng)目環(huán)境、配置多個(gè)dist包、以及執(zhí)行打包操作,可以實(shí)現(xiàn)多個(gè)子項(xiàng)目的獨(dú)立管理
    2025-12-12
  • Vue3其它API suspense組件全局API如何轉(zhuǎn)移到應(yīng)用對(duì)象上

    Vue3其它API suspense組件全局API如何轉(zhuǎn)移到應(yīng)用對(duì)象上

    這篇文章主要介紹了Vue3其它API suspense組件全局API如何轉(zhuǎn)移到應(yīng)用對(duì)象上的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-06-06
  • Vue3.js自定義組件 v-model詳解

    Vue3.js自定義組件 v-model詳解

    在Vue3 中,v-model是用于創(chuàng)建雙向數(shù)據(jù)綁定的指令,通常,我們使用該指令將任何 HTML 表單元素與一個(gè)變量綁定以收集輸入值,本文給大家介紹Vue3.js自定義組件 v-model,感興趣的朋友一起看看吧
    2023-10-10
  • Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼(基于postrender機(jī)制)

    Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼(基于postrender機(jī)制)

    本篇文章給大家介紹基于postrender機(jī)制使用Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-09-09
  • Vue關(guān)于element穿梭框進(jìn)行的修改成table表格穿梭框方式

    Vue關(guān)于element穿梭框進(jìn)行的修改成table表格穿梭框方式

    這篇文章主要介紹了Vue關(guān)于element穿梭框進(jìn)行的修改成table表格穿梭框方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • Vue查詢數(shù)據(jù)并通過(guò)bootstarp?table渲染數(shù)據(jù)

    Vue查詢數(shù)據(jù)并通過(guò)bootstarp?table渲染數(shù)據(jù)

    這篇文章主要為大家介紹了Vue查詢數(shù)據(jù)并通過(guò)bootstarp?table渲染數(shù)據(jù),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • 基于Vue實(shí)現(xiàn)人民幣小寫轉(zhuǎn)為大寫功能

    基于Vue實(shí)現(xiàn)人民幣小寫轉(zhuǎn)為大寫功能

    在金融類應(yīng)用中,經(jīng)常需要將金額從小寫數(shù)字轉(zhuǎn)換為大寫形式,這種轉(zhuǎn)換主要用于正式票據(jù)、合同等場(chǎng)合,以增加文本的專業(yè)性和可讀性,本文將詳細(xì)介紹如何在Vue.js項(xiàng)目中實(shí)現(xiàn)這一功能,并提供多個(gè)示例和詳細(xì)的代碼說(shuō)明,需要的朋友可以參考下
    2024-09-09
  • 解決vue 按鈕多次點(diǎn)擊重復(fù)提交數(shù)據(jù)問(wèn)題

    解決vue 按鈕多次點(diǎn)擊重復(fù)提交數(shù)據(jù)問(wèn)題

    這篇文章主要介紹了vue 按鈕多次點(diǎn)擊重復(fù)提交數(shù)據(jù)的問(wèn)題,本文通過(guò)實(shí)例結(jié)合的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-05-05
  • vue中使用gojs/jointjs的示例代碼

    vue中使用gojs/jointjs的示例代碼

    這篇文章主要介紹了vue中使用gojs/jointjs的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08

最新評(píng)論

三穗县| 若尔盖县| 株洲县| 稷山县| 湘潭市| 济宁市| 剑河县| 赫章县| 天台县| 重庆市| 康平县| 玉林市| 左云县| 钟祥市| 拉萨市| 麻江县| 临沧市| 平阴县| 大新县| 房山区| 海伦市| 通河县| 广平县| 敖汉旗| 康保县| 元朗区| 高邑县| 南皮县| 同心县| 垣曲县| 息烽县| 崇仁县| 青阳县| 张家口市| 阿尔山市| 泽库县| 塔河县| 肃南| 泸溪县| 柘城县| 和硕县|