gaoshp
2024-03-23 bb130af2a7516017e584e4cc5f6fbf8ec2edbd36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export default {
    render() {
 
    },
    data() {
        return {
            logoutCount: this.$TOOL.data.get('AUTO_EXIT')
        }
    },
    mounted() {
        if(this.logoutCount){
            this.setNewAutoExitTime()
            document.onclick = () => {
                this.setNewAutoExitTime()
            }
            document.onmousemove = () => {
                this.setNewAutoExitTime()
            }
            document.onkeydown = () => {
                this.setNewAutoExitTime()
            }
            document.onscroll = () => {
                this.setNewAutoExitTime()
            }
            window.autoExitTimer = window.setInterval(this.autoExitfun, 1000)
        }
    },
    unmounted() {
        if(this.logoutCount){
            clearInterval(window.autoExitTimer)
            window.autoExitTimer = null
        }
    },
    methods: {
        setNewAutoExitTime(){
            window.autoExitTime = new Date().getTime()
        },
        autoExitfun(){
            if(new Date().getTime() - window.autoExitTime > this.logoutCount * 60 * 1000){
                clearInterval(window.autoExitTimer)
                window.autoExitTimer = null
                this.$router.replace({path: '/login'})
                this.$alert("用户长时间无操作,为保证账户安全,系统已自动登出。", "提示", {
                    type: 'warning',
                    center: true,
                    roundButton: true
                })
            }
        }
    }
}