|
@@ -1,6 +1,6 @@
|
|
|
/* eslint-disable */
|
|
|
import { createSlice, PayloadAction, Middleware, createAsyncThunk } from '@reduxjs/toolkit';
|
|
|
-import { AprConfig, getAprExposureParams, SetAPR } from '../../API/exam/APRActions';
|
|
|
+import { AprConfig, getAprExposureParams, getAprByThickness, SetAPR } from '../../API/exam/APRActions';
|
|
|
import { workstationIdFromWorkstation, WorkstationType } from '../workstation';
|
|
|
import { ExtendedBodyPosition, setSelectedBodyPosition } from '../exam/bodyPositionListSlice';
|
|
|
import { initializeProductState } from '../productSlice';
|
|
@@ -9,6 +9,7 @@ interface AprState {
|
|
|
aprConfig: AprConfig;
|
|
|
bodysize: string;
|
|
|
workstation: string;
|
|
|
+ thickness: number;
|
|
|
isAECEnabled: boolean;
|
|
|
currentExposureMode: string;
|
|
|
/**
|
|
@@ -34,6 +35,7 @@ const initialState: AprState = {
|
|
|
},
|
|
|
bodysize: '',
|
|
|
workstation: '',
|
|
|
+ thickness: 0,
|
|
|
isAECEnabled: false,
|
|
|
currentExposureMode: 'mAs',
|
|
|
isPending:false
|
|
@@ -52,6 +54,9 @@ const aprSlice = createSlice({
|
|
|
setWorkstation: (state, action: PayloadAction<string>) => {
|
|
|
state.workstation = action.payload;
|
|
|
},
|
|
|
+ setThickness: (state, action: PayloadAction<number>) => {
|
|
|
+ state.thickness = action.payload;
|
|
|
+ },
|
|
|
setIsAECEnabled: (state, action: PayloadAction<boolean>) => {
|
|
|
state.isAECEnabled = action.payload;
|
|
|
},
|
|
@@ -161,10 +166,34 @@ const aprSlice = createSlice({
|
|
|
.addCase(decDensity.rejected, (state, action) => {
|
|
|
console.error('Failed to decrease Density', action.error);
|
|
|
})
|
|
|
+ .addCase(incThickness.pending, (state) => {
|
|
|
+ console.log('Increasing Thickness...');
|
|
|
+ })
|
|
|
+ .addCase(incThickness.fulfilled, (state, action) => {
|
|
|
+ console.log('Thickness increased successfully');
|
|
|
+ state.thickness = action.payload;
|
|
|
+ })
|
|
|
+ .addCase(incThickness.rejected, (state, action) => {
|
|
|
+ console.error('Failed to increase Thickness', action.error);
|
|
|
+ })
|
|
|
+ .addCase(decThickness.pending, (state) => {
|
|
|
+ console.log('Decreasing Thickness...');
|
|
|
+ })
|
|
|
+ .addCase(decThickness.fulfilled, (state, action) => {
|
|
|
+ console.log('Thickness decreased successfully');
|
|
|
+ state.thickness = action.payload;
|
|
|
+ })
|
|
|
+ .addCase(decThickness.rejected, (state, action) => {
|
|
|
+ console.error('Failed to decrease Thickness', action.error);
|
|
|
+ })
|
|
|
.addCase(setSelectedBodyPosition, (state, action: PayloadAction<ExtendedBodyPosition | null>) => {
|
|
|
console.log('APR Extra Reducer triggered for setSelectedBodyPosition action');
|
|
|
const selectedBodyPosition = action.payload;
|
|
|
if (selectedBodyPosition) {
|
|
|
+ // 初始化厚度值
|
|
|
+ state.thickness = selectedBodyPosition.work?.Thickness || 0;
|
|
|
+ console.log('Initialized thickness from selected body position:', state.thickness);
|
|
|
+
|
|
|
const reqParam = JSON.stringify({
|
|
|
P0:{
|
|
|
FOCUS: "0",
|
|
@@ -275,6 +304,67 @@ const aprMiddleware: Middleware = (store) => (next) => (action: any) => {
|
|
|
console.log('APR exposure parameters fetch attempt finished.');
|
|
|
});
|
|
|
}
|
|
|
+ } else if (action.type === aprSlice.actions.setThickness.type) {
|
|
|
+ console.log('APR Middleware triggered by thickness change:', action.type);
|
|
|
+ const state = store.getState();
|
|
|
+ const thickness = state.apr.thickness;
|
|
|
+ console.log(`Fetching APR exposure parameters by thickness: ${thickness}`);
|
|
|
+
|
|
|
+ // 确保厚度值在有效范围内 (1-50)
|
|
|
+ if (thickness >= 1 && thickness <= 50) {
|
|
|
+ getAprByThickness(thickness)
|
|
|
+ .then((data) => {
|
|
|
+ console.log('Received APR exposure parameters by thickness:', data);
|
|
|
+ if (data) {
|
|
|
+ store.dispatch(setAprConfig(data));
|
|
|
+
|
|
|
+ // After updating the store, send the APR parameters to the device
|
|
|
+ const currentState = store.getState();
|
|
|
+ const selectedBodyPosition = currentState.bodyPositionList.selectedBodyPosition;
|
|
|
+ console.info(`根据厚度得到arp后,下发kv ms mas ma 给设备`);
|
|
|
+ if (selectedBodyPosition) {
|
|
|
+ const reqParam = JSON.stringify({
|
|
|
+ P0: {
|
|
|
+ FOCUS: "0",
|
|
|
+ TECHMODE: "0",
|
|
|
+ AECFIELD: "101",
|
|
|
+ AECFILM: "0",
|
|
|
+ AECDENSITY: "0",
|
|
|
+ KV: data.kV.toString(),
|
|
|
+ MA: data.mA.toString(),
|
|
|
+ MS: (data.mAs/data.mA).toString(),
|
|
|
+ MAS: data.mAs.toString(),
|
|
|
+ KV2: "0.0",
|
|
|
+ MA2: "0.0",
|
|
|
+ MS2: "0.0",
|
|
|
+ DOSE: "0.0",
|
|
|
+ FILTER: "null",
|
|
|
+ TUBELOAD: "0.0",
|
|
|
+ WORKSTATION: selectedBodyPosition.work_station_id
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.info(`根据厚度得到arp后,下发之前 kv ms mas ma = ${reqParam}`);
|
|
|
+ SetAPR(reqParam)
|
|
|
+ .then(() => {
|
|
|
+ console.log('[aprMiddleware] SetAPR called successfully after thickness change');
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error('[aprMiddleware] Error calling SetAPR after thickness change:', error);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.warn('[aprMiddleware] No selected body position found, skipping SetAPR call');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error('Error fetching APR exposure parameters by thickness:', error);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ console.log('APR exposure parameters fetch by thickness attempt finished.');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.warn(`Thickness value ${thickness} is out of valid range (1-50), skipping API call`);
|
|
|
+ }
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
@@ -319,10 +409,19 @@ export const decDensity = createAsyncThunk<number, number>('apr/decDensity', asy
|
|
|
return amount;
|
|
|
});
|
|
|
|
|
|
+export const incThickness = createAsyncThunk<number, number>('apr/incThickness', async (amount: number) => {
|
|
|
+ return amount;
|
|
|
+});
|
|
|
+
|
|
|
+export const decThickness = createAsyncThunk<number, number>('apr/decThickness', async (amount: number) => {
|
|
|
+ return amount;
|
|
|
+});
|
|
|
+
|
|
|
export const {
|
|
|
setAprConfig,
|
|
|
setBodysize,
|
|
|
setWorkstation,
|
|
|
+ setThickness,
|
|
|
setIsAECEnabled,
|
|
|
setCurrentExposureMode,
|
|
|
} = aprSlice.actions;
|