| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- /**
- * 响应用户的操作,不需要组件传递参数,这些操作对应的方法有:
- *
- 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();
|