@sw7d/paper-renderer 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1167 @@
1
+ # 试卷文档数据结构说明
2
+
3
+ 本文档详细解释 `@sw7d/paper-renderer` 保存/导出的 JSON 数据格式,供下游系统(批改、解析、渲染等)使用。
4
+
5
+ ---
6
+
7
+ ## 目录
8
+
9
+ 1. [顶层结构](#1-顶层结构)
10
+ 2. [info — 文档信息](#2-info--文档信息)
11
+ 3. [header — 页眉](#3-header--页眉)
12
+ 4. [body — 正文(核心)](#4-body--正文核心)
13
+ - [4.1 body.props — 页面配置](#41-bodyprops--页面配置)
14
+ - [4.2 body.children — 栏与内容](#42-bodychildren--栏与内容)
15
+ - [4.3 Question 节点](#43-question-节点)
16
+ - [4.4 内联元素(InlineNode)](#44-内联元素-inlinenode)
17
+ - [4.5 VuePlug 节点(题组标题)](#45-vueplug-节点题组标题)
18
+ 5. [footer — 页脚](#5-footer--页脚)
19
+ 6. [theme — 主题](#6-theme--主题)
20
+ 7. [styles — 样式](#7-styles--样式)
21
+ 8. [_pages — 页面坐标导出格式](#8-_pages--页面坐标导出格式)
22
+ 9. [完整示例](#9-完整示例)
23
+
24
+ ---
25
+
26
+ ## 1. 顶层结构
27
+
28
+ ```typescript
29
+ interface SwDocument {
30
+ info: DocInfo // 文档元信息
31
+ header: HeaderSection // 页眉(标题、学校、二维码等)
32
+ body: BodySection // 正文(所有题目内容)
33
+ footer: FooterSection // 页脚(页码、答题统计等)
34
+ theme: Theme // 颜色/字体/格式主题
35
+ styles: Styles // 默认样式
36
+ version: string // 文档格式版本,当前为 "1.3"
37
+ mode: number // 模式,通常为 1
38
+ lastUpdateTime: number // 最后更新时间戳(ms)
39
+
40
+ // 可选字段:由 save() 方法在序列化时追加,
41
+ // 包含每页的题目坐标数据,供批改系统直接使用
42
+ _pages?: PageExport[]
43
+ }
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 2. info — 文档信息
49
+
50
+ ```typescript
51
+ interface DocInfo {
52
+ author: string // 作者
53
+ created: string // 创建时间
54
+ modify: string // 修改时间
55
+ }
56
+ ```
57
+
58
+ > 当前序列化时 author/created/modify 均为空字符串 `""`,为占位保留字段。
59
+
60
+ ---
61
+
62
+ ## 3. header — 页眉
63
+
64
+ ```typescript
65
+ interface HeaderSection {
66
+ title: HeaderBlock // 首页页眉
67
+ titleEven: HeaderBlock // 偶数页(通常为首页)页眉
68
+ titleOdd: HeaderBlock // 奇数页(后续页)页眉
69
+ }
70
+
71
+ interface HeaderBlock {
72
+ type: 'header'
73
+ children: VuePlugNode[]
74
+ }
75
+ ```
76
+
77
+ 三个字段实际序列化时结构一致,均为包含 `VuePlugNode` 的数组。
78
+
79
+ ### titleEven(偶数页/首页页眉)
80
+
81
+ 包含一个 `name: 'titleEven'` 的 vueplug,其 `bind` 属性包含:
82
+
83
+ | bind 字段 | 类型 | 说明 |
84
+ |-----------|------|------|
85
+ | `title` | string | 试卷名称 |
86
+ | `headerInput` | string | 学校名称 |
87
+ | `qrCodeContent` | string | 二维码内容文本 |
88
+ | `qrCodeImage` | string | 二维码图片 base64 dataURL |
89
+ | `totalScore` | number | 试卷总分 |
90
+ | `hideHeaderDesc` | boolean | 是否隐藏学校信息行 |
91
+
92
+ ### titleOdd(奇数页/后续页页眉)
93
+
94
+ 包含一个 `name: 'titleOdd'` 的 vueplug,其 `bind` 包含:
95
+
96
+ | bind 字段 | 类型 | 说明 |
97
+ |-----------|------|------|
98
+ | `headerInput` | string | 页眉横线文本(通常为空) |
99
+ | `totalScore` | number | 总分(用于显示) |
100
+ | `hideHeaderDesc` | boolean | 是否隐藏 |
101
+
102
+ > 反序列化时从 `header` 中提取 `paperName`(title)、`schoolName`(headerInput)、`qrCodeContent`、`qrCodeImage`、`totalScore`。
103
+
104
+ ---
105
+
106
+ ## 4. body — 正文(核心)
107
+
108
+ ```typescript
109
+ interface BodySection {
110
+ type: 'document'
111
+ props: BodyProps // 页面全局配置
112
+ children: ColumnNode[] // 通常只有一个 ColumnNode
113
+ }
114
+ ```
115
+
116
+ ### 4.1 body.props — 页面配置
117
+
118
+ ```typescript
119
+ interface BodyProps {
120
+ paper: PaperConfig // 纸张全局配置
121
+ page: PageConfig // 内容区尺寸
122
+ grid: GridConfig // 网格线配置
123
+ background: BackgroundConfig // 背景色
124
+ }
125
+ ```
126
+
127
+ #### PaperConfig — 纸张配置
128
+
129
+ | 字段 | 类型 | 说明 |
130
+ |------|------|------|
131
+ | `type` | string | 纸张类型,如 `"A4"`、`"A3_2"`、`"8K_2"`、`"16K_2"`。`_N` 后缀表示分栏数 |
132
+ | `width` | number | 纸张宽度(px) |
133
+ | `height` | number | 纸张高度(px) |
134
+ | `width2mm` | number | 物理宽度(mm) |
135
+ | `height2mm` | number | 物理高度(mm) |
136
+ | `padding` | MarginConfig | 页边距 `{ top, right, bottom, left }`(px) |
137
+ | `point` | CornerPoints | 角标坐标 `{ tl, tr, bl, br }`,每个角标含 `{ top, left, width, height }` |
138
+ | `headerTop` | number | 页眉距页面顶部距离(px) |
139
+ | `footerBottom` | number | 页脚距页面顶部距离(px),当前固定为 `13.2` |
140
+ | `showScore` | boolean | 是否显示分数 |
141
+ | `fontSize` | number | 全局字号(px) |
142
+ | `lineSpacing` | number | 全局行距倍数 |
143
+ | `bodyTopEven` | number | 偶数页(首页)body 内容区 Y 偏移(px) |
144
+ | `bodyTopOdd` | number | 奇数页(后续页)body 内容区 Y 偏移(px) |
145
+
146
+ **纸张尺寸对照表:**
147
+
148
+ | 类型 | 宽度(px) | 高度(px) | 宽度(mm) | 高度(mm) |
149
+ |------|----------|----------|----------|----------|
150
+ | A4 | 793 | 1123 | 210 | 297 |
151
+ | A3 | 1587 | 1123 | 420 | 297 |
152
+ | 8K | 1085 | 1559 | 260 | 370 |
153
+ | 16K | 1092 | 779 | 260 | 184 |
154
+
155
+ > A3/16K 为横向试卷(宽 > 高)。
156
+
157
+ #### PageConfig — 内容区尺寸
158
+
159
+ ```typescript
160
+ interface PageConfig {
161
+ width: number // 内容区宽度 = 纸张宽 - 左右边距
162
+ height: number // 内容区高度 = 纸张高 - 上下边距
163
+ padding: MarginConfig // 通常为 { top:0, right:0, bottom:0, left:0 }
164
+ }
165
+ ```
166
+
167
+ #### GridConfig — 网格线
168
+
169
+ ```typescript
170
+ interface GridConfig {
171
+ type: 'line'
172
+ linePitch: number // 行间距,当前固定为 21.15(约 5.6mm)
173
+ }
174
+ ```
175
+
176
+ #### BackgroundConfig — 背景
177
+
178
+ ```typescript
179
+ interface BackgroundConfig {
180
+ solidFill: { color: Color }
181
+ }
182
+
183
+ interface Color {
184
+ colorType: string // 如 "rgb"
185
+ colorValue: string // 如 "7030A0"
186
+ }
187
+ ```
188
+
189
+ ---
190
+
191
+ ### 4.2 body.children — 栏与内容
192
+
193
+ ```typescript
194
+ interface ColumnNode {
195
+ type: 'column'
196
+ props: ColumnProps
197
+ children: ColumnChild[] // 实际内容:VuePlugNode | QuestionNode[]
198
+ }
199
+
200
+ interface ColumnProps {
201
+ cols: number // 分栏数 1/2/3
202
+ colspace: number // 栏间距(px)
203
+ stroke: string // 栏分隔线颜色,如 "#D1D3D4"
204
+ strokeWidth: number // 栏分隔线宽度
205
+ strokeDasharray: string // 栏分隔线虚线样式,如 "8,8"
206
+ }
207
+ ```
208
+
209
+ `children` 数组按顺序排列,包含两种节点类型:
210
+
211
+ 1. **VuePlugNode** — 题组标题(如"一、选择题")
212
+ 2. **QuestionNode** — 题目
213
+
214
+ > 文档始终只包含一个 ColumnNode。多栏通过 `props.cols` 控制,由渲染引擎自动排布。
215
+
216
+ ---
217
+
218
+ ### 4.3 Question 节点
219
+
220
+ ```typescript
221
+ interface QuestionNode {
222
+ type: 'question'
223
+ props: QuestionProps
224
+ children: (QuestionStemNode | OptionNode | CorrectionBoxNode | ParagraphNode)[]
225
+ }
226
+ ```
227
+
228
+ #### QuestionProps — 题目属性
229
+
230
+ | 字段 | 类型 | 说明 |
231
+ |------|------|------|
232
+ | `topicId` | string | 题目唯一 ID |
233
+ | `topicIndex` | string | 题号(如 `"1"`、`"2.1"`) |
234
+ | `padding` | `{ left: number, right: number }` | 缩进(左缩进,px) |
235
+ | `rect` | `{ height: number \| string }` | 题块高度(`""` 表示自适应) |
236
+ | `paddingBottom` | number | 下内边距(px),固定 2 |
237
+ | `showScore` | boolean | 是否显示分数 |
238
+ | `choiceMarkingType` | number | 选择题批改方式(2=单选,3=多选) |
239
+ | `fillBlankMarkingType` | number | 填空题批改方式,固定 8 |
240
+ | `answerQuestionMarkingType` | number | 问答题批改方式,固定 8 |
241
+ | `isLongScoreBar` | boolean | 是否为长分数条 |
242
+ | `split` | boolean | 是否允许跨栏/跨页拆分 |
243
+ | `width` | number | 题块宽度(px) |
244
+ | `isMaterial` | boolean | 是否为材料题 |
245
+ | `lastModifyTs` | number | 最后修改时间戳 |
246
+ | `smallTopicType` | `'SingleChoice' \| 'FillBlank' \| 'AnswerQuestion'` | 题目类型分类 |
247
+ | `hidden` | boolean | 是否隐藏 |
248
+ | `showTopicLabel` | boolean | 是否显示题号标签 |
249
+ | `topicLabel` | string | 题号标签文本 |
250
+ | `isAi` | boolean | 是否 AI 生成 |
251
+ | `smallTopicSplitColumn` | number | 小题目跨栏数 |
252
+ | `stemOnlyImages` | boolean | 题干是否仅含图片 |
253
+ | `createBySplit` | boolean | 是否由拆分创建 |
254
+ | `showAiTag` | boolean | 是否显示 AI 标签 |
255
+ | `qid` | string | 题库唯一 ID(从题库导入时保留,用于批改关联) |
256
+ | `keepNext` | boolean | 是否与下一块保持同行/同栏 |
257
+ | `blockQuestionType` | string | 题目类型(如 `"single_chose"`、`"fill_blank"`) |
258
+ | `blockMeta` | string | 完整的 metadata JSON 字符串(除已单独保存的字段外) |
259
+ | `blockHeight` | number | 手动拖拽调整后的题块高度(px) |
260
+
261
+ #### QuestionNode.children 结构
262
+
263
+ children 数组按顺序包含以下子节点:
264
+
265
+ 1. **question-stem** — 题干(必需)
266
+ 2. **option** — 选项(选择题特有)
267
+ 3. **correction-box** — 评分框(必需,在最后一个)
268
+
269
+ ##### 1. QuestionStemNode — 题干
270
+
271
+ ```typescript
272
+ interface QuestionStemNode {
273
+ type: 'question-stem'
274
+ props: {
275
+ split: boolean // 是否允许拆分
276
+ anchorOverflow: boolean // 锚点溢出处理
277
+ topicId: string // 题目 ID
278
+ }
279
+ children: (ParagraphNode | AnchorNode)[] // 段落列表
280
+ }
281
+ ```
282
+
283
+ ##### 2. OptionNode — 选择题选项
284
+
285
+ ```typescript
286
+ interface OptionNode {
287
+ type: 'option'
288
+ props: {
289
+ autoLayout: boolean // 是否自动布局
290
+ topicId: string
291
+ keepNext: boolean
292
+ }
293
+ children: OptionItemNode[]
294
+ }
295
+
296
+ interface OptionItemNode {
297
+ type: 'option-item'
298
+ props: {
299
+ labelCoord: { val: string } // 标签位置,如 "left"
300
+ label: string // 显示标签,如 "A."
301
+ oriLabel: string // 原始标签,如 "A"
302
+ index: number // 选项索引(0-based)
303
+ }
304
+ children: (ParagraphNode | AnchorNode)[] // 选项内容段落
305
+ }
306
+ ```
307
+
308
+ > 选项标签通常为 `A`、`B`、`C`、`D`,labels 格式为 `"A."`(带点)。
309
+
310
+ ##### 3. CorrectionBoxNode — 评分框
311
+
312
+ ```typescript
313
+ interface CorrectionBoxNode {
314
+ type: 'correction-box'
315
+ children: [{ type: 'text', text: string, props?: any }]
316
+ props: CorrectionBoxProps
317
+ }
318
+
319
+ interface CorrectionBoxProps {
320
+ rect: { height: number; width: number } // 评分框尺寸(px)
321
+ transform: { top: number; left: number } // 偏移位置(px)
322
+ score: number // 分数
323
+ keepNext: boolean
324
+ questionWidth: number // 题目宽度(px)
325
+ correctType: number // 批改类型
326
+ topicId: string
327
+ isLongScoreBar: boolean // 是否为长分数条
328
+ }
329
+ ```
330
+
331
+ ##### 4. ParagraphNode — 段落
332
+
333
+ ```typescript
334
+ interface ParagraphNode {
335
+ type: 'paragraph'
336
+ props: ParagraphProps
337
+ children: InlineNode[] // 内联元素列表
338
+ }
339
+
340
+ interface ParagraphProps {
341
+ justification?: string // 对齐方式:'left' | 'center' | 'right'
342
+ split?: boolean // 是否允许跨页拆分
343
+ spacing: { // 行间距
344
+ line: number // 行高值(px)
345
+ lineRule?: string // 行距规则,如 "exact"
346
+ }
347
+ hidden?: boolean // 是否隐藏
348
+ name?: string // 段落名称
349
+ }
350
+ ```
351
+
352
+ ---
353
+
354
+ ### 4.4 内联元素(InlineNode)
355
+
356
+ 内联元素是段落内的最小单位。支持以下类型:
357
+
358
+ #### 4.4.1 TextNode — 文本
359
+
360
+ ```typescript
361
+ {
362
+ type: 'text',
363
+ text: string, // 文本内容
364
+ props: {
365
+ fontSize: number, // 字号(px)
366
+ runfonts: {
367
+ ascii?: string, // ASCII 字体,如 "Times New Roman"
368
+ eastAsia?: string, // 东亚字体,如 "宋体"
369
+ hint?: string // 字体提示,如 "eastAsia"
370
+ },
371
+ color?: { val: string }, // 颜色,如 "#FF0000"
372
+ bold?: string, // 粗体,值为 "bold" 时启用
373
+ italic?: string, // 斜体,值为 "italic" 时启用
374
+ dotAbove?: boolean, // 加点字
375
+ wavyLine?: boolean, // 波浪线
376
+ verticalAlign?: number, // 垂直偏移(正=下移,负=上移),用于上下标
377
+ fontFamily?: string, // CSS font-family
378
+ underline?: boolean, // 文本下划线
379
+ strikethrough?: boolean, // 删除线
380
+ backgroundColor?: string // 背景色/高亮色
381
+ }
382
+ }
383
+ ```
384
+
385
+ #### 4.4.2 LatexNode — LaTeX 公式
386
+
387
+ ```typescript
388
+ {
389
+ type: 'latex',
390
+ props: {
391
+ raw: string, // 原始 LaTeX 字符串,如 "50^{\\circ }"
392
+ fontSize: number // 字号(px)
393
+ },
394
+ value: string, // 同 props.raw
395
+ children: [{ type: 'text', text: string, props: any }]
396
+ }
397
+ ```
398
+
399
+ #### 4.4.3 MathmlNode — MathML 公式
400
+
401
+ ```typescript
402
+ {
403
+ type: 'mathml',
404
+ props: {
405
+ raw: string, // 原始 MathML XML 字符串
406
+ fontSize: number // 字号(px)
407
+ },
408
+ value: string, // 同 props.raw
409
+ children: [{ type: 'text', text: string, props: any }]
410
+ }
411
+ ```
412
+
413
+ > 公式优先使用 LatexNode。仅当 data-latex 为空时使用 MathmlNode(通过 data-mathml 解析)。
414
+
415
+ #### 4.4.4 UnderlineNode — 填空下划线
416
+
417
+ ```typescript
418
+ {
419
+ type: 'underline',
420
+ props: {
421
+ fontSize: number, // 字号,固定 16
422
+ topicId: string, // 所属题目 ID
423
+ rect: { width: number, height: number }, // 下划线尺寸
424
+ width: number, // 宽度(px)
425
+ verticalAlign: number, // 垂直偏移
426
+ index: number, // 填空序号(1-based)
427
+ split: boolean, // 是否允许折行拆分
428
+ minSplitWidth: number, // 最小拆分宽度(px),默认 37.8
429
+ minNewLineWidth: number, // 最小换行宽度(px),默认 32
430
+ isNoStemMode: boolean, // 是否非题干模式
431
+ showBlankIndex: boolean, // 是否显示空序号
432
+ blankCount: number, // 该题总空数
433
+ standardBlankIndex?: number, // 标准空序号
434
+ realIndex?: number, // 实际序号
435
+ placeholder?: string, // 占位文本,默认 "空"
436
+ isEmpty?: boolean, // 是否为空下划线
437
+ ulId?: string, // 下划线唯一 ID(保留选中状态)
438
+ blankType?: string, // 空白类型:'tiankong' | 'xuanze' | 'judge'
439
+ correctAnswer?: string // 标准答案
440
+ },
441
+ children: [{ type: 'text', text: string, props: any }]
442
+ }
443
+ ```
444
+
445
+ > ⚠️ **答案字段**:填空题的正确答案存储在 `correctAnswer` 属性中。批量批改时应从 `_pages` 导出格式的 `underlines[].correctAnswer` 读取。
446
+
447
+ #### 4.4.5 ImageNode — 图片
448
+
449
+ ```typescript
450
+ {
451
+ type: 'image',
452
+ props: {
453
+ src?: string, // 图片 URL 或 base64 dataURL
454
+ width?: number, // 宽度(px)
455
+ height?: number, // 高度(px)
456
+ rect?: { // 备用尺寸字段
457
+ width: number,
458
+ height: number
459
+ },
460
+ id?: string, // 图片唯一标识
461
+ rawHtml?: string // 原始 HTML(表格图片等,由前端 html2canvas 渲染为 dataURL)
462
+ }
463
+ }
464
+ ```
465
+
466
+ #### 4.4.6 ObjectFillNode — 涂卡区(选择题答题区)
467
+
468
+ ```typescript
469
+ {
470
+ type: 'object-fill',
471
+ props: {
472
+ rect: { width: number, height: number },
473
+ answerType?: string, // 答案类型
474
+ index?: number, // 序号
475
+ blankCount?: number // 空白数量
476
+ },
477
+ children: [{ type: 'text', text: string, props: any }]
478
+ }
479
+ ```
480
+
481
+ #### 4.4.7 HtabNode — 水平制表符
482
+
483
+ ```typescript
484
+ {
485
+ type: 'htab',
486
+ props: {
487
+ width?: number, // 宽度(px)
488
+ tabWidth?: number // 制表符宽度
489
+ }
490
+ }
491
+ ```
492
+
493
+ #### 4.4.8 QuestionScoreNode — 分数节点
494
+
495
+ ```typescript
496
+ {
497
+ type: 'question-score',
498
+ props: {
499
+ fontSize: number,
500
+ score: number,
501
+ showScore: boolean,
502
+ disableEdit: boolean,
503
+ rect: { width: number, height: number }
504
+ }
505
+ }
506
+ ```
507
+
508
+ > 分数节点位于题干第一个段落的首部,渲染为 "(3分)" 格式。
509
+
510
+ #### 4.4.9 PageNumberAlignNode — 页码
511
+
512
+ ```typescript
513
+ {
514
+ type: 'pagenumber-align',
515
+ props: {
516
+ justification: string, // 对齐:'left' | 'center' | 'right'
517
+ initialPageNum: number, // 起始页码
518
+ isShowTotalNumber: boolean // 是否显示总页数
519
+ },
520
+ children: [{ type: 'text', text: '/1234', props: { ... } }]
521
+ }
522
+ ```
523
+
524
+ #### 4.4.10 AnchorNode — 锚点
525
+
526
+ ```typescript
527
+ {
528
+ type: 'anchor',
529
+ props: {
530
+ transform: { top: number, left: number }, // 绝对位置
531
+ name: string, // 锚点名称
532
+ wrapMode?: 'none' | 'text-wrap', // 文字环绕模式
533
+ anchorAlign?: 'left' | 'right' // 水平对齐
534
+ },
535
+ children: any[] // 内部包含 vueplug 或其他内容
536
+ }
537
+ ```
538
+
539
+ ---
540
+
541
+ ### 4.5 VuePlug 节点(题组标题)
542
+
543
+ ```typescript
544
+ interface VuePlugNode {
545
+ type: 'vueplug'
546
+ children: [{ type: 'text', text: string, props?: any }]
547
+ props: VuePlugProps
548
+ }
549
+
550
+ interface VuePlugProps {
551
+ id: string // 唯一 ID
552
+ name: string // 组件名,如 'title'、'titleEven'、'titleOdd'、'tail'
553
+ topicTitleType?: string // 题组标题类型
554
+ keepNext?: boolean // 与下一块保持同行/同栏
555
+ rect: { height: number } // 高度(px)
556
+ bind?: Record<string, any> // 绑定数据
557
+ controllerVisible?: boolean // 控制器可见性
558
+ }
559
+ ```
560
+
561
+ **题组标题的 bind 数据:**
562
+
563
+ | bind 字段 | 类型 | 说明 |
564
+ |-----------|------|------|
565
+ | `upperIndex` | string | 上级索引 |
566
+ | `scoringMode` | number | 计分模式 |
567
+ | `showScore` | boolean | 是否显示分数 |
568
+ | `score` | number | 该题组总分 |
569
+ | `title` | string | 完整标题(如 "一、选择题(每题2分)") |
570
+ | `type` | string | 类型,如 "normal" |
571
+ | `topicTitle` | string | 题组标题(如 "一、选择题") |
572
+ | `topicGroupInfo` | string | 题组附加信息 |
573
+ | `hide` | boolean | 是否隐藏 |
574
+ | `showTitleAITips` | boolean | 是否显示 AI 提示 |
575
+
576
+ ---
577
+
578
+ ## 5. footer — 页脚
579
+
580
+ ```typescript
581
+ interface FooterSection {
582
+ pageIndexRight: FooterBlock // 右页(通常为奇数页)页脚
583
+ pageIndexLeft: FooterBlock // 左页(通常为偶数页)页脚
584
+ }
585
+
586
+ interface FooterBlock {
587
+ type: 'footer'
588
+ children: (AnchorNode | ParagraphNode)[]
589
+ }
590
+ ```
591
+
592
+ 每个 FooterBlock 包含两个子节点:
593
+
594
+ 1. **AnchorNode** (`name: 'tailAnchor'`) — 包含一个 `name: 'tail'` 的 vueplug,其 bind 包含:
595
+
596
+ | bind 字段 | 类型 | 说明 |
597
+ |-----------|------|------|
598
+ | `enableAnsweringTime` | boolean | 是否启用答题时长统计 |
599
+ | `enableCorrectStat` | boolean | 是否启用正确率统计 |
600
+ | `answerConfigs` | `{ value: string, key: string }[]` | 答题时长选项列表 |
601
+
602
+ 2. **ParagraphNode** — 页码行,包含一个 `pagenumber-align` 节点,配置页码对齐方式和起始页。
603
+
604
+ ---
605
+
606
+ ## 6. theme — 主题
607
+
608
+ ```typescript
609
+ interface Theme {
610
+ clrScheme: ColorScheme // 配色方案
611
+ fmtScheme: FormatScheme // 格式方案
612
+ fontScheme: FontScheme // 字体方案
613
+ }
614
+
615
+ interface ColorScheme {
616
+ accent1: string, accent2: string, accent3: string,
617
+ accent4: string, accent5: string, accent6: string,
618
+ dk1: string, dk2: string,
619
+ folHlink: string, hlink: string,
620
+ lt1: string, lt2: string
621
+ }
622
+
623
+ interface FontScheme {
624
+ majorFont: FontDef // 主要字体
625
+ minorFont: FontDef // 次要字体
626
+ }
627
+
628
+ interface FontDef {
629
+ cs: string
630
+ ea: string
631
+ font: Array<{ script: string; typeface: string }>
632
+ latin: string
633
+ }
634
+ ```
635
+
636
+ **默认值:**
637
+ - 强调色:`accent1=4472C4`, `accent2=ED7D31`, `accent3=A5A5A5`, ...
638
+ - 字体:主要字体 "等线 Light",次要字体 "等线"
639
+
640
+ ---
641
+
642
+ ## 7. styles — 样式
643
+
644
+ ```typescript
645
+ interface Styles {
646
+ docDefaults: {
647
+ textPropsDefault: {
648
+ runfonts: { hint: string } // 默认 "eastAsia"
649
+ }
650
+ }
651
+ }
652
+ ```
653
+
654
+ ---
655
+
656
+ ## 8. _pages — 页面坐标导出格式
657
+
658
+ `_pages` 是 `save()` 序列化时额外附加的字段(通过 `SerializeOptions.pages`),为下游批改系统提供每页的结构化坐标数据,无需查表或重新渲染。
659
+
660
+ > ✨ **批改系统应当使用 `_pages` 字段而非解析 body 树**,因为 `_pages` 包含了渲染后准确的像素坐标。
661
+
662
+ ```typescript
663
+ interface PageExport {
664
+ pageIndex: number // 页码(0-based)
665
+ pageWidth: number // 页面宽度(px)
666
+ pageHeight: number // 页面高度(px)
667
+ cornerMarks: { // 四个角标坐标
668
+ position: 'tl' | 'tr' | 'bl' | 'br'
669
+ bbox: BBox // [x, y, w, h] 绝对坐标
670
+ }[]
671
+ header?: Record<string, BBox> // 页眉区域坐标映射
672
+ sectionTitles?: { // 题组标题区域
673
+ label: string
674
+ bbox: BBox
675
+ }[]
676
+ questions: QuestionExport[] // 题目列表(按自然顺序排序)
677
+ footer?: {
678
+ pageNumber?: BBox // 页码区域坐标
679
+ }
680
+ }
681
+ ```
682
+
683
+ **BBox 格式:** `[x, y, width, height]` — 页面绝对像素坐标(左上角为原点),保留 2 位小数。
684
+
685
+ ### header 区域
686
+
687
+ | key | 类型 | 说明 |
688
+ |-----|------|------|
689
+ | `headerDesc` | BBox | 学校信息行 |
690
+ | `paperName` | BBox | 试卷名称 |
691
+ | `qrCode` | BBox | 二维码 |
692
+ | `studentName` | BBox | 姓名行 |
693
+ | `studentClass` | BBox | 班级行 |
694
+ | `studentCode` | BBox | 准考证号行 |
695
+ | `score` | BBox | 总分(可能缺失,由 `showScore` 控制) |
696
+
697
+ ### QuestionExport — 题目导出格式
698
+
699
+ ```typescript
700
+ interface QuestionExport {
701
+ topicId: string // 题目唯一 ID
702
+ qid?: string // 题库 ID(从题库导入时保留)
703
+ questionNo: string // 题号,如 "1"、"2.1"
704
+ questionType: 'choice' | 'fill' | 'answer' // 题目类型
705
+ sortIndex: number // 排序索引(按 blocks 自然顺序)
706
+ bbox: BBox // 题块边框坐标(首个片段)
707
+ bboxes?: BBox[] // 多片段(跨栏/跨页)时的所有边框坐标
708
+ score?: number // 分数
709
+ parentTopicId?: string // 父题 ID(子题时存在)
710
+ hasSubQuestions?: boolean // 是否包含子题
711
+ underlines?: UnderlineExport[] // 填空题下划线列表(含答案)
712
+ isCrossPage?: boolean // 是否跨页
713
+ answer?: string // 整题答案(JSON 导入时存储)
714
+ }
715
+ ```
716
+
717
+ ### UnderlineExport — 填空下划线导出格式
718
+
719
+ ```typescript
720
+ interface UnderlineExport {
721
+ bbox: BBox // 下划线区域坐标
722
+ correctAnswer?: string // 标准答案
723
+ blankType?: string // 空白类型:'tiankong' | 'xuanze' | 'judge'
724
+ index?: number // 填空序号
725
+ underlineId?: string // 逻辑空白唯一 ID(折行片段共享同一 ID)
726
+ isSplitPart?: boolean // 是否为折行拆分后的后续段
727
+ }
728
+ ```
729
+
730
+ ### RenderedRegion 类型说明
731
+
732
+ `_pages` 的数据来源于 `renderedRegions`,所有区域类型如下:
733
+
734
+ | type | 说明 | 位置 |
735
+ |------|------|------|
736
+ | `header-desc` | 学校信息行 | header |
737
+ | `paper-name` | 试卷标题 | header |
738
+ | `qr-code` | 二维码 | header |
739
+ | `student-name` | 姓名行 | header |
740
+ | `student-class` | 班级行 | header |
741
+ | `student-code` | 准考证号行 | header |
742
+ | `score` | 分数 | header |
743
+ | `page-number` | 页码 | footer |
744
+ | `correction-box` | 评分框(每题) | 题块 |
745
+ | `title-embed` | 题组标题 | 题组 |
746
+ | `column-separator` | 栏分隔线 | - |
747
+ | `question-border` | 题块边框 | 题块 |
748
+ | `underline` | 填空下划线 | 题块 |
749
+
750
+ ---
751
+
752
+ ## 9. 完整示例
753
+
754
+ ```json
755
+ {
756
+ "info": {
757
+ "author": "",
758
+ "created": "",
759
+ "modify": ""
760
+ },
761
+ "header": {
762
+ "title": {
763
+ "type": "header",
764
+ "children": [
765
+ {
766
+ "type": "vueplug",
767
+ "children": [{ "type": "text", "props": {}, "text": "" }],
768
+ "props": {
769
+ "id": "poielxmwjdlsnmfmw",
770
+ "name": "title",
771
+ "rect": { "height": 100 },
772
+ "bind": { "input": "2024-2025学年第一学期期末考试" }
773
+ }
774
+ }
775
+ ]
776
+ },
777
+ "titleEven": {
778
+ "type": "header",
779
+ "children": [
780
+ {
781
+ "type": "vueplug",
782
+ "children": [{ "type": "text", "text": "" }],
783
+ "props": {
784
+ "id": "header-even",
785
+ "name": "titleEven",
786
+ "rect": { "height": 155 },
787
+ "bind": {
788
+ "title": "2024-2025学年第一学期期末考试",
789
+ "headerInput": "阳光中学",
790
+ "qrCodeContent": "https://example.com/paper/123",
791
+ "qrCodeImage": "data:image/png;base64,...",
792
+ "totalScore": 100,
793
+ "hideHeaderDesc": false
794
+ }
795
+ }
796
+ }
797
+ ]
798
+ },
799
+ "titleOdd": {
800
+ "type": "header",
801
+ "children": [
802
+ {
803
+ "type": "vueplug",
804
+ "children": [{ "type": "text", "text": "" }],
805
+ "props": {
806
+ "id": "header-odd",
807
+ "name": "titleOdd",
808
+ "rect": { "height": 30 },
809
+ "bind": {
810
+ "headerInput": "",
811
+ "totalScore": 100,
812
+ "hideHeaderDesc": false
813
+ }
814
+ }
815
+ }
816
+ ]
817
+ }
818
+ },
819
+ "body": {
820
+ "type": "document",
821
+ "props": {
822
+ "paper": {
823
+ "type": "A4",
824
+ "width": 793,
825
+ "height": 1123,
826
+ "width2mm": 210,
827
+ "height2mm": 297,
828
+ "padding": { "top": 50, "right": 56, "bottom": 50, "left": 56 },
829
+ "point": {
830
+ "tl": { "top": 26.46, "left": 26.46, "width": 26.46, "height": 13.23 },
831
+ "tr": { "top": 26.46, "left": 740.08, "width": 26.46, "height": 13.23 },
832
+ "bl": { "top": 1070.08, "left": 26.46, "width": 13.23, "height": 26.46 },
833
+ "br": { "top": 1070.08, "left": 753.31, "width": 13.23, "height": 26.46 }
834
+ },
835
+ "headerTop": 18,
836
+ "footerBottom": 13.2,
837
+ "showScore": true,
838
+ "fontSize": 14,
839
+ "lineSpacing": 1.5,
840
+ "bodyTopEven": 173,
841
+ "bodyTopOdd": 50
842
+ },
843
+ "page": {
844
+ "width": 681,
845
+ "height": 1023,
846
+ "padding": { "top": 0, "right": 0, "bottom": 0, "left": 0 }
847
+ },
848
+ "grid": { "type": "line", "linePitch": 21.15 },
849
+ "background": { "solidFill": { "color": { "colorType": "rgb", "colorValue": "7030A0" } } }
850
+ },
851
+ "children": [
852
+ {
853
+ "type": "column",
854
+ "props": {
855
+ "cols": 1,
856
+ "colspace": 0,
857
+ "stroke": "#D1D3D4",
858
+ "strokeWidth": 0.5,
859
+ "strokeDasharray": "8,8"
860
+ },
861
+ "children": [
862
+ {
863
+ "type": "vueplug",
864
+ "children": [{ "type": "text", "text": "" }],
865
+ "props": {
866
+ "id": "topicDesc-1718000000000",
867
+ "name": "title",
868
+ "topicTitleType": "undefined",
869
+ "keepNext": true,
870
+ "rect": { "height": 40 },
871
+ "bind": {
872
+ "upperIndex": "",
873
+ "scoringMode": 0,
874
+ "showScore": true,
875
+ "score": 20,
876
+ "title": "一、选择题(每题2分,共20分)",
877
+ "type": "normal",
878
+ "topicTitle": "一、选择题",
879
+ "topicGroupInfo": "",
880
+ "hide": false,
881
+ "showTitleAITips": false
882
+ }
883
+ }
884
+ },
885
+ {
886
+ "type": "question",
887
+ "props": {
888
+ "topicId": "topic-1",
889
+ "topicIndex": "1",
890
+ "padding": { "left": 17.5, "right": 0 },
891
+ "rect": { "height": "" },
892
+ "paddingBottom": 2,
893
+ "showScore": true,
894
+ "choiceMarkingType": 2,
895
+ "fillBlankMarkingType": 8,
896
+ "answerQuestionMarkingType": 8,
897
+ "isLongScoreBar": true,
898
+ "split": true,
899
+ "width": 681,
900
+ "isMaterial": false,
901
+ "lastModifyTs": 1718000000000,
902
+ "smallTopicType": "SingleChoice",
903
+ "hidden": false,
904
+ "showTopicLabel": false,
905
+ "topicLabel": "",
906
+ "isAi": false,
907
+ "smallTopicSplitColumn": 1,
908
+ "qid": "qb-12345",
909
+ "keepNext": false,
910
+ "blockQuestionType": "single_chose",
911
+ "blockMeta": "{\"answer\":\"A\"}"
912
+ },
913
+ "children": [
914
+ {
915
+ "type": "question-stem",
916
+ "props": { "split": true, "anchorOverflow": false, "topicId": "topic-1" },
917
+ "children": [
918
+ {
919
+ "type": "paragraph",
920
+ "props": {
921
+ "justification": "left",
922
+ "split": false,
923
+ "spacing": { "line": 14.834, "lineRule": "exact" }
924
+ },
925
+ "children": [
926
+ {
927
+ "type": "question-score",
928
+ "props": {
929
+ "fontSize": 14,
930
+ "score": 2,
931
+ "showScore": true,
932
+ "disableEdit": false,
933
+ "rect": { "width": 40, "height": 20 }
934
+ },
935
+ "children": [{ "type": "text", "text": "", "props": { "runfonts": { "hint": "eastAsia" }, "fontSize": 14 } }]
936
+ },
937
+ {
938
+ "type": "text",
939
+ "text": "地球绕太阳运动的轨道形状是?",
940
+ "props": {
941
+ "fontSize": 14,
942
+ "runfonts": { "ascii": "Times New Roman", "eastAsia": "宋体", "hint": "eastAsia" }
943
+ }
944
+ }
945
+ ]
946
+ }
947
+ ]
948
+ },
949
+ {
950
+ "type": "option",
951
+ "props": { "autoLayout": true, "topicId": "topic-1", "keepNext": false },
952
+ "children": [
953
+ {
954
+ "type": "option-item",
955
+ "props": { "labelCoord": { "val": "left" }, "label": "A.", "oriLabel": "A", "index": 0 },
956
+ "children": [
957
+ {
958
+ "type": "paragraph",
959
+ "props": { "justification": "left", "split": false, "spacing": { "line": 14.834, "lineRule": "exact" } },
960
+ "children": [
961
+ {
962
+ "type": "text",
963
+ "text": "圆形",
964
+ "props": { "fontSize": 14, "runfonts": { "ascii": "Times New Roman", "eastAsia": "宋体", "hint": "eastAsia" } }
965
+ }
966
+ ]
967
+ }
968
+ ]
969
+ },
970
+ {
971
+ "type": "option-item",
972
+ "props": { "labelCoord": { "val": "left" }, "label": "B.", "oriLabel": "B", "index": 1 },
973
+ "children": [
974
+ {
975
+ "type": "paragraph",
976
+ "props": { "justification": "left", "split": false, "spacing": { "line": 14.834, "lineRule": "exact" } },
977
+ "children": [
978
+ {
979
+ "type": "text",
980
+ "text": "椭圆形",
981
+ "props": { "fontSize": 14, "runfonts": { "ascii": "Times New Roman", "eastAsia": "宋体", "hint": "eastAsia" } }
982
+ }
983
+ ]
984
+ }
985
+ ]
986
+ }
987
+ ]
988
+ },
989
+ {
990
+ "type": "correction-box",
991
+ "children": [{ "type": "text", "text": "" }],
992
+ "props": {
993
+ "rect": { "height": 19.65, "width": 130.35 },
994
+ "transform": { "top": 0, "left": 17.5 },
995
+ "score": 2,
996
+ "keepNext": false,
997
+ "questionWidth": 681,
998
+ "correctType": 8,
999
+ "topicId": "topic-1",
1000
+ "isLongScoreBar": true
1001
+ }
1002
+ }
1003
+ ]
1004
+ }
1005
+ ]
1006
+ }
1007
+ ]
1008
+ },
1009
+ "footer": {
1010
+ "pageIndexRight": {
1011
+ "type": "footer",
1012
+ "children": [
1013
+ {
1014
+ "type": "anchor",
1015
+ "props": { "transform": { "top": 0, "left": 0 }, "name": "tailAnchor" },
1016
+ "children": [
1017
+ {
1018
+ "type": "vueplug",
1019
+ "children": [{ "type": "text", "text": "" }],
1020
+ "props": {
1021
+ "id": "footer-tail-right",
1022
+ "name": "tail",
1023
+ "rect": { "height": 50 },
1024
+ "bind": {
1025
+ "enableAnsweringTime": false,
1026
+ "enableCorrectStat": false,
1027
+ "answerConfigs": [
1028
+ { "value": "10分钟以内", "key": "0" },
1029
+ { "value": "10-20分钟", "key": "10" },
1030
+ { "value": "20-30分钟", "key": "20" },
1031
+ { "value": ">30分钟", "key": "30" }
1032
+ ]
1033
+ },
1034
+ "controllerVisible": false
1035
+ }
1036
+ }
1037
+ ]
1038
+ },
1039
+ {
1040
+ "type": "paragraph",
1041
+ "props": { "hidden": false, "justification": "center", "name": "pageIndex", "spacing": { "line": 24 } },
1042
+ "children": [
1043
+ { "type": "text", "text": "", "props": { "fontSize": 12, "runfonts": {} } },
1044
+ {
1045
+ "type": "pagenumber-align",
1046
+ "props": { "justification": "right", "initialPageNum": 1, "isShowTotalNumber": true },
1047
+ "children": [{ "type": "text", "text": "/1234", "props": { "color": { "val": "#898989" }, "bold": "bold", "fontSize": 12 } }]
1048
+ },
1049
+ { "type": "text", "text": "", "props": { "fontSize": 12, "runfonts": {} } }
1050
+ ]
1051
+ }
1052
+ ]
1053
+ },
1054
+ "pageIndexLeft": {
1055
+ "type": "footer",
1056
+ "children": [
1057
+ {
1058
+ "type": "anchor",
1059
+ "props": { "transform": { "top": 0, "left": 0 }, "name": "tailAnchor" },
1060
+ "children": [
1061
+ {
1062
+ "type": "vueplug",
1063
+ "children": [{ "type": "text", "text": "" }],
1064
+ "props": {
1065
+ "id": "footer-tail-left",
1066
+ "name": "tail",
1067
+ "rect": { "height": 50 },
1068
+ "bind": {
1069
+ "enableAnsweringTime": false,
1070
+ "enableCorrectStat": false,
1071
+ "answerConfigs": [
1072
+ { "value": "10分钟以内", "key": "0" },
1073
+ { "value": "10-20分钟", "key": "10" },
1074
+ { "value": "20-30分钟", "key": "20" },
1075
+ { "value": ">30分钟", "key": "30" }
1076
+ ]
1077
+ },
1078
+ "controllerVisible": false
1079
+ }
1080
+ }
1081
+ ]
1082
+ },
1083
+ {
1084
+ "type": "paragraph",
1085
+ "props": { "hidden": false, "justification": "center", "name": "pageIndex", "spacing": { "line": 24 } },
1086
+ "children": [
1087
+ { "type": "text", "text": "", "props": { "fontSize": 12, "runfonts": {} } },
1088
+ {
1089
+ "type": "pagenumber-align",
1090
+ "props": { "justification": "left", "initialPageNum": 1, "isShowTotalNumber": true },
1091
+ "children": [{ "type": "text", "text": "/1234", "props": { "color": { "val": "#898989" }, "bold": "bold", "fontSize": 12 } }]
1092
+ },
1093
+ { "type": "text", "text": "", "props": { "fontSize": 12, "runfonts": {} } }
1094
+ ]
1095
+ }
1096
+ ]
1097
+ }
1098
+ },
1099
+ "theme": {
1100
+ "clrScheme": {
1101
+ "accent1": "4472C4", "accent2": "ED7D31", "accent3": "A5A5A5",
1102
+ "accent4": "FFC000", "accent5": "5B9BD5", "accent6": "70AD47",
1103
+ "dk1": "000000", "dk2": "44546A", "folHlink": "954F72",
1104
+ "hlink": "0563C1", "lt1": "FFFFFF", "lt2": "E7E6E6"
1105
+ },
1106
+ "fmtScheme": {
1107
+ "bgFillStyleList": [{ "solidFill": { "color": { "colorType": "scheme", "colorValue": "lt1" } } }],
1108
+ "effectStyleList": [{ "effectStyle": { "effectList": { "noEffect": 1 } } }],
1109
+ "fillStyleList": [{ "solidFill": { "color": { "colorType": "scheme", "colorValue": "dk1" } } }],
1110
+ "outlineStyleList": [{
1111
+ "cap": "flat", "cmpd": "sng", "lineJoin": "miter",
1112
+ "solidFill": { "color": { "colorType": "scheme", "colorValue": "accent1" } },
1113
+ "style": "solid", "width": 1
1114
+ }]
1115
+ },
1116
+ "fontScheme": {
1117
+ "majorFont": { "cs": "", "ea": "", "font": [{ "script": "Hans", "typeface": "等线 Light" }], "latin": "等线 Light" },
1118
+ "minorFont": { "cs": "", "ea": "", "font": [{ "script": "Hans", "typeface": "等线" }], "latin": "等线" }
1119
+ }
1120
+ },
1121
+ "styles": {
1122
+ "docDefaults": {
1123
+ "textPropsDefault": { "runfonts": { "hint": "eastAsia" } }
1124
+ }
1125
+ },
1126
+ "version": "1.3",
1127
+ "mode": 1,
1128
+ "lastUpdateTime": 1718000000000,
1129
+ "_pages": [
1130
+ {
1131
+ "pageIndex": 0,
1132
+ "pageWidth": 793,
1133
+ "pageHeight": 1123,
1134
+ "cornerMarks": [
1135
+ { "position": "tl", "bbox": [26.46, 26.46, 26.46, 13.23] },
1136
+ { "position": "tr", "bbox": [740.08, 26.46, 26.46, 13.23] },
1137
+ { "position": "bl", "bbox": [26.46, 1070.08, 13.23, 26.46] },
1138
+ { "position": "br", "bbox": [753.31, 1070.08, 13.23, 26.46] }
1139
+ ],
1140
+ "header": {
1141
+ "headerDesc": [56, 30, 681, 20],
1142
+ "paperName": [56, 55, 400, 24],
1143
+ "qrCode": [700, 25, 60, 60]
1144
+ },
1145
+ "sectionTitles": [
1146
+ { "label": "一、选择题", "bbox": [56, 173, 200, 40] }
1147
+ ],
1148
+ "questions": [
1149
+ {
1150
+ "topicId": "topic-1",
1151
+ "qid": "qb-12345",
1152
+ "questionNo": "1",
1153
+ "questionType": "choice",
1154
+ "sortIndex": 0,
1155
+ "bbox": [56, 213, 681, 120],
1156
+ "score": 2,
1157
+ "answer": "A",
1158
+ "underlines": []
1159
+ }
1160
+ ],
1161
+ "footer": {
1162
+ "pageNumber": [700, 1095, 40, 15]
1163
+ }
1164
+ }
1165
+ ]
1166
+ }
1167
+ ```