<template>
    <div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            lastTime: null,//最后一次点击事件
            currentTime: null,//当前时间
            sys_timeout: 15 * 60 * 1000, // 超时时间, 如果规定时间15分钟都没有点击页面就算超时 15 * 60* 1000,
            check_time: 5 * 60 * 1000,// 检查的时间，每隔5分钟检查一次有没有超时 5 * 60 * 1000,
            whole_timer: null,// 计时器
        }
    },
    mounted() {
        this.getLock()//锁屏
        this.isLoginOut()//启动这个定时器 
    },
    methods: {
        isLoginOut() {
            clearInterval(this.whole_timer);
            let that = this;
            this.whole_timer = setInterval(() => {
                try {
                    if (that.isTimeOut()) {
                        setTimeout(() => {
                            that.lockScreen()//锁屏
                            clearInterval(that.whole_timer)
                        }, 1000)
                    }
                } catch (error) {

                }
            }, that.check_time);
        },
        isTimeOut() {// 判断是否超时
            this.lastTime = this.$store.state.lastTime;
            this.currentTime = new Date().getTime();
            if ((this.currentTime - this.lastTime) > this.sys_timeout) {
                return true
            } else {
                return false
            }
        },
        //解除锁屏
        unlockScreen() {
            let that = this
            if (!this.password) {
                this.nullPrompt = this.$t('e_password')
                this.isPasswordError = 'true';
                setTimeout(() => {
                    this.isPasswordError = '';
                }, 2000)
            } else {
                this.$api.isLock(
                    this.$getCodeRSA(this.password),//this.$getCodeRSA
                    {
                        onSucess: res => {
                            if (res == undefined) {
                                that.isPasswordError = 'true';
                                // that.$message({type:'warning',message:'密码错误',customClass: 'message-override'})
                                return
                            }
                            this.nullPrompt = '';
                            if (res.data.status == 200) {
                                that.isLock = 'false';
                                sessionStorage.setItem('screenLock', 'false');
                                res.data.data && localStorage.setItem('token', res.data.data)
                                that.isLoginOut()//成功重新启动这个定时器
                            } else {
                                that.isLock = 'true';
                                if (res.data.code == '1000429') {
                                    this.errorTip = res.data.message;
                                    that.isPasswordError = '';
                                } else {
                                    this.errorTip = ''
                                    that.isPasswordError = 'true';
                                    setTimeout(() => {
                                        that.isPasswordError = '';
                                    }, 2000)
                                } 
                            }
                        }, catch: error => {
                            console.log('error1', error)
                        }


                    }
                )
            }
        },
        //解决输入框无法输入
        changePassword() {
            this.$forceUpdate()
        },
    }
}
</script>
<style>
.message-override {
    z-index: 999999 !important;
}
</style>