优化退出错误代码提示
This commit is contained in:
53
src/App.vue
53
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) }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user