import React from "react"; interface BaseProperty { label: string; value: string | number; unit?: string; formatter?: (value: string | number) => string; } // 新增:表格型属性(用于二级数据) interface TableProperty { type: "table"; label: string; columns: string[]; // 表头 rows: (string | number)[][]; // 每行的数据 } type PropertyItem = BaseProperty | TableProperty; interface PropertyPanelProps { id?: string; type?: string; properties?: PropertyItem[]; } const PropertyPanel: React.FC = ({ id, type = "未知类型", properties = [], }) => { const formatValue = (property: BaseProperty) => { if (property.formatter) { return property.formatter(property.value); } if (property.unit) { return `${property.value} ${property.unit}`; } return property.value; }; const isImportantKeys = ["ID", "类型", "Name", "面积", "长度"]; // 统计属性数量(表格型按行数计入) const totalProps = id ? 2 + properties.reduce((sum, p) => { if ("type" in p && p.type === "table") return sum + p.rows.length; return sum + 1; }, 0) : 0; return (
{/* 头部 */}

属性面板

{/* 内容区域 */}
{!id ? (

暂无属性信息

请选择一个要素以查看其属性

) : (
{/* ID 属性 */}
ID {id}
{/* 类型属性 */}
类型 {type}
{/* 其他属性(包含二级表格) */} {properties.map((property, index) => { // 二级表格 if ("type" in property && property.type === "table") { return (
{property.label}
{property.columns.map((col, ci) => ( ))} {property.rows.map((row, ri) => ( {row.map((cell, cci) => ( ))} ))}
{col}
{cell}
); } // 普通属性 const base = property as BaseProperty; const isImportant = isImportantKeys.includes(base.label); return (
{base.label} {formatValue(base)}
); })}
)}
{/* 底部统计区域 */}
共 {totalProps} 个属性 {id && ( 已选中 )}
); }; export default PropertyPanel;