|
@@ -1,15 +1,20 @@
|
|
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
import emitter from '../utils/eventEmitter';
|
|
import emitter from '../utils/eventEmitter';
|
|
|
import store from './store';
|
|
import store from './store';
|
|
|
|
|
+import { MqttMessage } from '../domain/mqttService';
|
|
|
|
|
|
|
|
export interface BusinessFlowState {
|
|
export interface BusinessFlowState {
|
|
|
currentKey: string;
|
|
currentKey: string;
|
|
|
lastKey?: string; // Optional
|
|
lastKey?: string; // Optional
|
|
|
|
|
+ shouldKeepSelection?: boolean; // 🆕 标记是否应该保持选中的体位
|
|
|
|
|
+ keptSelectionSopUid?: string; // 🆕 要保持选中的体位SOP UID
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const initialState: BusinessFlowState = {
|
|
const initialState: BusinessFlowState = {
|
|
|
currentKey: 'register',
|
|
currentKey: 'register',
|
|
|
lastKey: '',
|
|
lastKey: '',
|
|
|
|
|
+ shouldKeepSelection: false,
|
|
|
|
|
+ keptSelectionSopUid: undefined,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const BusinessFlowSlice = createSlice({
|
|
const BusinessFlowSlice = createSlice({
|
|
@@ -18,16 +23,53 @@ const BusinessFlowSlice = createSlice({
|
|
|
reducers: {
|
|
reducers: {
|
|
|
setBusinessFlow: (state, action: PayloadAction<string>) => {
|
|
setBusinessFlow: (state, action: PayloadAction<string>) => {
|
|
|
const lastKey = state.currentKey; // Save the last key before changing
|
|
const lastKey = state.currentKey; // Save the last key before changing
|
|
|
- //state={lastKey:lastKey,currentKey:action.payload}; // Update state with new key and last key
|
|
|
|
|
-
|
|
|
|
|
- return { lastKey: lastKey, currentKey: action.payload };
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 🆕 只在 exam->process 的流程切换时保持标记(TASK_SUCCESS 场景)
|
|
|
|
|
+ const isExamToProcess = lastKey === 'exam' && action.payload === 'process';
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...state,
|
|
|
|
|
+ lastKey: lastKey,
|
|
|
|
|
+ currentKey: action.payload,
|
|
|
|
|
+ // 🆕 exam->process 时保持标记,其他情况清除
|
|
|
|
|
+ shouldKeepSelection: isExamToProcess ? state.shouldKeepSelection : false,
|
|
|
|
|
+ keptSelectionSopUid: isExamToProcess ? state.keptSelectionSopUid : undefined,
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
+ setKeepSelection: (state, action: PayloadAction<{ sopUid: string }>) => {
|
|
|
|
|
+ state.shouldKeepSelection = true;
|
|
|
|
|
+ state.keptSelectionSopUid = action.payload.sopUid;
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `[BusinessFlowSlice] setKeepSelection: ${action.payload.sopUid}`
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ clearKeepSelection: (state) => {
|
|
|
|
|
+ state.shouldKeepSelection = false;
|
|
|
|
|
+ state.keptSelectionSopUid = undefined;
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-emitter.on('TASK_SUCCESS', () => {
|
|
|
|
|
|
|
+emitter.on('TASK_SUCCESS', (message: MqttMessage) => {
|
|
|
|
|
+ console.log('[BusinessFlowSlice] TASK_SUCCESS received, switching to process');
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前选中的体位
|
|
|
|
|
+ const state = store.getState();
|
|
|
|
|
+ const selectedBodyPosition = state.bodyPositionList.selectedBodyPosition;
|
|
|
|
|
+
|
|
|
|
|
+ // 🆕 先标记要保持选中(在切换流程之前)
|
|
|
|
|
+ if (selectedBodyPosition) {
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `[BusinessFlowSlice] Marking to keep selected position: ${selectedBodyPosition.sop_instance_uid}`
|
|
|
|
|
+ );
|
|
|
|
|
+ store.dispatch(setKeepSelection({
|
|
|
|
|
+ sopUid: selectedBodyPosition.sop_instance_uid
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 然后切换到 process 模式
|
|
|
store.dispatch(setBusinessFlow('process'));
|
|
store.dispatch(setBusinessFlow('process'));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-export const { setBusinessFlow } = BusinessFlowSlice.actions;
|
|
|
|
|
|
|
+export const { setBusinessFlow, setKeepSelection, clearKeepSelection } = BusinessFlowSlice.actions;
|
|
|
export default BusinessFlowSlice.reducer;
|
|
export default BusinessFlowSlice.reducer;
|