import Link from 'next/link'; import { ChevronRight } from 'lucide-react'; import { ManualTreeNav } from './ManualTreeNav'; import { ContentView } from './ContentView'; import type { Manual, ManualTreeNode } from '@/lib/types'; interface ManualLayoutProps { tree: ManualTreeNode[]; /** 当前文档(含正文);为 null 表示无选中 */ doc: Manual | null; } /** 扁平化树为「仅文档」节点,便于查找前一篇/后一篇 */ function flattenDocs(nodes: ManualTreeNode[]): { id: number; title: string }[] { const out: { id: number; title: string }[] = []; const walk = (list: ManualTreeNode[]) => { for (const n of list) { if (n.type === 1) out.push({ id: n.id, title: n.title }); if (n.children.length > 0) walk(n.children); } }; walk(nodes); return out; } /** 构建从根到当前节点的标题面包屑路径 */ function findPath( nodes: ManualTreeNode[], id: number, prefix: string[] = [], ): string[] | null { for (const n of nodes) { const path = [...prefix, n.title]; if (n.id === id) return path; if (n.children.length > 0) { const sub = findPath(n.children, id, path); if (sub) return sub; } } return null; } /** 使用手册左右布局外壳 */ export function ManualLayout({ tree, doc }: ManualLayoutProps) { const docs = flattenDocs(tree); const currentIndex = doc ? docs.findIndex((d) => d.id === doc.id) : -1; const prev = currentIndex > 0 ? docs[currentIndex - 1] : null; const next = currentIndex >= 0 && currentIndex < docs.length - 1 ? docs[currentIndex + 1] : null; const breadcrumb = doc ? findPath(tree, doc.id) : null; return (
{/* 左:树形菜单 */} {/* 右:正文 */}
{doc ? ( <> {breadcrumb && breadcrumb.length > 1 && ( )}

{doc.title}

{doc.content ? ( ) : (

本文档暂无内容

)} {/* 上一篇 / 下一篇 */} {(prev || next) && (
{prev ? ( 上一篇: {prev.title} ) : ( )} {next && ( 下一篇: {next.title} )}
)} ) : (

暂无可显示的文档,请从左侧菜单选择。

若有权限,可在后台「使用手册」中新增文档。

)}
); }