You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
import { computed, onUnmounted, unref, watchEffect } from 'vue'
|
|
|
|
import { useThrottleFn } from '@vueuse/core'
|
|
|
|
|
|
|
|
import { useAppStore } from '@/store/modules/app'
|
|
|
|
import { useLockStore } from '@/store/modules/lock'
|
|
|
|
|
|
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
|
import { useRootSetting } from '../setting/useRootSetting'
|
|
|
|
|
|
|
|
export function useLockPage() {
|
|
|
|
const { getLockTime } = useRootSetting()
|
|
|
|
const lockStore = useLockStore()
|
|
|
|
const userStore = useUserStore()
|
|
|
|
const appStore = useAppStore()
|
|
|
|
|
|
|
|
let timeId: TimeoutHandle
|
|
|
|
|
|
|
|
function clear(): void {
|
|
|
|
window.clearTimeout(timeId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetCalcLockTimeout(): void {
|
|
|
|
// not login
|
|
|
|
if (!userStore.getAccessToken) {
|
|
|
|
clear()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const lockTime = appStore.getProjectConfig.lockTime
|
|
|
|
if (!lockTime || lockTime < 1) {
|
|
|
|
clear()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
clear()
|
|
|
|
|
|
|
|
timeId = setTimeout(() => {
|
|
|
|
lockPage()
|
|
|
|
}, lockTime * 60 * 1000)
|
|
|
|
}
|
|
|
|
|
|
|
|
function lockPage(): void {
|
|
|
|
lockStore.setLockInfo({
|
|
|
|
isLock: true,
|
|
|
|
pwd: undefined
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
watchEffect((onClean) => {
|
|
|
|
if (userStore.getAccessToken) {
|
|
|
|
resetCalcLockTimeout()
|
|
|
|
} else {
|
|
|
|
clear()
|
|
|
|
}
|
|
|
|
onClean(() => {
|
|
|
|
clear()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
clear()
|
|
|
|
})
|
|
|
|
|
|
|
|
const keyupFn = useThrottleFn(resetCalcLockTimeout, 2000)
|
|
|
|
|
|
|
|
return computed(() => {
|
|
|
|
if (unref(getLockTime)) {
|
|
|
|
return { onKeyup: keyupFn, onMousemove: keyupFn }
|
|
|
|
} else {
|
|
|
|
clear()
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|