From cb5088115ad824b8c62ac298f7c2008c9db3259e Mon Sep 17 00:00:00 2001
From: Stev_Wang <304865932@qq.com>
Date: Sat, 27 Dec 2025 21:12:05 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E7=8E=A9=E5=AE=B6=E5=92=8C=E7=AE=A1=E7=90=86=E5=91=98=E7=99=BB?=
=?UTF-8?q?=E5=BD=95=E5=90=8E=E5=88=B7=E6=96=B0=E8=87=AA=E5=8A=A8=E9=80=80?=
=?UTF-8?q?=E5=87=BA=E7=9A=84bug=E4=BC=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend/src/components/AdminAuthRoute.tsx | 3 +-
frontend/src/components/AdminLayout.tsx | 5 +-
frontend/src/components/PlayerAuthRoute.tsx | 19 +++-
frontend/src/components/PlayerLayout.tsx | 82 +++++++++++------
frontend/src/main.tsx | 6 +-
frontend/src/pages/admin/AdminDashboard.tsx | 8 +-
frontend/src/pages/admin/AdminLogin.tsx | 7 +-
frontend/src/pages/player/PlayerDashboard.tsx | 53 ++++++-----
frontend/src/pages/player/PlayerLogin.tsx | 6 +-
frontend/src/stores/authStore.ts | 90 +++++++++++++++----
frontend/src/theme/index.ts | 2 +-
11 files changed, 195 insertions(+), 86 deletions(-)
diff --git a/frontend/src/components/AdminAuthRoute.tsx b/frontend/src/components/AdminAuthRoute.tsx
index 21d4b8e..3b3c9ed 100644
--- a/frontend/src/components/AdminAuthRoute.tsx
+++ b/frontend/src/components/AdminAuthRoute.tsx
@@ -3,8 +3,9 @@ import { useAuthStore } from '../stores/authStore';
const AdminAuthRoute = () => {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
+ const authType = useAuthStore((state) => state.authType);
- if (!isAuthenticated) {
+ if (!isAuthenticated || authType !== 'admin') {
return ;
}
diff --git a/frontend/src/components/AdminLayout.tsx b/frontend/src/components/AdminLayout.tsx
index 28ae72c..66013fc 100644
--- a/frontend/src/components/AdminLayout.tsx
+++ b/frontend/src/components/AdminLayout.tsx
@@ -1,5 +1,5 @@
import { useState } from 'react';
-import { Layout, Menu, Button, theme } from 'antd';
+import { Layout, Menu, Button, theme, App } from 'antd';
import {
MenuFoldOutlined,
MenuUnfoldOutlined,
@@ -10,7 +10,6 @@ import {
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import { useAuthStore } from '../stores/authStore';
import { adminAuthService } from '../services/adminAuthService';
-import { message } from 'antd';
const { Header, Sider, Content, Footer } = Layout;
@@ -23,11 +22,11 @@ const AdminLayout = () => {
const location = useLocation();
const adminUser = useAuthStore((state) => state.adminUser);
const logout = useAuthStore((state) => state.logout);
+ const { message } = App.useApp();
const handleLogout = async () => {
try {
await adminAuthService.logout();
- localStorage.removeItem('adminToken');
logout();
message.success('登出成功');
navigate('/admin/login');
diff --git a/frontend/src/components/PlayerAuthRoute.tsx b/frontend/src/components/PlayerAuthRoute.tsx
index 826b99b..807b957 100644
--- a/frontend/src/components/PlayerAuthRoute.tsx
+++ b/frontend/src/components/PlayerAuthRoute.tsx
@@ -3,8 +3,25 @@ import { useAuthStore } from '../stores/authStore';
const PlayerAuthRoute = () => {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
+ const authType = useAuthStore((state) => state.authType);
+ const setAuth = useAuthStore((state) => state.setAuth);
- if (!isAuthenticated) {
+ // 检查是否有playerToken
+ const playerToken = localStorage.getItem('playerToken');
+ const playerUserStr = localStorage.getItem('playerUser');
+
+ // 如果有playerToken但authType不是player,说明需要重新加载玩家认证
+ if (playerToken && playerUserStr && authType !== 'player') {
+ try {
+ const playerUser = JSON.parse(playerUserStr);
+ setAuth(playerUser, playerToken, 'player');
+ } catch (e) {
+ console.error('解析playerUser失败:', e);
+ }
+ }
+
+ // 如果没有playerToken,重定向到登录页
+ if (!playerToken) {
return ;
}
diff --git a/frontend/src/components/PlayerLayout.tsx b/frontend/src/components/PlayerLayout.tsx
index 3155a3d..a0d6f44 100644
--- a/frontend/src/components/PlayerLayout.tsx
+++ b/frontend/src/components/PlayerLayout.tsx
@@ -1,4 +1,4 @@
-import { Layout, Menu, Button, Dropdown, theme } from 'antd';
+import { Layout, Menu, Button, Dropdown, theme, App } from 'antd';
import {
HomeOutlined,
UserOutlined,
@@ -6,7 +6,6 @@ import {
DownOutlined,
} from '@ant-design/icons';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
-import { message } from 'antd';
import { playerAuthService } from '../services/playerAuthService';
const { Header, Content, Footer } = Layout;
@@ -17,11 +16,11 @@ const PlayerLayout = () => {
} = theme.useToken();
const navigate = useNavigate();
const location = useLocation();
+ const { message } = App.useApp();
const handleLogout = async () => {
try {
await playerAuthService.logout();
- localStorage.removeItem('playerToken');
message.success('登出成功');
navigate('/player/login');
} catch (error) {
@@ -57,40 +56,67 @@ const PlayerLayout = () => {
style={{
display: 'flex',
alignItems: 'center',
- justifyContent: 'space-between',
- background: colorBgLayout,
- padding: '0 24px',
+ justifyContent: 'center',
+ background: '#001529',
+ padding: '0',
+ height: 64,
}}
>
+ {/* 导航条内容容器 */}
- 梦幻西游玩家服务中心
-
-