import React, { useState } from 'react'; import { Button, Flex, Divider } from 'antd'; import { useIntl } from 'react-intl'; import '@/themes/truncateText.css'; import { useDispatch } from 'react-redux'; import { setAction, toggleTool, deactivateAllTools } from '@/states/view/functionAreaSlice'; import { switchToMeasurementPanel, switchToMorePanel, switchToAdvancedProcessingPanel, switchToRectCropPanel, switchToMarkPanel } from '@/states/panelSwitchSliceForView'; import Icon from '@/components/Icon'; import { showNotImplemented } from '@/utils/notificationHelper'; import { useAppSelector } from '@/states/store'; import { useButtonAvailability } from '@/utils/useButtonAvailability'; import { theme } from 'antd'; const { useToken } = theme; // 有状态按钮列表 - 这些按钮代表持续的状态,不应在执行后清理action const STATEFUL_BUTTON_ACTIONS = new Set([ 'Adjust Brightness and Contrast', 'Magnifier', 'Zoom Image', 'Pan', ]); const FunctionButton = ({ title, action, iconName, }: { title: string; action: string; iconName: string; }) => { const intl = useIntl(); const dispatch = useDispatch(); const themeType = useAppSelector((state) => state.theme.themeType); const activeTools = useAppSelector((state) => state.functionArea.activeTools); const { disabled } = useButtonAvailability(action); // 对于有状态按钮,基于工具激活状态;对于无状态按钮,基于action const isActive = STATEFUL_BUTTON_ACTIONS.has(action) ? activeTools[action] || false : false; // 无状态按钮不显示激活状态 const [isHovered, setIsHovered] = useState(false); const colorPrimary = useToken().token.colorPrimary; // 根据状态计算Icon的样式 const getIconStyle = () => { const baseStyle = { /*控制svg图标的大小,暂时使用这种fontSize方式 */ fontSize: '48px', }; if (disabled) { return { ...baseStyle, opacity: 0.4, filter: 'grayscale(1)' }; } if (isActive) { return { ...baseStyle, color: colorPrimary }; } if (isHovered) { return { ...baseStyle }; } return { ...baseStyle }; // 默认颜色 }; const handleButtonClick = () => { if (disabled) { return; } // 检查是否为未实现的功能 if (action === 'Delete Digital Mask' || action === 'Crop Selected Area' || ['Image Comparison', 'Reset Cursor', 'Snapshot', ].includes(action) ) { showNotImplemented(); return; } // 处理有状态工具按钮(鼠标左键绑定工具) if (STATEFUL_BUTTON_ACTIONS.has(action)) { dispatch(toggleTool(action)); return; } // 对于其他按钮,先停用所有工具 dispatch(deactivateAllTools()); // 面板切换按钮 if (action === 'Image Measurement') { dispatch(switchToMeasurementPanel()); } else if (action === 'Rectangle Crop') { dispatch(switchToRectCropPanel()); } else if (action === 'More') { dispatch(switchToMorePanel()); } else if (action === 'Advanced Processing') { dispatch(switchToAdvancedProcessingPanel()); } else if (action === 'AddMark') { dispatch(switchToMarkPanel()); } else { // 其他功能按钮保持原有逻辑 dispatch(setAction(action)); } }; return ( ); }; const FunctionArea = () => { const intl = useIntl(); return ( ); }; export default FunctionArea;