Browse Source

实现从登录界面通过急诊进入检查

dengdx 2 months ago
parent
commit
e6aebce7a0

+ 3 - 3
src/domain/patient/handleEmergencyOperation.ts

@@ -24,7 +24,7 @@ const handleEmergencyOperation = async () => {
     }
 
     // Switch system mode back to normal
-    dispatch(setSystemMode(SystemMode.Normal));
+    // dispatch(setSystemMode(SystemMode.Normal));
 
     // Save registration result to cache
     const task = mapToTask(registrationResult.data);
@@ -33,11 +33,11 @@ const handleEmergencyOperation = async () => {
     // Step 3: Proceed to Examination
     dispatch(setBusinessFlow('exam'));
   } catch (error) {
-    dispatch(setSystemMode(SystemMode.Normal));
+    // dispatch(setSystemMode(SystemMode.Normal));
     console.error('Error in handleEmergencyOperation:', error);
     throw error;
   } finally {
-    dispatch(setSystemMode(SystemMode.Normal));
+    // dispatch(setSystemMode(SystemMode.Normal));
   }
 };
 

+ 1 - 7
src/pages/demo/App.tsx

@@ -1,29 +1,23 @@
 // App.tsx
 import React from 'react';
 import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
-import { useSelector } from 'react-redux';
 import BasicLayout from '../../layouts/BasicLayout';
 import HomePage from './HomePage';
 import AboutPage from './AboutPage';
 import Login from '@/pages/security/Login';
 import AppInitializer from './AppInitializer';
-import type { RootState } from '@/states/store';
 
 // 登录判断组件
 const AppContent: React.FC = () => {
-  const userInfo = useSelector((state: RootState) => state.userInfo);
   const [initialized, setInitialized] = React.useState(false);
 
-  if (!userInfo || userInfo.uid === 0) {
-    return <Login />;
-  }
-
   if (!initialized) {
     return <AppInitializer onInitialized={() => setInitialized(true)} />;
   }
 
   return (
     <Router>
+      <Login />
       <BasicLayout>
         <Routes>
           <Route path="/" element={<HomePage />} />

+ 16 - 0
src/pages/security/Login.tsx

@@ -1,14 +1,29 @@
 import React from 'react';
 import { Row, Col, Form, Input, Button, Card, message, Image } from 'antd';
+import { useSelector } from 'react-redux';
+import { RootState } from '../../states/store';
+import { SystemMode } from '../../states/systemModeSlice';
 import loginBrand from 'src/assets/imgs/login-brand.jpeg';
 import { useDispatch } from 'react-redux';
 import { login as loginApi } from '../../API/security/userActions';
 import { setUserInfo, type UserInfoState } from '../../states/user_info'; // 同时导入 setUserInfo 和类型 UserInfoState
 import handleEmergencyOperation from '../../domain/patient/handleEmergencyOperation';
+import { setSystemMode } from '../../states/systemModeSlice';
 
 const Login: React.FC = () => {
   const [form] = Form.useForm();
   const dispatch = useDispatch();
+  const systemMode = useSelector((state: RootState) => state.systemMode.mode);
+  const userInfo = useSelector((state: RootState) => state.userInfo);
+  console.log(`========${systemMode}`);
+
+  if (systemMode === SystemMode.Emergency) {
+    return null;
+  }
+  //非急诊,但已经登录,不显示login
+  if (systemMode === SystemMode.Normal && !!userInfo && userInfo.uid !== 0) {
+    return null;
+  }
 
   // 2. 登录请求函数
   const loginRequest = async (values: {
@@ -37,6 +52,7 @@ const Login: React.FC = () => {
         };
         // 5. 分发 redux action
         dispatch(setUserInfo(userInfo));
+        dispatch(setSystemMode(SystemMode.Normal));
         message.success('登录成功'); //todo 更详细的提示与异步过程
       } else {
         message.error(result.description || '登录失败');

+ 2 - 1
src/states/systemModeSlice.ts

@@ -1,6 +1,7 @@
 import { createSlice, PayloadAction } from '@reduxjs/toolkit';
 
 export const SystemMode = {
+  Unkonwn: 'Unknown',
   Emergency: 'Emergency',
   Normal: 'Normal',
 } as const;
@@ -12,7 +13,7 @@ interface SystemModeState {
 }
 
 const initialState: SystemModeState = {
-  mode: 'Normal',
+  mode: SystemMode.Unkonwn,
 };
 
 const systemModeSlice = createSlice({