|
@@ -11,6 +11,8 @@ import {
|
|
} from '@/states/exam/bodyPositionListSlice';
|
|
} from '@/states/exam/bodyPositionListSlice';
|
|
import { setBodyPositionDetail } from '@/states/exam/bodyPositionDetailSlice';
|
|
import { setBodyPositionDetail } from '@/states/exam/bodyPositionDetailSlice';
|
|
import { changeBodyPosition } from '@/API/exam/changeBodyPosition';
|
|
import { changeBodyPosition } from '@/API/exam/changeBodyPosition';
|
|
|
|
+import { setBusinessFlow } from '@/states/BusinessFlowSlice';
|
|
|
|
+import emitter from '@/utils/eventEmitter';
|
|
|
|
|
|
export const selectBodyPositionWithFullLogic = async (
|
|
export const selectBodyPositionWithFullLogic = async (
|
|
bodyPosition: ExtendedBodyPosition,
|
|
bodyPosition: ExtendedBodyPosition,
|
|
@@ -107,3 +109,83 @@ export const manualSelectBodyPosition = async (
|
|
true // 手动选中时显示用户消息
|
|
true // 手动选中时显示用户消息
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 带流程切换的体位选择(用户点击体位时调用,根据曝光状态自动切换流程)
|
|
|
|
+ */
|
|
|
|
+export const manualSelectBodyPositionWithFlowSwitch = async (
|
|
|
|
+ bodyPosition: ExtendedBodyPosition,
|
|
|
|
+ dispatch: AppDispatch,
|
|
|
|
+ currentKey: string
|
|
|
|
+): Promise<void> => {
|
|
|
|
+ const isExposed = bodyPosition.dview.expose_status === 'Exposed';
|
|
|
|
+ const isUnexposed = bodyPosition.dview.expose_status === 'Unexposed';
|
|
|
|
+
|
|
|
|
+ let targetFlow = currentKey;
|
|
|
|
+ let needSwitch = false;
|
|
|
|
+
|
|
|
|
+ // 判断是否需要切换流程
|
|
|
|
+ if (currentKey === 'exam' && isExposed) {
|
|
|
|
+ targetFlow = 'process';
|
|
|
|
+ needSwitch = true;
|
|
|
|
+ console.log(
|
|
|
|
+ `[bodyPositionSelection] Detected exposed position in exam mode, will switch to process`
|
|
|
|
+ );
|
|
|
|
+ } else if (currentKey === 'process' && isUnexposed) {
|
|
|
|
+ targetFlow = 'exam';
|
|
|
|
+ needSwitch = true;
|
|
|
|
+ console.log(
|
|
|
|
+ `[bodyPositionSelection] Detected unexposed position in process mode, will switch to exam`
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (needSwitch) {
|
|
|
|
+ console.log(
|
|
|
|
+ `[bodyPositionSelection] Switching flow from ${currentKey} to ${targetFlow}`
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // 创建一个 Promise 来等待流程切换完成
|
|
|
|
+ const flowSwitchPromise = new Promise<void>((resolve) => {
|
|
|
|
+ // 设置一个一次性监听器
|
|
|
|
+ const handler = (data: {
|
|
|
|
+ from: string;
|
|
|
|
+ to: string;
|
|
|
|
+ timestamp: number;
|
|
|
|
+ }) => {
|
|
|
|
+ if (data.to === targetFlow) {
|
|
|
|
+ console.log(
|
|
|
|
+ `[bodyPositionSelection] Flow switch completed: ${data.from} -> ${data.to}`
|
|
|
|
+ );
|
|
|
|
+ // 移除监听器
|
|
|
|
+ emitter.off('BUSINESS_FLOW_CHANGED', handler);
|
|
|
|
+ resolve();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ emitter.on('BUSINESS_FLOW_CHANGED', handler);
|
|
|
|
+
|
|
|
|
+ // 设置超时保护,防止事件永远不触发
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ emitter.off('BUSINESS_FLOW_CHANGED', handler);
|
|
|
|
+ console.warn(
|
|
|
|
+ '[bodyPositionSelection] Flow switch timeout, proceeding anyway'
|
|
|
|
+ );
|
|
|
|
+ resolve();
|
|
|
|
+ }, 2000); // 2秒超时
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 触发流程切换
|
|
|
|
+ dispatch(setBusinessFlow(targetFlow));
|
|
|
|
+
|
|
|
|
+ // 等待流程切换完成
|
|
|
|
+ await flowSwitchPromise;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 使用正确的流程 key 选中体位
|
|
|
|
+ await selectBodyPositionWithFullLogic(
|
|
|
|
+ bodyPosition,
|
|
|
|
+ dispatch,
|
|
|
|
+ targetFlow,
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+};
|