DeviceArea.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { Flex, Button, Badge } from 'antd';
  2. import {
  3. ToolOutlined,
  4. CameraOutlined,
  5. TabletOutlined,
  6. } from '@ant-design/icons';
  7. import { useSelector } from 'react-redux';
  8. import { RootState } from '@/states/store';
  9. import {
  10. GENERATOR_STATUS,
  11. GeneratorStatus,
  12. } from '@/states/exam/deviceAreaSlice';
  13. import triggerInspection from '../../API/exam/triggerInspection';
  14. const DeviceArea = ({ className }: { className?: string }) => {
  15. const generatorStatus = useSelector(
  16. (state: RootState) => state.deviceArea.generatorStatus
  17. );
  18. const generatorStatus_2 = useSelector(
  19. (state: RootState) => state.deviceArea.generatorStatus_2
  20. );
  21. // 只关注发生器的ready状态
  22. const generatorReady = useSelector(
  23. (state: RootState) => state.deviceArea.generatorReady
  24. );
  25. const exposureStatus = useSelector(
  26. (state: RootState) => state.deviceArea.exposureStatus
  27. );
  28. const tabletStatus = useSelector(
  29. (state: RootState) => state.deviceArea.tabletStatus
  30. );
  31. // 读取 FPD 状态,判断是否为模拟器模式
  32. const fpd = useSelector((state: RootState) => state.product.fpd);
  33. const isSimulator = fpd === 'Simulator';
  34. const btnStyle = { width: '1.5rem', height: '1.5rem' };
  35. const classValue = 'mr-1';
  36. return (
  37. <Flex justify="end" align="center" className={`w-full ${className}`}>
  38. <Button
  39. style={btnStyle}
  40. className={classValue}
  41. icon={
  42. <ToolOutlined
  43. className={
  44. generatorReady ? 'text-green-500' : 'text-yellow-500'
  45. }
  46. />
  47. }
  48. title={`手闸状态指示器: ${generatorStatus}`}
  49. />
  50. <Badge count={isSimulator ? 'S' : 'R'} offset={[-15, 10]} color="orange">
  51. <Button
  52. style={btnStyle}
  53. data-testid="device-all-ready"
  54. className={`${classValue} ${exposureStatus === 'ready'
  55. ? 'text-green-500'
  56. : exposureStatus === 'not_ready'
  57. ? ''
  58. : ''
  59. }`}
  60. icon={
  61. <CameraOutlined
  62. // className={
  63. // exposureStatus === 'ready'
  64. // ? 'text-green-500'
  65. // : exposureStatus === 'not_ready'
  66. // ? ''
  67. // : ''
  68. // }
  69. />
  70. }
  71. onClick={() => {
  72. if (!isSimulator) {
  73. // 真实环境下禁止点击
  74. console.warn('真实环境下,曝光操作需要通过硬件触发');
  75. return;
  76. }
  77. // 模拟环境下允许点击
  78. triggerInspection();
  79. }}
  80. title={`曝光指示器: ${exposureStatus}${isSimulator ? ' (模拟模式)' : ' (真实模式)'}`}
  81. />
  82. </Badge>
  83. <Button
  84. style={btnStyle}
  85. className={`${classValue} ${tabletStatus === 'exposing'
  86. ? 'text-yellow-500'
  87. : tabletStatus === 'ready'
  88. ? 'text-green-500'
  89. : tabletStatus === 'error'
  90. ? 'text-red-500'
  91. : ''
  92. }`}
  93. icon={
  94. <TabletOutlined
  95. // className={
  96. // tabletStatus === 'exposing'
  97. // ? 'text-yellow-500'
  98. // : tabletStatus === 'ready'
  99. // ? 'text-green-500'
  100. // : tabletStatus === 'error'
  101. // ? 'text-red-500'
  102. // : ''
  103. // }
  104. />
  105. }
  106. title={`平板指示器: ${tabletStatus}`}
  107. />
  108. </Flex>
  109. );
  110. };
  111. export default DeviceArea;