Explorar o código

解决历史清单锁定时不立即显示的问题

sw hai 5 días
pai
achega
05c8140437

+ 9 - 3
src/pages/patient/components/ActionPanel.tsx

@@ -5,7 +5,7 @@ import {
   deleteWorkThunk,
   lockWorkInWorklistThunk,
 } from '@/states/patient/worklist/slices/workSlice';
-import { deleteWorkThunk as deleteWorkThunkFromHistory } from '@/states/patient/worklist/slices/history';
+import { deleteWorkThunk as deleteWorkThunkFromHistory, lockWorkInhistorylistThunk } from '@/states/patient/worklist/slices/history';
 import { switchToSendPanel } from '@/states/patient/worklist/slices/historyPanelSwitchSlice';
 import { FormattedMessage } from 'react-intl';
 import { AppDispatch, RootState, useAppSelector } from '@/states/store';
@@ -65,6 +65,12 @@ const ActionPanel: React.FC = () => {
       ? deleteWorkThunk
       : deleteWorkThunkFromHistory;
   };
+  const getLockThunk = () => {
+    return currentKey === 'worklist'
+      ? lockWorkInWorklistThunk
+      : lockWorkInhistorylistThunk;
+  };
+
   const getSelectedWorks = () => {
     const selectedIds = getSelectedWorkIds();
     if (currentKey === 'worklist') {
@@ -153,13 +159,13 @@ const ActionPanel: React.FC = () => {
     // 4. 根据当前状态切换
     const newLockState =
       selectedItem.StudyLock === 'Locked' ? 'Unlocked' : 'Locked';
-
+    const lockThunk = getLockThunk();
     // 为每个选中项执行锁定/解锁操作
     selectedIds.forEach((studyId) => {
       console.log(
         `锁定,触发action ,目标 studyid是 ${studyId},新状态是 ${newLockState}`
       );
-      dispatch(lockWorkInWorklistThunk({ studyId, lock: newLockState }));
+      dispatch(lockThunk({ studyId, lock: newLockState }));
     });
   };
 

+ 37 - 3
src/states/patient/worklist/slices/history.ts

@@ -3,9 +3,9 @@ import {
   createFetchThunk,
   createDeleteThunk,
 } from '../../../list_template/thunk.factory';
-import { work } from '../types/worklist';
+import { work, workAnimal } from '../types/worklist';
 import { WorkFilter } from '../types/workfilter';
-import { PayloadAction } from '@reduxjs/toolkit';
+import { createAsyncThunk, Draft, PayloadAction } from '@reduxjs/toolkit';
 import {
   setId,
   setName,
@@ -21,8 +21,10 @@ import {
 import {
   deleteStudies,
   fetchTaskList,
+  lockStudy,
 } from '../../../../API/patient/workActions';
 import store from '@/states/store';
+import { EntitiesState } from '@/states/list_template/type.model';
 
 export const fetchWorkThunk = createFetchThunk<WorkFilter, work>(
   'historylist',
@@ -91,6 +93,30 @@ const extraReducersForFilter = (builder) => {
     }
   );
 };
+
+// 锁定/解锁研究的 thunk
+export const lockWorkInhistorylistThunk = createAsyncThunk(
+  'historylist/lock',
+  async ({ studyId, lock }: { studyId: string; lock: 'Locked' | 'Unlocked' }) => {
+    console.log(`锁定,从thunk调用api,目标 studyid是 ${studyId},新状态是 ${lock}`);
+    const result = await lockStudy(studyId, lock);
+    return { studyId, lock, result };
+  }
+);
+// 创建锁定操作的 handlers
+const createLockHandlers = () => ({
+  fulfilled: (
+    state: Draft<EntitiesState<work | workAnimal>>,
+    action: PayloadAction<{ studyId: string; lock: 'Locked' | 'Unlocked'; result: any }>
+  ) => {
+    const { studyId, lock } = action.payload;
+    console.log(`锁定,thunk fulfilled,目标 studyid是 ${studyId},新状态是 ${lock}`);
+    const item = state.data.find((item) => item.StudyID === studyId);
+    if (item) {
+      item.StudyLock = lock;
+    }
+  },
+});
 // Create the worklist slices
 const {
   entitiesSlice,
@@ -113,9 +139,17 @@ const {
     status: 'Completed',
     page: 1,
     page_size: 10,
-  } satisfies WorkFilter
+  } satisfies WorkFilter,
+  {
+        lock: {
+          thunk: lockWorkInhistorylistThunk,
+          handlers: createLockHandlers(),
+        },
+  }
 );
 
+
+
 export const historyEntitiesSlice = entitiesSlice;
 export const historyFiltersSlice = filtersSlice;
 export const historyPaginationSlice = paginationSlice;