import React, { useState, useCallback, useRef } from 'react'; import { Cpu, Settings, Anchor, ChevronUp, ChevronDown, Plus, Trash2, Image, Layers, FileText, ChevronRight, RotateCw, Target, Move } from 'lucide-react'; /** * Disassembly Edit/Preview Page * 融合 DisassemblyPages(视觉展示)与 DisassemblyLinkedProductsPage(交互编辑) * * 编辑模式:左侧属性面板 + 点击选中导航组件 + 支持新增/删除/修改名称/代码/图片 * 预览模式:与 DisassemblyPages v7.2.0 一致的工业草稿风格展示 */ const styles = ` @keyframes scanline { 0% { transform: translateY(-100%); } 100% { transform: translateY(100%); } } @keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } } @keyframes node-pulse-kf { 0% { box-shadow: 0 0 0 0px rgba(234, 179, 8, 0.5); } 100% { box-shadow: 0 0 0 10px rgba(234, 179, 8, 0); } } .blueprint-grid { background-color: #ffffff; background-image: linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px); background-size: 30px 30px; } .blueprint-grid::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px); background-size: 10px 10px; pointer-events: none; } .assembly-view { filter: drop-shadow(0 15px 30px rgba(0,0,0,0.1)) contrast(1.05); transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1); } .assembly-view:hover { filter: drop-shadow(0 20px 40px rgba(0,0,0,0.15)) contrast(1.1); } .leader-line-svg { transition: stroke 0.4s ease, stroke-width 0.4s ease; } .text-label-container { transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1); } .scan-effect { position: absolute; top: 0; left: 0; right: 0; height: 100%; background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.01), transparent); animation: scanline 15s linear infinite; pointer-events: none; } .node-selected { animation: node-pulse-kf 2s infinite; outline: 2px solid #eab308; outline-offset: 4px; } .custom-scrollbar::-webkit-scrollbar { width: 4px; } .custom-scrollbar::-webkit-scrollbar-thumb { background: #000; border-radius: 10px; } .part-hover { transition: all 0.35s cubic-bezier(0.23, 1, 0.32, 1); } `; const DEFAULT_PARTS = [ { id: 'p1', name: '环境监控', code: 'ENV-X', img: 'https://images.unsplash.com/photo-1555680202-c86f0e12f086?auto=format&fit=crop&q=80&w=200' }, { id: 'p2', name: '能源模组', code: 'BATT-V8', img: 'https://images.unsplash.com/photo-1619641259501-c88f28c6e355?auto=format&fit=crop&q=80&w=200' }, { id: 'p3', name: '雷达阵列', code: 'LDR-07', img: 'https://images.unsplash.com/photo-1555680202-c86f0e12f086?auto=format&fit=crop&q=80&w=200' }, { id: 'p4', name: '核心总成', code: 'CORE-MAX', img: 'https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&q=80&w=200' }, { id: 'p5', name: '液压单元', code: 'HYD-02', img: 'https://images.unsplash.com/photo-1635350736475-c8cef4b21906?auto=format&fit=crop&q=80&w=200' }, { id: 'p6', name: '散热单元', code: 'COOL-F2', img: 'https://images.unsplash.com/photo-1635350736475-c8cef4b21906?auto=format&fit=crop&q=80&w=200' }, { id: 'p7', name: '存储阵列', code: 'DATA-2T', img: 'https://images.unsplash.com/photo-1544006659-f0b21f04cb1d?auto=format&fit=crop&q=80&w=200' }, ]; const DEFAULT_ASSEMBLY = 'https://images.unsplash.com/photo-1581092160562-40aa08e78837?auto=format&fit=crop&q=80&w=1600'; const ICON_SIZE = 80; const CENTER_AXIS_Y = 180; const OFFSET_Y = 40; // ─── 单个组件节点(共用于编辑 & 预览)───────────────────────────────────── function PartNode({ part, index, isHovered, isSelected, isEditMode, onHover, onClick }) { const isUp = index % 2 === 0; const boxTop = isUp ? CENTER_AXIS_Y - OFFSET_Y : CENTER_AXIS_Y + OFFSET_Y; const SVG_CENTER_X = 50; const SVG_CENTER_Y = 40; const lineColor = isSelected ? '#eab308' : isHovered ? '#000' : '#f5f5f5'; const lineWidth = isSelected ? '2.5' : isHovered ? '2.5' : '1'; return (
onHover(part.id)} onMouseLeave={() => onHover(null)} onClick={() => isEditMode && onClick(part.id)} className={`group flex flex-col items-center relative flex-1 ${isEditMode ? 'cursor-pointer' : 'cursor-default'} ${isSelected ? 'z-30' : 'z-10'}`} style={{ minWidth: 0 }} > {/* 垂直引导线 */} {/* 图标节点 */}
{part.name} {(isHovered || isSelected) && (
)} {isEditMode && (
)}
{/* 标签容器 */}
{/* 接线端子 */}
{/* 指示器 */}
{isUp ? :
}
CODE.0{index + 1}
{!isUp ? :
}
{/* 大字名称 */}
{part.name}
); } // ─── 主组件 ──────────────────────────────────────────────────────────────── export default function App() { const [isEditMode, setIsEditMode] = useState(true); const [parts, setParts] = useState(DEFAULT_PARTS); const [assemblyImg, setAssemblyImg] = useState(DEFAULT_ASSEMBLY); const [hoveredId, setHoveredId] = useState(null); const [selectedId, setSelectedId] = useState(null); const [imgInputVal, setImgInputVal] = useState(''); const selectedPart = parts.find(p => p.id === selectedId) || null; const idxOf = (id) => parts.findIndex(p => p.id === id); // ── 更新选中组件字段 ── const updateField = useCallback((field, value) => { if (!selectedId) return; setParts(prev => prev.map(p => p.id === selectedId ? { ...p, [field]: value } : p)); }, [selectedId]); // ── 新增组件 ── const addPart = () => { const newPart = { id: 'p-' + Date.now(), name: '新组件', code: 'NEW-00', img: 'https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&q=80&w=200', }; setParts(prev => [...prev, newPart]); setSelectedId(newPart.id); }; // ── 删除选中组件 ── const deletePart = () => { if (!selectedId) return; setParts(prev => prev.filter(p => p.id !== selectedId)); setSelectedId(null); }; // ── 上移 / 下移 ── const movePart = (dir) => { const idx = idxOf(selectedId); if (idx < 0) return; const next = idx + dir; if (next < 0 || next >= parts.length) return; setParts(prev => { const arr = [...prev]; [arr[idx], arr[next]] = [arr[next], arr[idx]]; return arr; }); }; // ── 切换模式 ── const enterPreview = () => { setIsEditMode(false); setSelectedId(null); }; const enterEdit = () => setIsEditMode(true); return (
{/* ── 顶部标题栏 ────────────────────────────────────── */}

Disassembly_Editor

EDIT_PREVIEW_v1.0.0 // VISUAL_ENHANCED

{/* 模式切换 */}
{isEditMode ? 'MODE: EDIT' : 'MODE: PREVIEW'}
{/* ── 主体区域 ────────────────────────────────────── */}
{/* ── 左侧编辑面板(仅编辑模式)─────────────────── */} {isEditMode && ( )} {/* ── 右侧主画布 ─────────────────────────────────── */}
isEditMode && setSelectedId(null)} >
{/* 中心工业总成图 */}
{/* 角标 */}
Central Assembly System {/* 编辑模式标注 */} {isEditMode && (
双击替换图片
)}
{/* 底部组件导航 */}
e.stopPropagation()} > {parts.map((part, index) => ( setSelectedId(prev => prev === id ? null : id)} /> ))}
{/* 预览模式按钮 */} {!isEditMode && (
)}
{/* ── 页脚 ───────────────────────────────────────── */}
); }