/** * 响应用户的操作,不需要组件传递参数,这些操作对应的方法有: * 1. 增加KV 2. 减少KV 3. 增加MAS 4. 减少MAS 5. 增加MA 6. 减少MA 7. 增加MS 8. 减少MS 9. 增加Density 10. 减少Density 11. 增加Thickness 12. 减少Thickness 13. 设置APR * 以上方法内部逻辑是向服务发送设置曝光参数,KV MA MS MAS;间接调用api method,通过 调用 @/src/API/exam/APRActions.ts 中定义的方法完成调用,并不直接调用api * 接收device mqtt发来的新参数。device mqtt会触发事件 emitter.emit('NEW_KV',parsedMessage.CONTEXT); 这是接收KV新值的,还有对应的其他新曝光参数的新值 * 把 device mqtt 发来的新参数传递给 @/src/states/exam/aprSlice.ts 。 dispatch thunk的 action,有fullfilled pending rejected ,比如 incMS.fulfilled ;考虑 device mqtt 发来新曝光参数会超时,超时的情况下向 aprSLice发送 rejected 。 */ import { incKv as incKvFromAction, decKv as decKvFromAction, incMas as incMasFromAction, decMas as decMasFromAction, incMa as incMaFromAction, decMa as decMaFromAction, incMs as incMsFromAction, decMs as decMsFromAction, incDensity as incDensityFromAction, decDensity as decDensityFromAction, incThickness as incThicknessFromAction, decThickness as decThicknessFromAction, setExposureModeFromAction, } from '../../API/exam/APRActions'; import emitter from '../../utils/eventEmitter'; import { incKV, decKV, incMAS, decMAS, incMA, decMA, incMS, decMS, incDensity, decDensity, incThickness, decThickness, setExposureModeThunk, } from '../../states/exam/aprSlice'; import store from '../../states/store'; class ParaSettingCoordinator { constructor() { this.dispatch = store.dispatch; this.initializeEventListeners(); } dispatch; initializeEventListeners() { emitter.on('NEW_KV', (newValue) => this.handleNewKV(newValue)); emitter.on('NEW_MAS', (newValue) => this.handleNewMAS(newValue)); emitter.on('NEW_MA', (newValue) => this.handleNewMA(newValue)); emitter.on('NEW_MS', (newValue) => this.handleNewMS(newValue)); emitter.on('NEW_DENSITY', (newValue) => this.handleNewDensity(newValue)); emitter.on('NEW_THICKNESS', (newValue) => this.handleNewThickness(newValue) ); emitter.on('NEW_EXPOSURE_MODE', (newValue) => this.handleNewExposureMode(newValue) ); } handleNewKV(newValue) { this.dispatch({ type: incKV.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewMAS(newValue) { console.info('有新的mAs从设备端到来。handleNewMAS', newValue); this.dispatch({ type: incMAS.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewMA(newValue) { this.dispatch({ type: incMA.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewMS(newValue) { this.dispatch({ type: incMS.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewDensity(newValue) { this.dispatch({ type: incDensity.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewThickness(newValue) { this.dispatch({ type: incThickness.fulfilled.type, payload: newValue, meta: { arg: newValue, requestId: '' }, }); } handleNewExposureMode(newValue) { // 将数字转换为字符串: 0 -> 'time', 1 -> 'mAs' const mode = newValue === '0' ? 'time' : 'mAs'; console.info('有新的曝光模式从设备端到来。handleNewExposureMode', newValue, '转换为:', mode); this.dispatch({ type: setExposureModeThunk.fulfilled.type, payload: mode, meta: { arg: mode, requestId: '' }, }); } setExposureMode(mode: string) { console.info('[ParaSettingCoordinator] 切换曝光模式:', mode); // 1. Dispatch pending this.dispatch({ type: setExposureModeThunk.pending.type, meta: { arg: mode, requestId: '' }, }); // 2. 调用API try { // 将UI字符串转换为API需要的数字: 'mAs' -> 1, 'time' -> 0 let reqParam; if (mode === 'mAs') { // 构造参数对象 reqParam = JSON.stringify({ P0: "1" }); } else if (mode === 'time') { // 构造参数对象 reqParam = JSON.stringify({ P0: "0" }); } console.info('[ParaSettingCoordinator] 下发曝光模式参数:', reqParam); setExposureModeFromAction(reqParam); } catch (error) { console.error('[ParaSettingCoordinator] 切换曝光模式失败:', error); this.dispatch({ type: setExposureModeThunk.rejected.type, payload: error, meta: { arg: mode, requestId: '' }, }); } } increaseKV() { this.dispatch({ type: incKV.pending.type, meta: { arg: 0, requestId: '' }, }); try { incKvFromAction(); } catch (error) { this.dispatch({ type: incKV.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseKV() { this.dispatch({ type: decKV.pending.type, meta: { arg: 0, requestId: '' }, }); try { decKvFromAction(); } catch (error) { this.dispatch({ type: decKV.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } increaseMAS() { this.dispatch({ type: incMAS.pending.type, meta: { arg: 0, requestId: '' }, }); try { incMasFromAction(); } catch (error) { this.dispatch({ type: incMAS.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseMAS() { this.dispatch({ type: decMAS.pending.type, meta: { arg: 0, requestId: '' }, }); try { decMasFromAction(); } catch (error) { this.dispatch({ type: decMAS.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } increaseMA() { this.dispatch({ type: incMA.pending.type, meta: { arg: 0, requestId: '' }, }); try { incMaFromAction(); } catch (error) { this.dispatch({ type: incMA.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseMA() { this.dispatch({ type: decMA.pending.type, meta: { arg: 0, requestId: '' }, }); try { decMaFromAction(); } catch (error) { this.dispatch({ type: decMA.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } increaseMS() { this.dispatch({ type: incMS.pending.type, meta: { arg: 0, requestId: '' }, }); try { incMsFromAction(); } catch (error) { this.dispatch({ type: incMS.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseMS() { this.dispatch({ type: decMS.pending.type, meta: { arg: 0, requestId: '' }, }); try { decMsFromAction(); } catch (error) { this.dispatch({ type: decMS.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } increaseDensity() { this.dispatch({ type: incDensity.pending.type, meta: { arg: 0, requestId: '' }, }); try { incDensityFromAction(); } catch (error) { this.dispatch({ type: incDensity.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseDensity() { this.dispatch({ type: decDensity.pending.type, meta: { arg: 0, requestId: '' }, }); try { decDensityFromAction(); } catch (error) { this.dispatch({ type: decDensity.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } increaseThickness() { this.dispatch({ type: incThickness.pending.type, meta: { arg: 0, requestId: '' }, }); try { incThicknessFromAction(); } catch (error) { this.dispatch({ type: incThickness.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } decreaseThickness() { this.dispatch({ type: decThickness.pending.type, meta: { arg: 0, requestId: '' }, }); try { decThicknessFromAction(); } catch (error) { this.dispatch({ type: decThickness.rejected.type, payload: error, meta: { arg: 0, requestId: '' }, }); } } } export default new ParaSettingCoordinator();