以急诊身份登录系统后,点击退出按钮注销账号时,系统出现黑屏。
在 src/domain/patient/handleEmergencyOperation.ts 中,急诊登录时会设置两个关键状态:
// Step 2: Set system mode to Emergency
dispatch(setSystemMode(SystemMode.Emergency));
// Step 3: Set temporary user info with guest token
dispatch(setUserInfo({
token: guestToken,
expire: Date.now() + 24 * 60 * 60 * 1000,
uid: -1, // Special uid to identify emergency mode
name: 'Emergency User',
avatar: '',
}));
在 src/components/ExitModal.tsx 的注销逻辑中,只清除了用户信息:
case 'logout':
actionName = '注销用户';
dispatch(clearUserInfo()); // ← 只清除了用户信息
message.success('已退出登录');
onClose();
return;
关键问题:systemMode 仍然保持为 Emergency,没有被重置!
注销操作
↓
clearUserInfo()
↓
src/pages/index/index.tsx 检测到 !loggedIn
↓
返回 <Login />
↓
Login.tsx 检测到 systemMode === SystemMode.Emergency
↓
返回 null(第 37-39 行)
↓
黑屏!
在 src/pages/security/Login.tsx 第 37-39 行:
if (systemMode === SystemMode.Emergency) {
return null; // ← 这里导致黑屏
}
这个逻辑是为了在急诊模式下隐藏登录页面,因为急诊模式不需要显示登录界面。但当注销后,如果 systemMode 没有重置,就会导致登录页面无法显示。
在 src/components/ExitModal.tsx 中:
导入必要的依赖:
import { setSystemMode } from '../states/systemModeSlice';
import { SystemMode } from '../states/systemModeSlice';
typescript
case 'logout':
actionName = '注销用户';
dispatch(clearUserInfo());
dispatch(setSystemMode(SystemMode.Normal)); // ← 添加这一行
message.success('已退出登录');
onClose();
return;
注销操作
↓
clearUserInfo() + setSystemMode(SystemMode.Normal)
↓
src/pages/index/index.tsx 检测到 !loggedIn
↓
返回 <Login />
↓
Login.tsx 检测到 systemMode === SystemMode.Normal
↓
正常显示登录界面
✓
修改前:
import { clearUserInfo } from '../states/user_info';
// ...
case 'logout':
actionName = '注销用户';
dispatch(clearUserInfo());
message.success('已退出登录');
onClose();
return;
修改后:
import { clearUserInfo } from '../states/user_info';
import { setSystemMode, SystemMode } from '../states/systemModeSlice';
// ...
case 'logout':
actionName = '注销用户';
dispatch(clearUserInfo());
dispatch(setSystemMode(SystemMode.Normal)); // 重置系统模式
message.success('已退出登录');
onClose();
return;
注销后应确保:
userInfo.token = ''userInfo.uid = 0systemMode = 'Normal'loggedIn = falsesrc/components/ExitModal.tsx此修复只影响注销逻辑,不影响:
系统模式重置的必要性:
与已有注销功能的兼容性:
添加 Cypress 测试:
错误处理增强:
状态管理优化: