| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- import React, { useState } from 'react';
- import { Button, Flex, Divider } from 'antd';
- import '@/themes/truncateText.css';
- import { useDispatch } from 'react-redux';
- import { setAction } 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',
- ]);
- const FunctionButton = ({
- title,
- action,
- iconName,
- }: {
- title: string;
- action: string;
- iconName: string;
- }) => {
- 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', 'Zoom Image', 'Reset Cursor', 'Pan', 'Snapshot',
- ].includes(action)
- ) {
- showNotImplemented('');
- return;
- }
- 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 (
- <Button
- onClick={handleButtonClick}
- onMouseEnter={() => setIsHovered(true)}
- onMouseLeave={() => setIsHovered(false)}
- disabled={disabled}
- icon={
- <Icon
- module="module-process"
- name={iconName}
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- style={getIconStyle()}
- className={`text-[${useToken().token.colorPrimary}] `}
- />
- }
- style={{
- width: '1.5rem',
- height: '1.5rem',
- padding: 0, // 关键
- border: isHovered ? `1px solid ${colorPrimary}` : '1px solid transparent',
- //backgroundColor: isHovered ? `${colorPrimary}` : 'transparent',
- //minWidth: 44, // 保险
- //overflow: 'hidden', // 超出的文字裁掉
- }}
- title={disabled ? `${title} (多分格模式下不可用)` : title}
- className="truncate-text"
- >
- {/* {title} */}
- </Button>
- );
- };
- const FunctionArea = () => {
- return (
- <Flex wrap gap="small" align="center" justify="start" className="p-1">
- <FunctionButton title="Add L Mark" action="Add L Mark" iconName="LMark" />
- <FunctionButton title="Add R Mark" action="Add R Mark" iconName="RMark" />
- <FunctionButton title="Add Mark" action="AddMark" iconName="AddMark" />
- <FunctionButton
- title="Delete Selected Mark"
- action="Delete Selected Mark"
- iconName="EraseMark"
- />
- <FunctionButton
- title="Horizontal Flip"
- action="Horizontal Flip"
- iconName="HReverse"
- />
- <FunctionButton
- title="Vertical Flip"
- action="Vertical Flip"
- iconName="VReverse"
- />
- <FunctionButton
- title="Rotate Counterclockwise 90°"
- action="Rotate Counterclockwise 90"
- iconName="RotateL90"
- />
- <FunctionButton
- title="Rotate Clockwise 90°"
- action="Rotate Clockwise 90"
- iconName="RotateR90"
- />
- <FunctionButton
- title="Rotate Any Angle"
- action="Rotate Any Angle"
- iconName="RotateAnyDegree"
- />
- <FunctionButton
- title="Crop Selected Area"
- action="Crop Selected Area"
- iconName="Crop"
- />
- <FunctionButton
- title="删除数字遮线框"
- action="Delete Digital Mask"
- iconName="btn_RemoveCrop"
- />
- <FunctionButton
- title="Adjust Brightness and Contrast"
- action="Adjust Brightness and Contrast"
- iconName="btn_BrightnessContrast"
- />
- <FunctionButton
- title="Add Mask"
- action="Add Mask"
- iconName="AddMask"
- />
- <FunctionButton
- title="Delete Mask"
- action="Delete Mask"
- iconName="DeleteMask"
- />
- <FunctionButton
- title="Image Comparison"
- action="Image Comparison"
- iconName="btn_Compare"
- />
- <FunctionButton
- title="反色对比"
- action="Invert Contrast"
- iconName="btn_ReverseColour"
- />
- <FunctionButton
- title="1x1 Layout"
- action="1x1 Layout"
- iconName="1x1_normal"
- />
- <FunctionButton
- title="1x2 Layout"
- action="1x2 Layout"
- iconName="1x2_normal"
- />
- <FunctionButton
- title="2x2 Layout"
- action="2x2 Layout"
- iconName="2x1_normal"
- />
- <FunctionButton
- title="4x4 Layout"
- action="4x4 Layout"
- iconName="2x2_normal"
- />
- <FunctionButton
- title="Magnifier"
- action="Magnifier"
- iconName="Magnifier"
- />
- <FunctionButton
- title="Fit Size"
- action="Fit Size"
- iconName="FitInWindow"
- />
- <FunctionButton
- title="Original Size"
- action="Original Size"
- iconName="1by1_normal"
- />
- <FunctionButton title="Zoom Image" action="Zoom Image" iconName="Zoom" />
- <FunctionButton
- title="Reset Cursor"
- action="Reset Cursor"
- iconName="btn_pointer"
- />
- <FunctionButton title="Pan" action="Pan" iconName="Pan" />
- <FunctionButton
- title="Invert Image"
- action="Invert Image"
- iconName="Invert"
- />
- <FunctionButton
- title="Reset Image"
- action="Reset Image"
- iconName="Reset"
- />
- <FunctionButton
- title="Snapshot"
- action="Snapshot"
- iconName="imgsnapshot"
- />
- <Divider type="horizontal" style={{ height: 'auto', margin: '8px' }} />
- <FunctionButton
- title="Advanced Processing"
- action="Advanced Processing"
- iconName="btn_Imageprocess"
- />
- <FunctionButton
- title="Image Measurement"
- action="Image Measurement"
- iconName="btn_Measurements"
- />
- <FunctionButton
- title="矩形裁剪"
- action="Rectangle Crop"
- iconName="rectangle-crop"
- />
- <FunctionButton title="More" action="More" iconName="btn_OtherSetting" />
- </Flex>
- );
- };
- export default FunctionArea;
|