This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@vueuse相关放入@vben/utils
- Loading branch information
Showing
36 changed files
with
99 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,88 @@ | ||
import {computed, onUnmounted, unref, watch, watchEffect} from 'vue'; | ||
import {useThrottleFn} from '@vben/use'; | ||
import { computed, onUnmounted, unref, watch, watchEffect } from 'vue' | ||
import { useThrottleFn } from '@vben/utils' | ||
|
||
import {useLockStore} from '@/store/lock'; | ||
import {useConfigStore} from '@/store/config' | ||
import {useUserStore} from '@/store/user'; | ||
import {useRootSetting} from '../setting/useRootSetting'; | ||
import {BASIC_LOCK_PATH} from '@vben/constants' | ||
import {router} from "@/router"; | ||
import { useLockStore } from '@/store/lock' | ||
import { useConfigStore } from '@/store/config' | ||
import { useUserStore } from '@/store/user' | ||
import { useRootSetting } from '../setting/useRootSetting' | ||
import { BASIC_LOCK_PATH } from '@vben/constants' | ||
import { router } from '@/router' | ||
|
||
const LOCK_PATH = BASIC_LOCK_PATH; | ||
const LOCK_PATH = BASIC_LOCK_PATH | ||
|
||
export function useLockScreen() { | ||
const {getLockTime} = useRootSetting(); | ||
const lockStore = useLockStore(); | ||
const userStore = useUserStore(); | ||
const { getLockTime } = useRootSetting() | ||
const lockStore = useLockStore() | ||
const userStore = useUserStore() | ||
const configStore = useConfigStore() | ||
|
||
let timeId: TimeoutHandle; | ||
let timeId: TimeoutHandle | ||
|
||
function clear(): void { | ||
window.clearTimeout(timeId); | ||
window.clearTimeout(timeId) | ||
} | ||
|
||
function resetCalcLockTimeout(): void { | ||
// not login | ||
if (!userStore.getAccessToken) { | ||
clear(); | ||
return; | ||
clear() | ||
return | ||
} | ||
const lockTime = configStore.getProjectConfig.lockTime; | ||
const lockTime = configStore.getProjectConfig.lockTime | ||
if (!lockTime || lockTime < 1) { | ||
clear(); | ||
return; | ||
clear() | ||
return | ||
} | ||
clear(); | ||
clear() | ||
|
||
timeId = setTimeout(() => { | ||
lockPage(); | ||
}, lockTime * 60 * 1000); | ||
lockPage() | ||
}, lockTime * 60 * 1000) | ||
} | ||
|
||
function lockPage(): void { | ||
lockStore.setLockInfo({ | ||
isLock: true, | ||
pwd: undefined | ||
}); | ||
pwd: undefined, | ||
}) | ||
} | ||
|
||
watchEffect((onClean) => { | ||
if (userStore.getAccessToken) { | ||
resetCalcLockTimeout(); | ||
resetCalcLockTimeout() | ||
} else { | ||
clear(); | ||
clear() | ||
} | ||
onClean(() => { | ||
clear(); | ||
}); | ||
}); | ||
clear() | ||
}) | ||
}) | ||
|
||
watch(() => lockStore.getLockInfo?.isLock, | ||
watch( | ||
() => lockStore.getLockInfo?.isLock, | ||
(newValue) => { | ||
if (newValue) { | ||
router.replace({ | ||
path: LOCK_PATH, | ||
query: {redirect: unref(router.currentRoute).path} | ||
query: { redirect: unref(router.currentRoute).path }, | ||
}) | ||
} | ||
}, {deep: true}) | ||
}, | ||
{ deep: true }, | ||
) | ||
|
||
onUnmounted(() => { | ||
clear(); | ||
}); | ||
clear() | ||
}) | ||
|
||
const keyupFn = useThrottleFn(resetCalcLockTimeout, 2000); | ||
const keyupFn = useThrottleFn(resetCalcLockTimeout, 2000) | ||
|
||
return computed(() => { | ||
if (unref(getLockTime)) { | ||
return {onKeyup: keyupFn, onMousemove: keyupFn}; | ||
return { onKeyup: keyupFn, onMousemove: keyupFn } | ||
} else { | ||
clear(); | ||
return {}; | ||
clear() | ||
return {} | ||
} | ||
}); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export * from './usePromise' | ||
export * from './web' | ||
export * from './useTitle' | ||
export * from './usePage' | ||
export * from './useContext' | ||
export * from './useRefs' |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { computed, ref, unref } from 'vue' | ||
import { useElementSize } from '@vben/use' | ||
import { ref } from 'vue' | ||
import { useElementSize } from '@vben/utils' | ||
import { context } from '../bridge' | ||
export const layoutHeader = ref(null) | ||
// 获取header高度 | ||
// @ts-ignore | ||
export const headerRef = ref<HTMLElement | null>(null) | ||
// @ts-ignore | ||
export const { height, width } = useElementSize(headerRef) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.