From 1fc3f82155edd9fafb51386a16c946580d8db3ee Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 28 Jun 2026 14:50:58 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84PRD=E5=AF=BC=E5=87=BA=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- aidocs/project_context.md | 1 - tools/docx/.gitignore | 2 - tools/docx/build-docx.mjs | 305 -------------------------------------- tools/docx/package.json | 13 -- 4 files changed, 321 deletions(-) delete mode 100644 tools/docx/.gitignore delete mode 100644 tools/docx/build-docx.mjs delete mode 100644 tools/docx/package.json diff --git a/aidocs/project_context.md b/aidocs/project_context.md index c3e7c4e..f6ac7b9 100644 --- a/aidocs/project_context.md +++ b/aidocs/project_context.md @@ -9,7 +9,6 @@ - PRD:`docs/PRD-艺术品可信溯源与认证系统.md`,覆盖用户端、后台、业务流程、权限安全、非功能需求、MVP 范围与待确认事项;已落实甲方决策并整体润色。 - 技术方案:`docs/技术方案-艺术品可信溯源与认证系统.md`,含技术栈选型、总体架构、模块划分、数据库设计与 ER 图、核心流程图、关键时序图、部署与安全(mermaid 绘图)。 -- PRD 导出工具:`tools/docx`(Node 脚本,将 PRD 转为商务风 docx,运行 `node build-docx.mjs` 生成)。 - 早期《技术设计-数据结构》草稿已并入技术方案第 5 章后删除。 - 项目已迁移至 `F:\NIXProject\artveris`(内部代号 artveris),保留完整 Git 历史。 diff --git a/tools/docx/.gitignore b/tools/docx/.gitignore deleted file mode 100644 index 504afef..0000000 --- a/tools/docx/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -package-lock.json diff --git a/tools/docx/build-docx.mjs b/tools/docx/build-docx.mjs deleted file mode 100644 index 6010771..0000000 --- a/tools/docx/build-docx.mjs +++ /dev/null @@ -1,305 +0,0 @@ -import { - Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, - WidthType, BorderStyle, AlignmentType, HeadingLevel, ShadingType, - PageNumber, Header, Footer, PageBreak, LevelFormat, - VerticalAlign, Bookmark, InternalHyperlink, PageReference, - TabStopType, LeaderType, -} from "docx"; -import * as fs from "fs"; - -const MD_PATH = "E:/Users/Administrator/Documents/YSP/docs/PRD-艺术品可信溯源与认证系统.md"; -const OUT_PATH = "E:/Users/Administrator/Documents/YSP/docs/PRD-艺术品可信溯源与认证系统.docx"; - -// ---------- 设计令牌(商务、简约、整洁) ---------- -const C = { - primary: "1F3864", // 主深蓝(章节标题 / 表头) - secondary: "2E5496", // 中蓝(小节标题 / 行内代码) - h4: "404040", // 深灰(子标题) - body: "262626", // 正文近黑 - zebra: "F4F7FC", // 表格斑马行浅蓝灰 - border: "C9C9C9", // 表格细边框 - subtle: "8A8A8A", // 页眉页脚浅灰 - codeBg: "F1F3F7", // 行内代码底色 - white: "FFFFFF", - coverSub: "595959", -}; -const FONT = { ascii: "Calibri", eastAsia: "微软雅黑", hAnsi: "Calibri" }; -const FONT_CODE = { ascii: "Consolas", eastAsia: "微软雅黑", hAnsi: "Consolas" }; - -// ---------- 行内解析(** 加粗 ** 与 `代码`) ---------- -function parseInline(text, opts = {}) { - const size = opts.size ?? 21; - const color = opts.color ?? C.body; - const baseBold = opts.bold ?? false; - const pieces = String(text).split(/(\*\*[^*]+\*\*|`[^`]+`)/g).filter((s) => s !== ""); - const runs = []; - for (const piece of pieces) { - if (/^\*\*[\s\S]+\*\*$/.test(piece)) { - runs.push(new TextRun({ text: piece.slice(2, -2), bold: true, color, size, font: FONT })); - } else if (/^`[\s\S]+`$/.test(piece)) { - runs.push(new TextRun({ - text: piece.slice(1, -1), font: FONT_CODE, color: C.secondary, size: size - 1, - shading: { type: ShadingType.CLEAR, color: "auto", fill: C.codeBg }, - })); - } else { - runs.push(new TextRun({ text: piece, bold: baseBold, color, size, font: FONT })); - } - } - if (runs.length === 0) runs.push(new TextRun({ text: "", font: FONT })); - return runs; -} - -// ---------- 块级构造器 ---------- -function heading(text, mdLevel, bookmarkId) { - const styleMap = { 2: HeadingLevel.HEADING_1, 3: HeadingLevel.HEADING_2, 4: HeadingLevel.HEADING_3 }; - const sizeMap = { 2: 30, 3: 25, 4: 22 }; - const colorMap = { 2: C.primary, 3: C.secondary, 4: C.h4 }; - const spacing = mdLevel === 2 ? { before: 360, after: 160 } - : mdLevel === 3 ? { before: 260, after: 100 } - : { before: 180, after: 70 }; - const run = new TextRun({ text, bold: true, color: colorMap[mdLevel], size: sizeMap[mdLevel], font: FONT }); - const children = bookmarkId - ? [new Bookmark({ id: bookmarkId, children: [run] })] - : [run]; - const opts = { heading: styleMap[mdLevel], spacing, keepNext: true, children }; - if (mdLevel === 2) opts.border = { bottom: { color: C.primary, size: 6, space: 6, style: BorderStyle.SINGLE } }; - return new Paragraph(opts); -} - -function para(text) { - return new Paragraph({ spacing: { after: 130, line: 340, lineRule: "auto" }, children: parseInline(text) }); -} - -function bulletItem(text) { - return new Paragraph({ - bullet: { level: 0 }, - indent: { left: 360, hanging: 230 }, - spacing: { after: 60, line: 320, lineRule: "auto" }, - children: parseInline(text), - }); -} - -function numberItem(text, ref) { - return new Paragraph({ - numbering: { reference: ref, level: 0 }, - spacing: { after: 60, line: 320, lineRule: "auto" }, - children: parseInline(text), - }); -} - -function tableBorders() { - const b = { style: BorderStyle.SINGLE, size: 4, color: C.border }; - return { top: b, bottom: b, left: b, right: b, insideHorizontal: b, insideVertical: b }; -} - -function buildTable(rows) { - const header = rows[0]; - const body = rows.slice(1); - const trs = []; - trs.push(new TableRow({ - tableHeader: true, - children: header.map((cell) => new TableCell({ - shading: { type: ShadingType.CLEAR, color: "auto", fill: C.primary }, - margins: { top: 60, bottom: 60, left: 110, right: 110 }, - verticalAlign: VerticalAlign.CENTER, - children: [new Paragraph({ children: [new TextRun({ text: cell, bold: true, color: C.white, size: 21, font: FONT })] })], - })), - })); - body.forEach((r, i) => { - const fill = i % 2 === 1 ? C.zebra : C.white; - trs.push(new TableRow({ - children: r.map((cell) => new TableCell({ - shading: { type: ShadingType.CLEAR, color: "auto", fill }, - margins: { top: 50, bottom: 50, left: 110, right: 110 }, - verticalAlign: VerticalAlign.CENTER, - children: [new Paragraph({ spacing: { line: 290, lineRule: "auto" }, children: parseInline(cell, { size: 20 }) })], - })), - })); - }); - return new Table({ width: { size: 100, type: WidthType.PERCENTAGE }, borders: tableBorders(), rows: trs }); -} - -// ---------- Markdown -> 块 ---------- -function parseBlocks(md) { - const lines = md.split(/\r?\n/); - const out = []; - const olRefs = []; - const tocEntries = []; - let i = 0; - let olCounter = 0; - let hCounter = 0; - while (i < lines.length) { - const line = lines[i]; - if (line.trim() === "") { i++; continue; } - - if (line.trim().startsWith("|")) { - const tbl = []; - while (i < lines.length && lines[i].trim().startsWith("|")) { tbl.push(lines[i]); i++; } - const rows = tbl.map((r) => r.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim())); - const dataRows = rows.filter((r) => !r.every((c) => /^:?-{2,}:?$/.test(c))); - if (dataRows.length > 0) out.push(buildTable(dataRows)); - continue; - } - - const h = line.match(/^(#{1,6})\s+(.*)$/); - if (h) { - const level = h[1].length; - if (level === 1) { i++; continue; } // 文档主标题已用于封面 - const mdLevel = Math.min(level, 4); - const text = h[2].trim(); - // 目录只收录 2、3 级标题(章 + 小节),并加书签供跳转与页码引用 - if (mdLevel === 2 || mdLevel === 3) { - const bookmarkId = `_h${hCounter++}`; - tocEntries.push({ level: mdLevel, text, bookmarkId }); - out.push(heading(text, mdLevel, bookmarkId)); - } else { - out.push(heading(text, mdLevel)); - } - i++; continue; - } - - if (/^\d+\.\s+/.test(line)) { - const ref = `ol${olCounter++}`; - olRefs.push(ref); - while (i < lines.length && /^\d+\.\s+/.test(lines[i])) { - out.push(numberItem(lines[i].replace(/^\d+\.\s+/, ""), ref)); - i++; - } - continue; - } - - if (/^[-*]\s+/.test(line)) { - while (i < lines.length && /^[-*]\s+/.test(lines[i])) { - out.push(bulletItem(lines[i].replace(/^[-*]\s+/, ""))); - i++; - } - continue; - } - - if (/^>\s?/.test(line)) { - out.push(new Paragraph({ - spacing: { after: 130, line: 320, lineRule: "auto" }, - shading: { type: ShadingType.CLEAR, color: "auto", fill: C.zebra }, - border: { left: { color: C.secondary, size: 18, space: 14, style: BorderStyle.SINGLE } }, - children: parseInline(line.replace(/^>\s?/, ""), { color: C.h4 }), - })); - i++; continue; - } - - out.push(para(line)); - i++; - } - return { blocks: out, olRefs, tocEntries }; -} - -// ---------- 手动目录(实体文字 + 圆点引导线 + 页码域 + 可点击跳转) ---------- -function buildToc(entries) { - const TAB = 9600; // 右对齐页码的制表位位置(twips) - const paras = []; - for (const e of entries) { - const isChapter = e.level === 2; - const titleRun = new TextRun({ - text: e.text, - bold: isChapter, - size: isChapter ? 22 : 21, - color: isChapter ? C.primary : C.h4, - font: FONT, - }); - const pageRun = new PageReference(e.bookmarkId, { hyperlink: true }); - paras.push(new Paragraph({ - tabStops: [{ type: TabStopType.RIGHT, position: TAB, leader: LeaderType.DOT }], - indent: isChapter ? { left: 0 } : { left: 360 }, - spacing: { after: isChapter ? 80 : 50, before: isChapter ? 60 : 0, line: 300, lineRule: "auto" }, - children: [ - new InternalHyperlink({ anchor: e.bookmarkId, children: [titleRun] }), - new TextRun({ text: "\t", font: FONT }), - new TextRun({ children: [pageRun], size: isChapter ? 22 : 21, color: isChapter ? C.primary : C.h4, font: FONT }), - ], - })); - } - return paras; -} - -// ---------- 封面 ---------- -function blank(n) { - return Array.from({ length: n }, () => new Paragraph({ spacing: { after: 0 }, children: [new TextRun({ text: "", font: FONT })] })); -} -function cover() { - const now = new Date(); - const dateStr = `${now.getFullYear()} 年 ${now.getMonth() + 1} 月 ${now.getDate()} 日`; - return [ - ...blank(7), - new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 140 }, children: [new TextRun({ text: "艺术品可信溯源与认证系统", bold: true, size: 54, color: C.primary, font: FONT })] }), - new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 60 }, children: [new TextRun({ text: "产品需求文档(PRD)", size: 30, color: C.coverSub, font: FONT })] }), - new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 160, after: 160 }, border: { bottom: { color: C.secondary, size: 8, space: 10, style: BorderStyle.SINGLE } }, children: [new TextRun({ text: "", font: FONT })] }), - ...blank(9), - new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 70 }, children: [new TextRun({ text: "文档状态:待甲方确认", size: 24, color: C.h4, font: FONT })] }), - new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text: `编制日期:${dateStr}`, size: 24, color: C.h4, font: FONT })] }), - ]; -} - -// ---------- 组装文档 ---------- -const md = fs.readFileSync(MD_PATH, "utf8"); -const { blocks, olRefs, tocEntries } = parseBlocks(md); - -const numberingConfig = olRefs.map((ref) => ({ - reference: ref, - levels: [{ - level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.START, - style: { run: { font: FONT, color: C.body, size: 21 }, paragraph: { indent: { left: 510, hanging: 320 } } }, - }], -})); - -const pageHeader = new Header({ - children: [new Paragraph({ - alignment: AlignmentType.RIGHT, - border: { bottom: { color: C.border, size: 4, space: 4, style: BorderStyle.SINGLE } }, - children: [new TextRun({ text: "艺术品可信溯源与认证系统 · PRD", size: 17, color: C.subtle, font: FONT })], - })], -}); -const pageFooter = new Footer({ - children: [new Paragraph({ - alignment: AlignmentType.CENTER, - children: [ - new TextRun({ text: "第 ", size: 17, color: C.subtle, font: FONT }), - new TextRun({ children: [PageNumber.CURRENT], size: 17, color: C.subtle, font: FONT }), - new TextRun({ text: " 页 / 共 ", size: 17, color: C.subtle, font: FONT }), - new TextRun({ children: [PageNumber.TOTAL_PAGES], size: 17, color: C.subtle, font: FONT }), - new TextRun({ text: " 页", size: 17, color: C.subtle, font: FONT }), - ], - })], -}); - -const tocTitle = new Paragraph({ - spacing: { after: 200 }, - border: { bottom: { color: C.primary, size: 6, space: 6, style: BorderStyle.SINGLE } }, - children: [new TextRun({ text: "目 录", bold: true, size: 30, color: C.primary, font: FONT })], -}); -const tocParas = buildToc(tocEntries); - -const PAGE = { - size: { width: 11906, height: 16838 }, - margin: { top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 600 }, -}; - -const doc = new Document({ - creator: "产品团队", - title: "艺术品可信溯源与认证系统 PRD", - description: "艺术品可信溯源与认证系统产品需求文档", - features: { updateFields: true }, - styles: { default: { document: { run: { font: FONT, size: 21, color: C.body } } } }, - numbering: { config: numberingConfig }, - sections: [ - { properties: { page: PAGE }, children: cover() }, - { - properties: { page: { ...PAGE, pageNumbers: { start: 1 } } }, - headers: { default: pageHeader }, - footers: { default: pageFooter }, - children: [tocTitle, ...tocParas, new Paragraph({ children: [new PageBreak()] }), ...blocks], - }, - ], -}); - -const buf = await Packer.toBuffer(doc); -fs.writeFileSync(OUT_PATH, buf); -console.log("OK:", OUT_PATH, "bytes=", buf.length, "blocks=", blocks.length, "olRefs=", olRefs.length); diff --git a/tools/docx/package.json b/tools/docx/package.json deleted file mode 100644 index 7c7950e..0000000 --- a/tools/docx/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "prd-docx-export", - "private": true, - "type": "module", - "version": "1.0.0", - "description": "Generate a business-styled DOCX from the PRD markdown", - "scripts": { - "build": "node build-docx.mjs" - }, - "dependencies": { - "docx": "^9.7.1" - } -}