import React from 'react'; import { GroupOutlined, UngroupOutlined, CopySquareOutlined, PasteSquareOutlined, DeleteOutlined, EditOutlined, // BulbOutlined, AimOutlined, EyeOutlined, LockOutlined, } from '@easyv/react-icons'; import { ctrlKeyStr, shiftKeyStr, ComponentTypeEnum, ComponentInfo } from '@easytwin/core'; import classnames from 'classnames'; import { ContextMenuItem } from '@/components'; export interface RightClickContextMenuProp { style?: React.CSSProperties; copyComponents: ComponentInfo[]; selectComponents: ComponentInfo[]; onCreateGroup?: () => void; onRemoveGroup?: () => void; onClone?: () => void; onCopy?: () => void; onPaste?: () => void; onRemove?: () => void; onEdit?: () => void; // onOneShow?: () => void; onFlyTo?: () => void; onVisibleChange?: () => void; onActiveChange?: () => void; // 关闭 onClose?: () => void; } const RightClickContextMenu: React.FC = function ({ style, copyComponents, selectComponents, onCreateGroup, onRemoveGroup, onClone, onCopy, onPaste, onRemove, onEdit, // onOneShow, onFlyTo, onVisibleChange, onActiveChange, // onClose, }) { // 是否选中单个元件 const isSelectOne = React.useMemo(() => selectComponents.length === 1, [selectComponents]); // 选中的第一个元件 const firstSelectComponenter = React.useMemo(() => { if (selectComponents.length > 0) { return selectComponents[0]; } return null; }, [selectComponents]); // 鼠标是否进入 const [isMouseEnter, setIsMouseEnter] = React.useState(false); return (
setIsMouseEnter(true)} // 鼠标离开关闭 onMouseLeave={() => isMouseEnter && onClose?.()}>
} onClick={() => { onClose?.(); onCreateGroup?.(); }} /> } disabled={!selectComponents.some((i) => i?.type === ComponentTypeEnum.BIZGROUP)} onClick={() => { onClose?.(); onRemoveGroup?.(); }} /> } onClick={() => { onClose?.(); onClone?.(); }} /> } onClick={() => { onClose?.(); onCopy?.(); }} /> } disabled={copyComponents.length === 0} onClick={() => { onClose?.(); onPaste?.(); }} />
{isSelectOne && firstSelectComponenter?.type !== ComponentTypeEnum.BIZGROUP && (
{/* } disabled={firstSelectComponenter?.type === ComponentTypeEnum.BIZGROUP} onClick={() => { onClose?.(); onOneShow?.(); }} /> */} } disabled={firstSelectComponenter?.type !== ComponentTypeEnum.MODEL} onClick={() => { onClose?.(); onFlyTo?.(); }} /> 锁定 / 解锁 } desc={`${ctrlKeyStr} L`} icon={} onClick={() => { onClose?.(); onActiveChange?.(); }} /> 隐藏 / 显示 } desc={`${ctrlKeyStr} H`} icon={} onClick={() => { onClose?.(); onVisibleChange?.(); }} />
)}
{isSelectOne && ( } disabled={!isSelectOne} onClick={() => { onClose?.(); onEdit?.(); }} /> )} } onClick={() => { onClose?.(); onRemove?.(); }} />
); }; export default RightClickContextMenu;