|
|
|
@ -3004,18 +3004,23 @@ __webpack_require__.r(__webpack_exports__);
@@ -3004,18 +3004,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
// 登录状态
|
|
|
|
|
const isLoggedIn = (0,vue__WEBPACK_IMPORTED_MODULE_0__.ref)(false) |
|
|
|
|
|
|
|
|
|
// 应用设置
|
|
|
|
|
const appSettings = (0,vue__WEBPACK_IMPORTED_MODULE_0__.reactive)({ |
|
|
|
|
appName: 'GoFaster' |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// Toast 配置
|
|
|
|
|
const toastConfig = (0,vue__WEBPACK_IMPORTED_MODULE_0__.reactive)({ |
|
|
|
|
type: 'info', |
|
|
|
|
title: '', |
|
|
|
|
content: '', |
|
|
|
|
duration: 3000 |
|
|
|
|
}) |
|
|
|
|
// 应用设置
|
|
|
|
|
const appSettings = (0,vue__WEBPACK_IMPORTED_MODULE_0__.reactive)({ |
|
|
|
|
appName: 'GoFaster' |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// Toast 配置
|
|
|
|
|
const toastConfig = (0,vue__WEBPACK_IMPORTED_MODULE_0__.reactive)({ |
|
|
|
|
type: 'info', |
|
|
|
|
title: '', |
|
|
|
|
content: '', |
|
|
|
|
duration: 3000 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 会话超时相关
|
|
|
|
|
let sessionTimeoutTimer = null |
|
|
|
|
let lastActivityTime = Date.now() |
|
|
|
|
const sessionTimeoutMinutes = (0,vue__WEBPACK_IMPORTED_MODULE_0__.ref)(30) // 默认30分钟
|
|
|
|
|
|
|
|
|
|
const messages = (0,vue__WEBPACK_IMPORTED_MODULE_0__.ref)([ |
|
|
|
|
{ |
|
|
|
@ -3352,6 +3357,12 @@ __webpack_require__.r(__webpack_exports__);
@@ -3352,6 +3357,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
const userName = currentUser.name || userData.username || '用户' |
|
|
|
|
showToastMessage('success', '登录成功', `欢迎回来,${userName}!`) |
|
|
|
|
|
|
|
|
|
// 启动会话超时检测
|
|
|
|
|
startSessionTimeoutCheck() |
|
|
|
|
|
|
|
|
|
// 更新用户活动时间
|
|
|
|
|
updateUserActivity() |
|
|
|
|
|
|
|
|
|
// 跳转到首页
|
|
|
|
|
router.push('/') |
|
|
|
|
} |
|
|
|
@ -3427,6 +3438,139 @@ __webpack_require__.r(__webpack_exports__);
@@ -3427,6 +3438,139 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
toastConfig.duration = duration |
|
|
|
|
showToast.value = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新用户活动时间
|
|
|
|
|
const updateUserActivity = () => { |
|
|
|
|
lastActivityTime = Date.now() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 启动会话超时检测
|
|
|
|
|
const startSessionTimeoutCheck = () => { |
|
|
|
|
// 清除之前的定时器
|
|
|
|
|
if (sessionTimeoutTimer) { |
|
|
|
|
clearInterval(sessionTimeoutTimer) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取用户设置的会话超时时间
|
|
|
|
|
try { |
|
|
|
|
const userSettings = localStorage.getItem('gofaster-settings') |
|
|
|
|
if (userSettings) { |
|
|
|
|
const settings = JSON.parse(userSettings) |
|
|
|
|
if (settings.sessionTimeout) { |
|
|
|
|
sessionTimeoutMinutes.value = settings.sessionTimeout |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error('获取会话超时设置失败:', error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 每分钟检查一次会话状态
|
|
|
|
|
sessionTimeoutTimer = setInterval(() => { |
|
|
|
|
const currentTime = Date.now() |
|
|
|
|
const inactiveTime = (currentTime - lastActivityTime) / 1000 / 60 // 转换为分钟
|
|
|
|
|
|
|
|
|
|
if (inactiveTime >= sessionTimeoutMinutes.value) { |
|
|
|
|
console.log('会话超时,自动退出登录') |
|
|
|
|
showToastMessage('warning', '会话超时', '您的会话已超时,将自动退出登录') |
|
|
|
|
|
|
|
|
|
// 延迟2秒后执行退出登录,让用户看到提示
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
logout() |
|
|
|
|
}, 2000) |
|
|
|
|
} |
|
|
|
|
}, 60000) // 每分钟检查一次
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 停止会话超时检测
|
|
|
|
|
const stopSessionTimeoutCheck = () => { |
|
|
|
|
if (sessionTimeoutTimer) { |
|
|
|
|
clearInterval(sessionTimeoutTimer) |
|
|
|
|
sessionTimeoutTimer = null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理应用关闭事件
|
|
|
|
|
const handleAppWillClose = () => { |
|
|
|
|
if (isLoggedIn.value) { |
|
|
|
|
// 同步执行退出登录,不等待异步操作
|
|
|
|
|
try { |
|
|
|
|
const token = localStorage.getItem('token') |
|
|
|
|
|
|
|
|
|
if (token) { |
|
|
|
|
// 这里可以发送一个同步的退出登录请求,但考虑到应用即将关闭,主要是清除本地状态
|
|
|
|
|
_services_userService__WEBPACK_IMPORTED_MODULE_3__.userService.logout(token).catch(error => { |
|
|
|
|
console.error('应用关闭时调用登出接口失败:', error) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error('应用关闭时退出登录失败:', error) |
|
|
|
|
} finally { |
|
|
|
|
// 清除本地状态
|
|
|
|
|
localStorage.removeItem('user') |
|
|
|
|
localStorage.removeItem('isLoggedIn') |
|
|
|
|
localStorage.removeItem('token') |
|
|
|
|
|
|
|
|
|
// 清除用户对象状态
|
|
|
|
|
currentUser.id = null |
|
|
|
|
currentUser.name = '' |
|
|
|
|
currentUser.email = '' |
|
|
|
|
currentUser.avatar = null |
|
|
|
|
currentUser.role = '' |
|
|
|
|
currentUser.lastLogin = null |
|
|
|
|
currentUser.lastLoginIP = '' |
|
|
|
|
currentUser.status = 1 |
|
|
|
|
currentUser.roles = [] |
|
|
|
|
|
|
|
|
|
// 更新登录状态
|
|
|
|
|
isLoggedIn.value = false |
|
|
|
|
|
|
|
|
|
// 停止会话超时检测
|
|
|
|
|
stopSessionTimeoutCheck() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 自动退出登录(不显示提示)
|
|
|
|
|
const autoLogout = async () => { |
|
|
|
|
try { |
|
|
|
|
// 获取当前token
|
|
|
|
|
const token = localStorage.getItem('token') |
|
|
|
|
if (token) { |
|
|
|
|
// 调用后端登出接口
|
|
|
|
|
await _services_userService__WEBPACK_IMPORTED_MODULE_3__.userService.logout(token) |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error('调用登出接口失败:', error) |
|
|
|
|
} finally { |
|
|
|
|
// 清除用户信息
|
|
|
|
|
currentUser.id = null |
|
|
|
|
currentUser.name = '' |
|
|
|
|
currentUser.email = '' |
|
|
|
|
currentUser.avatar = null |
|
|
|
|
currentUser.role = '' |
|
|
|
|
currentUser.lastLogin = null |
|
|
|
|
currentUser.lastLoginIP = '' |
|
|
|
|
currentUser.status = 1 |
|
|
|
|
currentUser.roles = [] |
|
|
|
|
isLoggedIn.value = false |
|
|
|
|
|
|
|
|
|
// 清除本地存储
|
|
|
|
|
localStorage.removeItem('user') |
|
|
|
|
localStorage.removeItem('isLoggedIn') |
|
|
|
|
localStorage.removeItem('token') |
|
|
|
|
|
|
|
|
|
// 关闭用户菜单
|
|
|
|
|
showUserMenu.value = false |
|
|
|
|
|
|
|
|
|
// 触发全局事件,通知其他组件用户已登出
|
|
|
|
|
window.dispatchEvent(new CustomEvent('user-logout', {
|
|
|
|
|
detail: { user: currentUser }
|
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
// 跳转到首页
|
|
|
|
|
router.push('/') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const logout = async () => { |
|
|
|
|
try { |
|
|
|
@ -3440,7 +3584,10 @@ __webpack_require__.r(__webpack_exports__);
@@ -3440,7 +3584,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
console.error('调用登出接口失败:', error) |
|
|
|
|
// 即使后端调用失败,也要清除本地状态
|
|
|
|
|
} finally { |
|
|
|
|
// 清除用户信息
|
|
|
|
|
// 停止会话超时检测
|
|
|
|
|
stopSessionTimeoutCheck() |
|
|
|
|
|
|
|
|
|
// 清除用户信息
|
|
|
|
|
currentUser.id = null |
|
|
|
|
currentUser.name = '' |
|
|
|
|
currentUser.email = '' |
|
|
|
@ -3530,14 +3677,39 @@ __webpack_require__.r(__webpack_exports__);
@@ -3530,14 +3677,39 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
// 初始化收藏菜单
|
|
|
|
|
updateFavoriteMenu() |
|
|
|
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
const savedIsLoggedIn = localStorage.getItem('isLoggedIn') |
|
|
|
|
const savedUser = localStorage.getItem('user') |
|
|
|
|
|
|
|
|
|
if (savedIsLoggedIn === 'true' && savedUser) { |
|
|
|
|
try { |
|
|
|
|
const userData = JSON.parse(savedUser) |
|
|
|
|
console.log('从localStorage恢复的用户数据:', userData) |
|
|
|
|
// 添加用户活动监听器
|
|
|
|
|
const userActivityEvents = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'] |
|
|
|
|
userActivityEvents.forEach(event => { |
|
|
|
|
document.addEventListener(event, updateUserActivity, { passive: true }) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 监听应用关闭事件
|
|
|
|
|
if (window.electronAPI && window.electronAPI.onAppWillClose) { |
|
|
|
|
window.electronAPI.onAppWillClose(handleAppWillClose) |
|
|
|
|
} else { |
|
|
|
|
// 兼容性处理:如果electronAPI不可用,使用备用方案
|
|
|
|
|
console.warn('electronAPI不可用,无法注册应用关闭事件监听器') |
|
|
|
|
// 可以在这里添加其他备用方案,比如使用localStorage或其他方式
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 添加页面卸载事件监听器作为备用方案
|
|
|
|
|
window.addEventListener('beforeunload', () => { |
|
|
|
|
if (isLoggedIn.value) { |
|
|
|
|
// 同步清除本地状态
|
|
|
|
|
localStorage.removeItem('user') |
|
|
|
|
localStorage.removeItem('isLoggedIn') |
|
|
|
|
localStorage.removeItem('token') |
|
|
|
|
stopSessionTimeoutCheck() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
const savedIsLoggedIn = localStorage.getItem('isLoggedIn') |
|
|
|
|
const savedUser = localStorage.getItem('user') |
|
|
|
|
|
|
|
|
|
if (savedIsLoggedIn === 'true' && savedUser) { |
|
|
|
|
try { |
|
|
|
|
const userData = JSON.parse(savedUser) |
|
|
|
|
|
|
|
|
|
// 先设置默认值,然后用localStorage的数据覆盖
|
|
|
|
|
const defaultUser = { |
|
|
|
@ -3568,7 +3740,6 @@ __webpack_require__.r(__webpack_exports__);
@@ -3568,7 +3740,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
Object.assign(currentUser, defaultUser, mappedUserData) |
|
|
|
|
|
|
|
|
|
isLoggedIn.value = true |
|
|
|
|
console.log('恢复后的用户信息:', currentUser) |
|
|
|
|
} catch (error) { |
|
|
|
|
console.warn('解析用户信息失败:', error) |
|
|
|
|
// 清除无效的用户信息
|
|
|
|
@ -3607,6 +3778,15 @@ __webpack_require__.r(__webpack_exports__);
@@ -3607,6 +3778,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
// 组件卸载时清理事件监听器
|
|
|
|
|
;(0,vue__WEBPACK_IMPORTED_MODULE_0__.onUnmounted)(() => { |
|
|
|
|
document.removeEventListener('click', handleGlobalClick) |
|
|
|
|
|
|
|
|
|
// 移除用户活动监听器
|
|
|
|
|
const userActivityEvents = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'] |
|
|
|
|
userActivityEvents.forEach(event => { |
|
|
|
|
document.removeEventListener(event, updateUserActivity) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 停止会话超时检测
|
|
|
|
|
stopSessionTimeoutCheck() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 提供响应式数据给子组件
|
|
|
|
@ -3614,11 +3794,7 @@ __webpack_require__.r(__webpack_exports__);
@@ -3614,11 +3794,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
;(0,vue__WEBPACK_IMPORTED_MODULE_0__.provide)('currentUser', safeCurrentUser) |
|
|
|
|
;(0,vue__WEBPACK_IMPORTED_MODULE_0__.provide)('showLoginModal', showLoginModal) |
|
|
|
|
|
|
|
|
|
// 添加调试信息
|
|
|
|
|
console.log('MainLayout setup completed') |
|
|
|
|
console.log('isLoggedIn:', isLoggedIn) |
|
|
|
|
console.log('safeCurrentUser:', safeCurrentUser) |
|
|
|
|
console.log('showLoginModal:', showLoginModal) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
showMessagePanel, |
|
|
|
@ -4637,7 +4813,6 @@ __webpack_require__.r(__webpack_exports__);
@@ -4637,7 +4813,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
this.$router.push('/history'); |
|
|
|
|
}, |
|
|
|
|
openSettings() { |
|
|
|
|
console.log('打开用户设置'); |
|
|
|
|
|
|
|
|
|
// 通过事件通知父组件添加标签页
|
|
|
|
|
this.$emit('add-tab', { |
|
|
|
@ -4726,39 +4901,31 @@ __webpack_require__.r(__webpack_exports__);
@@ -4726,39 +4901,31 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
|
|
|
|
|
// 监听登录状态变化 - 使用计算属性确保响应式
|
|
|
|
|
this.$watch('computedIsLoggedIn', (newVal) => { |
|
|
|
|
console.log('Home.vue - 登录状态变化:', newVal); |
|
|
|
|
if (newVal && this.computedCurrentUser) { |
|
|
|
|
console.log('Home.vue - 当前用户信息:', this.computedCurrentUser); |
|
|
|
|
this.userInfo.name = this.computedCurrentUser.name || this.userInfo.name; |
|
|
|
|
this.userInfo.email = this.computedCurrentUser.email || this.userInfo.email; |
|
|
|
|
console.log('Home.vue - 更新后的用户信息:', this.userInfo); |
|
|
|
|
} |
|
|
|
|
}, { immediate: true }); |
|
|
|
|
|
|
|
|
|
// 监听用户信息变化 - 使用计算属性确保响应式
|
|
|
|
|
this.$watch('computedCurrentUser', (newUser) => { |
|
|
|
|
console.log('Home.vue - 用户信息变化:', newUser); |
|
|
|
|
if (newUser && newUser.name) { |
|
|
|
|
this.userInfo.name = newUser.name; |
|
|
|
|
this.userInfo.email = newUser.email || this.userInfo.email; |
|
|
|
|
console.log('Home.vue - 用户信息更新后:', this.userInfo); |
|
|
|
|
} |
|
|
|
|
}, { immediate: true, deep: true }); |
|
|
|
|
|
|
|
|
|
// 监听全局登录成功事件
|
|
|
|
|
window.addEventListener('user-login-success', (event) => { |
|
|
|
|
console.log('Home.vue - 收到登录成功事件:', event.detail); |
|
|
|
|
const { user } = event.detail; |
|
|
|
|
if (user) { |
|
|
|
|
this.userInfo.name = user.name || this.userInfo.name; |
|
|
|
|
this.userInfo.email = user.email || this.userInfo.email; |
|
|
|
|
console.log('Home.vue - 事件更新后的用户信息:', this.userInfo); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 监听全局登出事件
|
|
|
|
|
window.addEventListener('user-logout', () => { |
|
|
|
|
console.log('Home.vue - 收到登出事件'); |
|
|
|
|
this.userInfo.name = '用户'; |
|
|
|
|
this.userInfo.email = 'user@example.com'; |
|
|
|
|
}); |
|
|
|
@ -8856,7 +9023,7 @@ __webpack_require__.r(__webpack_exports__);
@@ -8856,7 +9023,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
|
|
/******/
|
|
|
|
|
/******/ /* webpack/runtime/getFullHash */ |
|
|
|
|
/******/ (() => { |
|
|
|
|
/******/ __webpack_require__.h = () => ("861ac4d425d88faa") |
|
|
|
|
/******/ __webpack_require__.h = () => ("4a166f955d2fe42e") |
|
|
|
|
/******/ })(); |
|
|
|
|
/******/
|
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
|
|
|