import { MemberNameWithStatus } from "./member-name-with-status" import { useFamily } from "@/context/family-context" interface RelationshipPathDisplayProps { path: string className?: string } /** * 显示关系路径,并为路径中的每个成员姓名添加状态标识 * 路径格式: "虞国栋 → 儿子(虞晓东) → 儿子(虞雨轩) → 女儿(虞诗语)" */ export function RelationshipPathDisplay({ path, className = "" }: RelationshipPathDisplayProps) { const { treeData } = useFamily() if (!path) return null // 解析路径字符串 // 格式: "起点名 → 关系(名字) → 关系(名字) → ..." const parts = path.split(' → ') return (
{parts.map((part, index) => { // 第一个部分是起点名字(没有关系前缀) if (index === 0) { const member = Object.values(treeData.members).find(m => m.fullName === part) return ( ) } // 其他部分格式: "关系(名字)" const match = part.match(/^(.+?)\((.+?)\)$/) if (match) { const [, relation, name] = match const member = Object.values(treeData.members).find(m => m.fullName === name) return ( {relation} ( ) ) } // 如果格式不匹配,直接显示原文 return {part} })}
) }