Browse Source

添加系统模式,为急诊相关功能做准备

dengdx 2 months ago
parent
commit
a1f46ea458
4 changed files with 37 additions and 2 deletions
  1. 5 1
      src/API/interceptor.ts
  2. 1 1
      src/states/productSlice.ts
  3. 2 0
      src/states/store.ts
  4. 29 0
      src/states/systemModeSlice.ts

+ 5 - 1
src/API/interceptor.ts

@@ -1,6 +1,7 @@
 import axios from 'axios';
 import store from '../states/store';
 import { API_BASE_URL } from './config';
+import { SystemMode } from '../states/systemModeSlice';
 
 const axiosInstance = axios.create({
   baseURL: API_BASE_URL,
@@ -9,7 +10,10 @@ const axiosInstance = axios.create({
 axiosInstance.interceptors.request.use(
   (config) => {
     const state = store.getState();
-    const token = state.userInfo.token;
+    const token =
+      state.systemMode.mode === SystemMode.Emergency
+        ? state.product.guest
+        : state.userInfo.token;
     const { productName, language, source } = state.product;
 
     config.headers.Authorization = `Bearer ${token}`;

+ 1 - 1
src/states/productSlice.ts

@@ -5,7 +5,7 @@ interface ProductState {
   productName: 'DROS' | 'VETDROS';
   language: string;
   source: 'Electron' | 'Browser' | 'Android';
-  guest: string;
+  guest: string; //本质是token,只用于急诊情况
 }
 
 const initialState: ProductState = {

+ 2 - 0
src/states/store.ts

@@ -6,6 +6,7 @@ import bodyPartReducer from './bodyPartSlice';
 import selectionReducer from './patient/register/SelectionTypeSlice';
 import productReducer from './productSlice';
 import BusinessFlowReducer from './BusinessFlowSlice';
+import systemModeReducer from './systemModeSlice';
 import {
   workEntitiesSlice,
   workFiltersSlice,
@@ -23,6 +24,7 @@ const store = configureStore({
     selection: selectionReducer,
     product: productReducer,
     BusinessFlow: BusinessFlowReducer,
+    systemMode: systemModeReducer,
     workEntities: workEntitiesSlice.reducer,
     workFilters: workFiltersSlice.reducer,
     workPagination: workPaginationSlice.reducer,

+ 29 - 0
src/states/systemModeSlice.ts

@@ -0,0 +1,29 @@
+import { createSlice, PayloadAction } from '@reduxjs/toolkit';
+
+export const SystemMode = {
+  Emergency: 'Emergency',
+  Normal: 'Normal',
+} as const;
+
+export type SystemMode = (typeof SystemMode)[keyof typeof SystemMode];
+
+interface SystemModeState {
+  mode: SystemMode;
+}
+
+const initialState: SystemModeState = {
+  mode: 'Normal',
+};
+
+const systemModeSlice = createSlice({
+  name: 'systemMode',
+  initialState,
+  reducers: {
+    setSystemMode: (state, action: PayloadAction<SystemMode>) => {
+      state.mode = action.payload;
+    },
+  },
+});
+
+export const { setSystemMode } = systemModeSlice.actions;
+export default systemModeSlice.reducer;