|
@@ -1,11 +1,16 @@
|
|
|
-import { Action, Middleware } from '@reduxjs/toolkit';
|
|
|
+import { Middleware, PayloadAction } from '@reduxjs/toolkit';
|
|
|
import prepare, { unprepare } from '../domain/exam/prepare';
|
|
|
import { BusinessFlowState, setBusinessFlow } from './BusinessFlowSlice';
|
|
|
+import { setFeedbackOpen } from './exam/largeScreenSlice';
|
|
|
+
|
|
|
+let continueBusinessFlow = '';
|
|
|
|
|
|
const businessFlowMiddlewareLogic: Middleware =
|
|
|
- (store) => (next) => (action: Action) => {
|
|
|
+ (store) => (next) => (action: PayloadAction<string>) => {
|
|
|
//const result = next(action);
|
|
|
- console.log(`[businessFlowMiddleware] Action dispatched: ${action.type}`);
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Action dispatched: ${action.type} ${action.payload}`
|
|
|
+ );
|
|
|
if (action.type !== setBusinessFlow.type) {
|
|
|
return next(action); // Only handle setBusinessFlow actions
|
|
|
}
|
|
@@ -15,28 +20,73 @@ const businessFlowMiddlewareLogic: Middleware =
|
|
|
console.log(
|
|
|
`[businessFlowMiddleware] Current business flow is now: ${state.currentKey} ; Last key was: ${state.lastKey}`
|
|
|
);
|
|
|
+ //进入检查
|
|
|
if (currentKey === 'exam') {
|
|
|
prepare();
|
|
|
}
|
|
|
- if (currentKey !== 'exam' && state.lastKey === 'exam') {
|
|
|
- if (currentKey === 'view') {
|
|
|
- //从检查进入图像处理,有可能是曝光导致的,怎么知道呢?看发生器状态
|
|
|
- if (store.getState().generatorMonitor.acquisitionState === 1) {
|
|
|
- //发生器正在采集
|
|
|
- console.log(
|
|
|
- `[businessFlowMiddleware] Exiting exam flow, but generator is still acquiring.`
|
|
|
- );
|
|
|
- return next(action); // 发生器正在采集,不能退出
|
|
|
- }
|
|
|
+ if (isFromExamToView(action.payload, currentKey)) {
|
|
|
+ //从检查进入图像处理,有可能是曝光导致的,怎么知道呢?看发生器状态
|
|
|
+ if (store.getState().generatorMonitor.acquisitionState === 1) {
|
|
|
+ //发生器正在采集
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Exiting exam flow, but generator is still acquiring.`
|
|
|
+ );
|
|
|
+ return next(action); // 发生器正在采集,不能退出
|
|
|
+ } else {
|
|
|
+ //非曝光导致的从检查进入处理 // 说明从检查退出 , 执行清理
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Exiting exam flow, last key was: ${state.lastKey}`
|
|
|
+ );
|
|
|
+ unprepare();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isExitingExam(action.payload, currentKey)) {
|
|
|
+ const exposureStatus = store.getState().bodyPositionList.exposureStatus;
|
|
|
+ if (exposureStatus === 'Half Exposed') {
|
|
|
+ store.dispatch(setFeedbackOpen(true));
|
|
|
+ // store.dispatch({ type: 'SET_CONTINUE_BUSINESS_FLOW', payload: currentKey });
|
|
|
+ continueBusinessFlow = action.payload; // 保存退出检查时,要去哪个业务流程
|
|
|
+ } else if (exposureStatus === 'Fully Exposed') {
|
|
|
+ // Notify backend
|
|
|
+ console.log(
|
|
|
+ '[businessFlowMiddleware] Fully Exposed, notifying backend'
|
|
|
+ );
|
|
|
+ // Proceed with the action
|
|
|
+ return next(action);
|
|
|
+ } else if (exposureStatus === 'Not Exposed') {
|
|
|
+ // Proceed with the action
|
|
|
+ return next(action);
|
|
|
}
|
|
|
- // 说明从检查退出 , 执行清理
|
|
|
+ }
|
|
|
+ //退出检查的中间过程
|
|
|
+ if (action.payload === 'exitExamCompleted') {
|
|
|
+ // Notify backend with different interfaces for completed and suspended
|
|
|
console.log(
|
|
|
- `[businessFlowMiddleware] Exiting exam flow, last key was: ${state.lastKey}`
|
|
|
+ `[businessFlowMiddleware] Notifying backend for ${action.payload}`
|
|
|
);
|
|
|
- unprepare();
|
|
|
+ // todo 把所有未曝光的体位从study删除掉--服务端和slice。
|
|
|
+ return next({ ...action, type: continueBusinessFlow });
|
|
|
}
|
|
|
-
|
|
|
- return next(action);
|
|
|
+ if (action.payload === 'exitExamSuspended') {
|
|
|
+ // Notify backend with different interfaces for completed and suspended 暂时不通知后端
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Notifying backend for ${action.payload}`
|
|
|
+ );
|
|
|
+ return next({ ...action, type: continueBusinessFlow });
|
|
|
+ }
|
|
|
+ next(action);
|
|
|
};
|
|
|
+/**
|
|
|
+ * 从检查到图像处理
|
|
|
+ */
|
|
|
+function isFromExamToView(currentAction: string, currentKey: string): boolean {
|
|
|
+ return currentAction === 'view' && currentKey === 'exam';
|
|
|
+}
|
|
|
+function isExitingExam(currentAction: string, currentKey: string): boolean {
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Checking if exiting exam: ${currentAction} vs ${currentKey}`
|
|
|
+ );
|
|
|
+ return currentAction !== 'exam' && currentKey === 'exam';
|
|
|
+}
|
|
|
|
|
|
export default businessFlowMiddlewareLogic;
|