| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import { computed, onUnmounted, unref, watchEffect } from 'vue';
- import { useThrottleFn } from '@vueuse/core';
- import { useAppStore } from '@jeesite/core/store/modules/app';
- import { useLockStore } from '@jeesite/core/store/modules/lock';
- import { useUserStore } from '@jeesite/core/store/modules/case';
- 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.getToken) {
- if (userStore.getSessionTimeout) {
- clear();
- return;
- }
- const lockTime = appStore.getProjectConfig.lockTime;
- if (!lockTime || lockTime < 1 || lockTime > 99999) {
- clear();
- return;
- }
- clear();
- timeId = setTimeout(
- () => {
- lockPage();
- },
- lockTime * 60 * 1000,
- );
- }
- function lockPage(): void {
- lockStore.setLockInfo({
- isLock: true,
- pwd: undefined,
- });
- }
- watchEffect((onClean) => {
- // if (userStore.getToken) {
- if (!userStore.getSessionTimeout) {
- 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 {};
- }
- });
- }
|