fix: 锁屏页面重构
This commit is contained in:
@@ -4,35 +4,30 @@ import useI18n from '@/hooks/useI18n';
|
|||||||
import { message } from 'ant-design-vue/lib';
|
import { message } from 'ant-design-vue/lib';
|
||||||
import { getToken } from '@/plugins/auth-token';
|
import { getToken } from '@/plugins/auth-token';
|
||||||
import useUserStore from '@/store/modules/user';
|
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 { getConfigKey } from '@/api/system/config';
|
||||||
import { CACHE_LOCAL_LOCK } from '@/constants/cache-keys-constants';
|
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
const lockedStore = useLockedStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const isLocked = ref(false);
|
|
||||||
const password = ref('');
|
const password = ref('');
|
||||||
/**设置定时器ID */
|
/**设置定时器ID */
|
||||||
let timeoutDuration = 10 * 60 * 1000; // 设置超时时间为10分钟,单位为毫秒
|
let timeoutDuration = 10 * 60 * 1000; // 设置超时时间为10分钟,单位为毫秒
|
||||||
let timeoutId: any | null = null;
|
let timeoutId: any = null;
|
||||||
|
|
||||||
|
// 超时锁屏
|
||||||
function resetTimeout() {
|
function resetTimeout() {
|
||||||
if (timeoutId) {
|
if (timeoutId) {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
fnLock();
|
lockedStore.fnLock('lock', true);
|
||||||
}, timeoutDuration);
|
}, timeoutDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnLock() {
|
|
||||||
isLocked.value = true;
|
|
||||||
localSet(CACHE_LOCAL_LOCK, `${isLocked.value}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**解锁 */
|
/**解锁 */
|
||||||
function handleUnlock() {
|
function handleUnlock() {
|
||||||
let lockFrom: any = {};
|
let lockFrom: any = {};
|
||||||
@@ -42,8 +37,7 @@ function handleUnlock() {
|
|||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
message.success(t('components.LockScreen.validSucc'), 3);
|
message.success(t('components.LockScreen.validSucc'), 3);
|
||||||
password.value = '';
|
password.value = '';
|
||||||
isLocked.value = false;
|
lockedStore.fnLock('lock', false);
|
||||||
localSet(CACHE_LOCAL_LOCK, `${isLocked.value}`);
|
|
||||||
} else {
|
} else {
|
||||||
message.error(t('components.LockScreen.validError'), 3);
|
message.error(t('components.LockScreen.validError'), 3);
|
||||||
}
|
}
|
||||||
@@ -52,6 +46,7 @@ function handleUnlock() {
|
|||||||
|
|
||||||
/**返回登录界面 */
|
/**返回登录界面 */
|
||||||
function backLogin() {
|
function backLogin() {
|
||||||
|
lockedStore.fnLock('lock', false);
|
||||||
userStore.fnLogOut().finally(() => router.push({ name: 'Login' }));
|
userStore.fnLogOut().finally(() => router.push({ name: 'Login' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +54,7 @@ onMounted(() => {
|
|||||||
getConfigKey('sys.lockTime')
|
getConfigKey('sys.lockTime')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
|
lockedStore.lockTimeout = res.data;
|
||||||
timeoutDuration = res.data * 1000;
|
timeoutDuration = res.data * 1000;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -69,9 +65,9 @@ onMounted(() => {
|
|||||||
window.addEventListener('mousemove', resetTimeout);
|
window.addEventListener('mousemove', resetTimeout);
|
||||||
window.addEventListener('keydown', resetTimeout);
|
window.addEventListener('keydown', resetTimeout);
|
||||||
}
|
}
|
||||||
const lockStr = localGet(CACHE_LOCAL_LOCK) || '';
|
// 本地锁定同时是登录状态
|
||||||
if (lockStr && getToken()) {
|
if (lockedStore.isLocked && getToken()) {
|
||||||
isLocked.value = Boolean(lockStr);
|
lockedStore.fnLock('lock', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -84,14 +80,11 @@ onUnmounted(() => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<a-button type="text" @click="fnLock">
|
|
||||||
<template #icon><lock-outlined /></template>
|
|
||||||
</a-button>
|
|
||||||
|
|
||||||
<a-modal
|
<a-modal
|
||||||
v-model:visible="isLocked"
|
v-model:visible="lockedStore.isLocked"
|
||||||
get-container="#app"
|
get-container="#app"
|
||||||
:footer="null"
|
:footer="null"
|
||||||
|
:zIndex="1008"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
:keyboard="false"
|
:keyboard="false"
|
||||||
:centered="true"
|
:centered="true"
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { ref, inject, provide } from 'vue';
|
|
||||||
|
|
||||||
const INJECT_LOADING_KEY = Symbol('loading_store');
|
|
||||||
|
|
||||||
export const createLoading = (v = false) => {
|
|
||||||
const loading = ref<boolean>(v);
|
|
||||||
const change = (bool: boolean) => {
|
|
||||||
loading.value = bool;
|
|
||||||
};
|
|
||||||
provide(INJECT_LOADING_KEY, loading);
|
|
||||||
return [loading, change];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useLoading = () => {
|
|
||||||
return inject(INJECT_LOADING_KEY);
|
|
||||||
};
|
|
||||||
@@ -169,6 +169,8 @@ export default {
|
|||||||
helpDoc: 'Doc',
|
helpDoc: 'Doc',
|
||||||
},
|
},
|
||||||
rightContent: {
|
rightContent: {
|
||||||
|
lock: "Lock Screen",
|
||||||
|
lockTip: "Confirmed to perform a lock screen?",
|
||||||
helpDoc: "System User Documentation",
|
helpDoc: "System User Documentation",
|
||||||
fullscreen: "Full Screen",
|
fullscreen: "Full Screen",
|
||||||
logout: "Logout",
|
logout: "Logout",
|
||||||
@@ -230,7 +232,7 @@ export default {
|
|||||||
tabPane2: 'Login with phone number',
|
tabPane2: 'Login with phone number',
|
||||||
registerBtn: 'Register an account',
|
registerBtn: 'Register an account',
|
||||||
loginBtn: 'Sign In',
|
loginBtn: 'Sign In',
|
||||||
loginSuccess: 'Login successful',
|
loginSuccess: 'Login Successful',
|
||||||
loginMethod: 'Other login methods:',
|
loginMethod: 'Other login methods:',
|
||||||
loginMethodWX: 'WeChat Scan Login',
|
loginMethodWX: 'WeChat Scan Login',
|
||||||
loginMethodQQ: 'QQ Scan Code Login',
|
loginMethodQQ: 'QQ Scan Code Login',
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ export default {
|
|||||||
helpDoc: '使用手册',
|
helpDoc: '使用手册',
|
||||||
},
|
},
|
||||||
rightContent: {
|
rightContent: {
|
||||||
|
lock: "锁屏",
|
||||||
|
lockTip: "确认要进行锁屏吗?",
|
||||||
helpDoc: "系统使用文档",
|
helpDoc: "系统使用文档",
|
||||||
fullscreen: "全屏显示",
|
fullscreen: "全屏显示",
|
||||||
logout: "退出登录",
|
logout: "退出登录",
|
||||||
|
|||||||
@@ -308,6 +308,9 @@ document.addEventListener('visibilitychange', function () {
|
|||||||
</transition>
|
</transition>
|
||||||
</RouterView>
|
</RouterView>
|
||||||
|
|
||||||
|
<!-- 锁屏遮罩 -->
|
||||||
|
<LockScreen />
|
||||||
|
|
||||||
<!--插槽-内容底部-->
|
<!--插槽-内容底部-->
|
||||||
<template #footerRender="{ width }">
|
<template #footerRender="{ width }">
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
|
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
|
||||||
|
import Modal from 'ant-design-vue/lib/modal/Modal';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useFullscreen } from '@vueuse/core';
|
import { useFullscreen } from '@vueuse/core';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
import useAppStore from '@/store/modules/app';
|
import useAppStore from '@/store/modules/app';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import useAlarmStore from '@/store/modules/alarm';
|
import useAlarmStore from '@/store/modules/alarm';
|
||||||
import LockScreen from '@/components/LockScreen/index.vue';
|
import useLockedStore from '@/store/modules/locked';
|
||||||
const { isFullscreen, toggle } = useFullscreen();
|
const { isFullscreen, toggle } = useFullscreen();
|
||||||
const { t, changeLocale, optionsLocale } = useI18n();
|
const { t, changeLocale, optionsLocale } = useI18n();
|
||||||
|
const lockedStore = useLockedStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -28,6 +30,17 @@ function fnClick({ key }: MenuInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**锁屏按钮提示 */
|
||||||
|
function fnClickLock() {
|
||||||
|
Modal.confirm({
|
||||||
|
title: t('common.tipTitle'),
|
||||||
|
content: t('loayouts.rightContent.lockTip'),
|
||||||
|
onOk() {
|
||||||
|
lockedStore.fnLock('lock', true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**告警数按钮提示跳转 */
|
/**告警数按钮提示跳转 */
|
||||||
function fnClickAlarm() {
|
function fnClickAlarm() {
|
||||||
router.push({ name: 'ActiveAlarm_2088' });
|
router.push({ name: 'ActiveAlarm_2088' });
|
||||||
@@ -62,7 +75,16 @@ function fnChangeLocale(e: any) {
|
|||||||
</a-badge>
|
</a-badge>
|
||||||
</template>
|
</template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<LockScreen />
|
|
||||||
|
<a-tooltip placement="bottom">
|
||||||
|
<template #title>{{ t('loayouts.rightContent.lock') }}</template>
|
||||||
|
<a-button type="text" @click="fnClickLock">
|
||||||
|
<template #icon>
|
||||||
|
<LockOutlined />
|
||||||
|
</template>
|
||||||
|
</a-button>
|
||||||
|
</a-tooltip>
|
||||||
|
|
||||||
<a-tooltip placement="bottom">
|
<a-tooltip placement="bottom">
|
||||||
<template #title>{{ t('loayouts.rightContent.helpDoc') }}</template>
|
<template #title>{{ t('loayouts.rightContent.helpDoc') }}</template>
|
||||||
<a-button type="text" @click="fnClickHelpDoc()">
|
<a-button type="text" @click="fnClickHelpDoc()">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import { TOKEN_COOKIE } from '@/constants/token-constants';
|
import { TOKEN_COOKIE } from '@/constants/token-constants';
|
||||||
import { localRemove } from '@/utils/cache-local-utils';
|
import { localRemove, localSet } from '@/utils/cache-local-utils';
|
||||||
import { CACHE_LOCAL_LOCK } from '@/constants/cache-keys-constants';
|
import { CACHE_LOCAL_LOCK } from '@/constants/cache-keys-constants';
|
||||||
|
|
||||||
/**获取cookis中Token字符串 */
|
/**获取cookis中Token字符串 */
|
||||||
@@ -11,6 +11,7 @@ export function getToken(): string {
|
|||||||
/**设置cookis中Token字符串 */
|
/**设置cookis中Token字符串 */
|
||||||
export function setToken(token: string): void {
|
export function setToken(token: string): void {
|
||||||
Cookies.set(TOKEN_COOKIE, token);
|
Cookies.set(TOKEN_COOKIE, token);
|
||||||
|
localSet(CACHE_LOCAL_LOCK, 'false');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**移除cookis中Token字符串,localStorage中锁屏字符串 */
|
/**移除cookis中Token字符串,localStorage中锁屏字符串 */
|
||||||
|
|||||||
32
src/store/modules/locked.ts
Normal file
32
src/store/modules/locked.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { CACHE_LOCAL_LOCK } from '@/constants/cache-keys-constants';
|
||||||
|
import { localGet, localSet } from '@/utils/cache-local-utils';
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
/**锁屏信息类型 */
|
||||||
|
type Locked = {
|
||||||
|
/**锁定状态 */
|
||||||
|
isLocked: boolean;
|
||||||
|
/**锁屏类型 */
|
||||||
|
lockType: 'lock' | 'reload' | 'upgrade';
|
||||||
|
/**超时锁屏时间,秒*/
|
||||||
|
lockTimeout: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const useLockedStore = defineStore('locked', {
|
||||||
|
state: (): Locked => ({
|
||||||
|
isLocked: localGet(CACHE_LOCAL_LOCK) === 'true',
|
||||||
|
lockType: 'lock',
|
||||||
|
lockTimeout: 0,
|
||||||
|
}),
|
||||||
|
getters: {},
|
||||||
|
actions: {
|
||||||
|
// 设置锁定
|
||||||
|
async fnLock(type: 'lock' | 'reload' | 'upgrade', v: boolean) {
|
||||||
|
this.lockType = type;
|
||||||
|
this.isLocked = v;
|
||||||
|
localSet(CACHE_LOCAL_LOCK, `${v}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default useLockedStore;
|
||||||
Reference in New Issue
Block a user