Commit 849d0456 by 高源

登录权限优化

parent b094eedf
No preview for this file type
<!doctype html>
<html lang="zh-cmn-Hans">
<head>
<meta name="buildTime" content="2024-12-10 17:34:19">
<meta name="buildTime" content="2025-02-06 10:11:28">
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<title>VueDashboard</title>
<script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-BMlV-6Dx.js"></script>
<script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-DpYjMZ_w.js"></script>
<link rel="stylesheet" crossorigin href="/Content/VueDashboardUi/VueDashboard1/assets/index-9k_B1ZU8.css">
</head>
<body>
......
......@@ -2,7 +2,7 @@ import { createApp } from 'vue';
import './plugins/assets';
import { localStg } from '@/utils/storage';
// main.js or main.ts
import 'font-awesome/css/font-awesome.css'; // 导入所有的 Font Awesome 样式
import 'font-awesome/css/font-awesome.css';
import { setupDayjs, setupIconifyOffline, setupLoading, setupNProgress } from './plugins';
import { setupStore } from './store';
import { setupRouter } from './router';
......@@ -10,18 +10,29 @@ import { setupI18n } from './locales';
import App from './App.vue';
let timeoutHandle: string | number | NodeJS.Timeout | undefined;
const INACTIVITY_TIMEOUT = 20 * 60 * 1000;
function handleLogout(app: any) {
localStg.remove('token');
localStg.remove('refreshToken');
localStg.remove('userInfo');
app.config.globalProperties.$router.push('/login/pwd-login');
}
function checkLastActivity(app: any) {
const lastActivity = localStorage.getItem('lastActivityTime');
if (lastActivity) {
const timeDiff = Date.now() - Number.parseInt(lastActivity, 10);
if (timeDiff > INACTIVITY_TIMEOUT) {
handleLogout(app);
}
}
}
function startInactivityTimer(app: any) {
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout(
() => {
localStg.remove('token');
localStg.remove('refreshToken');
localStg.remove('userInfo');
app.config.globalProperties.$router.push('/login/pwd-login');
},
29 * 60 * 1000
); // 30分钟 = 30 * 60 * 1000 毫秒
localStorage.setItem('lastActivityTime', Date.now().toString());
timeoutHandle = setTimeout(() => handleLogout(app), INACTIVITY_TIMEOUT);
}
function resetInactivityTimer(app: any) {
......@@ -30,22 +41,17 @@ function resetInactivityTimer(app: any) {
async function setupApp() {
setupLoading();
setupNProgress();
setupIconifyOffline();
setupDayjs();
const app = createApp(App);
setupStore(app);
await setupRouter(app);
setupI18n(app);
// 系统更新提示
// setupAppVersionNotification();
// 检查上次活动时间
checkLastActivity(app);
// 监听用户的操作
window.addEventListener('mousemove', () => resetInactivityTimer(app));
......@@ -59,6 +65,11 @@ async function setupApp() {
app.mount('#app');
}
// 页面卸载时保存最后活动时间
window.addEventListener('beforeunload', () => {
localStorage.setItem('lastActivityTime', Date.now().toString());
});
setTimeout(() => {
setupApp();
}, 200);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment