fix: 定义锁屏类型

This commit is contained in:
TsMask
2024-01-18 10:11:15 +08:00
parent b445464192
commit 817712029b
4 changed files with 21 additions and 22 deletions

View File

@@ -8,6 +8,7 @@ import useLockedStore from '@/store/modules/locked';
import { getConfigKey } from '@/api/system/config';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { useRouter } from 'vue-router';
import { computed } from 'vue';
const lockedStore = useLockedStore();
const userStore = useUserStore();
const router = useRouter();
@@ -24,7 +25,7 @@ function resetTimeout() {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
lockedStore.fnLock('lock', true);
lockedStore.fnLock('lock');
}, timeoutDuration);
}
@@ -37,7 +38,7 @@ function handleUnlock() {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('components.LockScreen.validSucc'), 3);
password.value = '';
lockedStore.fnLock('lock', false);
lockedStore.fnLock('none');
} else {
message.error(t('components.LockScreen.validError'), 3);
}
@@ -46,10 +47,12 @@ function handleUnlock() {
/**返回登录界面 */
function backLogin() {
lockedStore.fnLock('lock', false);
lockedStore.fnLock('none');
userStore.fnLogOut().finally(() => router.push({ name: 'Login' }));
}
const isLocked = computed(() => lockedStore.type !== 'none');
onMounted(() => {
getConfigKey('sys.lockTime')
.then(res => {
@@ -66,8 +69,8 @@ onMounted(() => {
window.addEventListener('keydown', resetTimeout);
}
// 本地锁定同时是登录状态
if (lockedStore.isLocked && getToken()) {
lockedStore.fnLock('lock', true);
if (lockedStore.type === 'lock' && getToken()) {
lockedStore.fnLock('lock');
}
});
});
@@ -81,7 +84,7 @@ onUnmounted(() => {
</script>
<template>
<a-modal
v-model:visible="lockedStore.isLocked"
v-model:visible="isLocked"
get-container="#app"
:footer="null"
:zIndex="1008"
@@ -99,7 +102,7 @@ onUnmounted(() => {
}"
>
<!-- 锁屏-登录 -->
<div class="lock-screen_login" v-if="lockedStore.lockType === 'lock'">
<div class="lock-screen_login" v-if="lockedStore.type === 'lock'">
<div class="lock-screen_login-user">
<a-avatar
shape="circle"
@@ -132,7 +135,7 @@ onUnmounted(() => {
</div>
<!-- 锁屏-OMC重启升级 -->
<div class="lock-screen_reload" v-if="lockedStore.lockType === 'reload'">
<div class="lock-screen_reload" v-if="lockedStore.type === 'reload'">
<LoadingOutlined style="font-size: 56px" />
<div class="text">
{{ t('components.LockScreen.backReload') }}

View File

@@ -11,7 +11,7 @@ export function getToken(): string {
/**设置cookis中Token字符串 */
export function setToken(token: string): void {
Cookies.set(TOKEN_COOKIE, token);
localSet(CACHE_LOCAL_LOCK, 'false');
localSet(CACHE_LOCAL_LOCK, 'none');
}
/**移除cookis中Token字符串,localStorage中锁屏字符串 */

View File

@@ -6,18 +6,15 @@ import { defineStore } from 'pinia';
/**锁屏信息类型 */
type Locked = {
/**锁定状态 */
isLocked: boolean;
/**锁屏类型 */
lockType: 'lock' | 'reload';
/**超时锁屏时间,秒*/
type: 'none' | 'lock' | 'reload' | string;
/**lock 超时锁屏时间,秒*/
lockTimeout: number;
};
const useLockedStore = defineStore('locked', {
state: (): Locked => ({
isLocked: localGet(CACHE_LOCAL_LOCK) === 'true',
lockType: 'lock',
type: localGet(CACHE_LOCAL_LOCK) || 'none',
lockTimeout: 0,
}),
getters: {},
@@ -26,7 +23,8 @@ const useLockedStore = defineStore('locked', {
async relaodWait() {
const res = await getSysConf();
if (res.code === RESULT_CODE_SUCCESS && res.data) {
this.fnLock('lock', false);
this.fnLock('none');
window.location.reload();
} else {
// 延迟5秒
setTimeout(() => {
@@ -35,10 +33,9 @@ const useLockedStore = defineStore('locked', {
}
},
// 设置锁定
async fnLock(type: 'lock' | 'reload', v: boolean) {
this.lockType = type;
this.isLocked = v;
localSet(CACHE_LOCAL_LOCK, `${v}`);
async fnLock(type: 'none' | 'lock' | 'reload') {
this.type = type;
localSet(CACHE_LOCAL_LOCK, type);
if (type === 'reload') {
// 延迟5秒
setTimeout(() => {

View File

@@ -296,10 +296,9 @@ function fnFileModalOk() {
.then(res => {
// OMC自升级
if (type === 'run' && from.neType.toLowerCase() === 'omc') {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS) {
fnFileModalCancel();
lockedStore.fnLock('reload', true);
lockedStore.fnLock('reload');
} else {
message.error({
content: `${fileModalState.title} ${res.msg}`,