From 46f0a7a92dd20fff0eb4c608e363edf0a3d63fff Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 17 Jan 2024 16:00:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=94=81=E5=B1=8F=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LockScreen/index.vue | 35 ++++++++++--------------- src/hooks/useLoading.ts | 16 ----------- src/i18n/locales/en-US.ts | 4 ++- src/i18n/locales/zh-CN.ts | 2 ++ src/layouts/BasicLayout.vue | 3 +++ src/layouts/components/RightContent.vue | 26 ++++++++++++++++-- src/plugins/auth-token.ts | 3 ++- src/store/modules/locked.ts | 32 ++++++++++++++++++++++ 8 files changed, 80 insertions(+), 41 deletions(-) delete mode 100644 src/hooks/useLoading.ts create mode 100644 src/store/modules/locked.ts diff --git a/src/components/LockScreen/index.vue b/src/components/LockScreen/index.vue index 9e265717..4ce9addd 100644 --- a/src/components/LockScreen/index.vue +++ b/src/components/LockScreen/index.vue @@ -4,35 +4,30 @@ import useI18n from '@/hooks/useI18n'; import { message } from 'ant-design-vue/lib'; import { getToken } from '@/plugins/auth-token'; import useUserStore from '@/store/modules/user'; -import { localGet, localSet } from '@/utils/cache-local-utils'; +import useLockedStore from '@/store/modules/locked'; import { getConfigKey } from '@/api/system/config'; -import { CACHE_LOCAL_LOCK } from '@/constants/cache-keys-constants'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { useRouter } from 'vue-router'; - +const lockedStore = useLockedStore(); const userStore = useUserStore(); const router = useRouter(); const { t } = useI18n(); -const isLocked = ref(false); + const password = ref(''); /**设置定时器ID */ let timeoutDuration = 10 * 60 * 1000; // 设置超时时间为10分钟,单位为毫秒 -let timeoutId: any | null = null; +let timeoutId: any = null; +// 超时锁屏 function resetTimeout() { if (timeoutId) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { - fnLock(); + lockedStore.fnLock('lock', true); }, timeoutDuration); } -function fnLock() { - isLocked.value = true; - localSet(CACHE_LOCAL_LOCK, `${isLocked.value}`); -} - /**解锁 */ function handleUnlock() { let lockFrom: any = {}; @@ -42,8 +37,7 @@ function handleUnlock() { if (res.code === RESULT_CODE_SUCCESS) { message.success(t('components.LockScreen.validSucc'), 3); password.value = ''; - isLocked.value = false; - localSet(CACHE_LOCAL_LOCK, `${isLocked.value}`); + lockedStore.fnLock('lock', false); } else { message.error(t('components.LockScreen.validError'), 3); } @@ -52,6 +46,7 @@ function handleUnlock() { /**返回登录界面 */ function backLogin() { + lockedStore.fnLock('lock', false); userStore.fnLogOut().finally(() => router.push({ name: 'Login' })); } @@ -59,6 +54,7 @@ onMounted(() => { getConfigKey('sys.lockTime') .then(res => { if (res.code === RESULT_CODE_SUCCESS && res.data) { + lockedStore.lockTimeout = res.data; timeoutDuration = res.data * 1000; } }) @@ -69,9 +65,9 @@ onMounted(() => { window.addEventListener('mousemove', resetTimeout); window.addEventListener('keydown', resetTimeout); } - const lockStr = localGet(CACHE_LOCAL_LOCK) || ''; - if (lockStr && getToken()) { - isLocked.value = Boolean(lockStr); + // 本地锁定同时是登录状态 + if (lockedStore.isLocked && getToken()) { + lockedStore.fnLock('lock', true); } }); }); @@ -84,14 +80,11 @@ onUnmounted(() => { });