From 5e2da72d882b39c45fb70a12e53aab3e9a12c93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E5=A4=8D=E4=B9=A0?= <2353956224@qq.com> Date: Wed, 8 Apr 2026 13:08:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BB=A3=E7=A0=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 53 ++++++++++++++++++----- src/components/pk-mini/mine/PKmessage.vue | 7 +-- src/utils/axios.js | 12 ++++- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8af34a5..b13de97 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,6 +38,7 @@ import WorkbenchLayout from './layout/WorkbenchLayout.vue' import UpdateNotification from './components/UpdateNotification.vue' import NoticeBar from './components/NoticeBar.vue' import { useNoticeStore } from './stores/noticeStore' +import { ElMessage } from 'element-plus' // Constants const USER_KEY = 'user_data' @@ -128,6 +129,8 @@ onMounted(() => { // 监听账号组配置更新事件 window.addEventListener('config-updated', handleConfigUpdate) + window.addEventListener('auth-expired', handleAuthExpired) + loadConfig() // Health Check @@ -138,6 +141,7 @@ onUnmounted(() => { window.removeEventListener('beforeunload', handleBeforeUnload) window.removeEventListener('storage', handleStorageChange) window.removeEventListener('config-updated', handleConfigUpdate) + window.removeEventListener('auth-expired', handleAuthExpired) stopHealthCheck() }) @@ -152,6 +156,12 @@ const handleStorageChange = (e) => { } } +const clearLoginState = () => { + localStorage.removeItem(USER_KEY) + localStorage.removeItem('user') + localStorage.removeItem('token') +} + // 处理配置更新事件 const handleConfigUpdate = () => { console.log('[App] 收到配置更新事件,重新加载配置') @@ -160,22 +170,45 @@ const handleConfigUpdate = () => { let healthCheckInterval = null +const resetToLogin = async (message) => { + if (message) { + ElMessage.error(message) + } + + stopHealthCheck() + clearLoginState() + currentPage.value = 'login' + + if (isElectron()) { + try { + await window.electronAPI.hideViews() + await handleStopAll() + } catch (e) { + console.warn('[App] 娓呯悊瑙嗗浘澶辫触:', e) + } + } + +} + +const handleAuthExpired = async (event) => { + await resetToLogin(event?.detail?.message) +} + const startHealthCheck = () => { const check = async () => { if (currentPage.value === 'login' || !isElectron()) return try { const result = await window.electronAPI.checkHealth() if (result.success && result.code === 40400) { - alert(result.message) - localStorage.removeItem(USER_KEY) + await resetToLogin(result.message); return // 隐藏所有 BrowserView 并停止自动化,防止视图悬浮在登录页上方 - try { - await window.electronAPI.hideViews() - await handleStopAll() - } catch (e) { - console.warn('[App] 清理视图失败:', e) - } - currentPage.value = 'login' + // try { + // await window.electronAPI.hideViews() + // await handleStopAll() + // } catch (e) { + // console.warn('[App] 清理视图失败:', e) + // } + // currentPage.value = 'login' } } catch (error) { console.error('[App] 健康检查失败:', error) @@ -237,7 +270,7 @@ const handleGoToConfig = async () => { const handleLogout = async () => { stopHealthCheck() currentPage.value = 'login' - localStorage.removeItem(USER_KEY) + clearLoginState() if (isElectron()) { try { await window.electronAPI.logout() } catch (e) { console.warn('[App] logout失败:', e) } diff --git a/src/components/pk-mini/mine/PKmessage.vue b/src/components/pk-mini/mine/PKmessage.vue index 0389e45..1b10e50 100644 --- a/src/components/pk-mini/mine/PKmessage.vue +++ b/src/components/pk-mini/mine/PKmessage.vue @@ -208,16 +208,16 @@ const formatTime = TimestamptolocalTime function formatBeijingTime(timestamp) { // 创建一个UTC时间的Date对象 const utcDate = new Date(timestamp) - + // 将UTC时间转换为北京时间(UTC+8) const beijingDate = new Date(utcDate.getTime() + 8 * 60 * 60 * 1000) - + const year = beijingDate.getUTCFullYear() const month = String(beijingDate.getUTCMonth() + 1).padStart(2, '0') const day = String(beijingDate.getUTCDate()).padStart(2, '0') const hours = String(beijingDate.getUTCHours()).padStart(2, '0') const minutes = String(beijingDate.getUTCMinutes()).padStart(2, '0') - + return `${year}/${month}/${day} ${hours}:${minutes}` } @@ -362,6 +362,7 @@ async function handleSubmit() { } if (formData.value.pkTime < Date.now()) { ElMessage.error('PK时间不能早于当前时间') + console.log(formData.value.pkTime) return } if (!formData.value.country) { diff --git a/src/utils/axios.js b/src/utils/axios.js index 643b163..8640bcd 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -4,7 +4,6 @@ */ import axios from 'axios' import { getToken } from '@/utils/storage' -import router from '@/router' import { ElMessage } from 'element-plus'; import { usePythonBridge, } from '@/utils/pythonBridge' @@ -16,6 +15,13 @@ const { stopScript } = usePythonBridge(); // 请求地址前缀 const baseURL = ENV.API_BASE_URL +function emitAuthExpired(code, message) { + + window.dispatchEvent(new CustomEvent('auth-expired', { + detail: { code, message } + })) +} + // 请求拦截器 axios.interceptors.request.use((config) => { // console.log("config", config) @@ -43,10 +49,12 @@ axios.interceptors.response.use((response) => { return response.data.data } else if (response.data.code == 40400) { stopScript(); - router.push('/') + emitAuthExpired(response.data.code, response.data.message) ElMessage.error(response.data.code + '' + response.data.message); + return Promise.reject(response.data) } else { ElMessage.error(response.data.code + '' + response.data.message); + return Promise.reject(response.data) } }, (error) => {