import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useRef, useState } from "react"; import { ArrowLeft, ArrowUpRight, BookOpen, Braces, CalendarDays, CheckSquare, ChevronRight, FileText, GitBranch, Globe2, ListChecks, Link2, Pencil, Target, Trash2, } from "lucide-react"; import GuidanceShell from "@/components/GuidanceShell"; import { CopyButton, KindBadge, Notice, Tabs, kindNames, } from "@/components/GuidanceUI"; import { guidanceXml, type Guidance } from "@/content/guides/catalog"; import s from "@/styles/guidance.module.css"; export type ReadingVersion = { revision: number; createdAt?: string }; export type ReadingLink = Guidance["links"][number] & { resolved: boolean }; export type ReaderProps = { document: Guidance; source: "example" | "community"; links: ReadingLink[]; versions: ReadingVersion[]; backlinks?: { id: string; revision?: number; title: string; source?: "example" | "community"; }[]; canEdit?: boolean; withdrawn?: boolean; }; const relationNames = { guide: "可选指导", context: "背景参考", evidence: "事实依据", }; function dateLabel(value?: string) { return value ? new Intl.DateTimeFormat("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit", timeZone: "UTC", }).format(new Date(value)) : "协议样例"; } export default function GuidanceReader({ document: doc, source, links, versions, backlinks = [], canEdit = false, withdrawn = false, }: ReaderProps) { const router = useRouter(), dialog = useRef(null); const [tab, setTab] = useState("overview"), [busy, setBusy] = useState(false), [error, setError] = useState(""), [isWithdrawn, setWithdrawn] = useState(withdrawn); useEffect(() => { setWithdrawn(withdrawn); setError(""); setTab("overview"); }, [doc.id, withdrawn]); const api = `/api/${source === "example" ? "guides" : "documents"}/${doc.id}?revision=${doc.revision}&format=xml`; const current = versions.find((v) => v.revision === doc.revision), xml = guidanceXml(doc); const route = source === "example" ? "/guide/" : "/documents/"; const sectionLinks = [ ["applies", "适用条件"], ["content", "指导正文"], ...(doc.steps.length ? [["steps", "建议步骤"]] : []), ...(doc.checks.length ? [["checks", "完成检查"]] : []), ["related", "条件链接"], ]; async function withdraw() { setBusy(true); setError(""); try { const response = await fetch("/api/documents/" + doc.id, { method: "DELETE", }); const body = await response.json(); if (!response.ok) throw Error(body.error || "撤下失败,请稍后重试"); setWithdrawn(true); dialog.current?.close(); } catch (e) { setError(e instanceof Error ? e.message : "撤下失败,请稍后重试"); } finally { setBusy(false); } } return (
{source === "example" ? "返回探索文档" : "返回社区文档"}
{source === "example" ? "协议样例" : "社区发布"} v{doc.revision} {isWithdrawn && ( 已撤下 · 历史版本 )}

{doc.title}

{doc.summary}

公开文档 固定版本 {doc.revision} {current?.createdAt && ( {dateLabel(current.createdAt)} )}
window.location.origin + api} /> 读取规范 XML {canEdit && !isWithdrawn && ( 编辑最新版本 )}
{isWithdrawn && ( 这篇文档已从公开目录撤下。你正在阅读固定历史版本,已有引用仍可继续使用。 )}
{tab === "overview" ? (

何时使用这篇文档

{doc.applies}

指导正文

{doc.body}
{!!doc.steps.length && (

建议步骤

    {doc.steps.map((step, index) => (
  1. {step}
  2. ))}
)} {!!doc.checks.length && (

完成检查

    {doc.checks.map((check, index) => (
  • {check}
  • ))}
)}

本篇目录

采用这一篇

把固定版本的读取地址交给 Agent。关联文档是候选帮助,无需一起加载。

{api} window.location.origin + api} />
{!!backlinks.length && (

被这些文档引用

{backlinks.map((b) => ( {b.title} ))}
)}

撤下这篇文档?

它将不再出现在目录中。已发布的固定历史版本会保留,已有引用仍然可以访问。

{error && {error}}
); }