@tongfun/ui 0.0.1-alpha.3 → 0.0.1-alpha.5

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,748 @@
1
+ # Golden Example: 新建单据页
2
+
3
+ ## 场景
4
+
5
+ 用于采购合同、销售订单、费用报销、入库单、付款申请等标准 BOS 单据创建页面。这个示例要求保持 `NewDocumentDemo.vue` 的企业后台单据风格:左侧是单据目录和完成进度,右侧是多个 `TfCard` 表单分区,点击目录可平滑定位到对应卡片。
6
+
7
+ 本示例只保留基础功能链路:
8
+
9
+ - 左侧单据目录。
10
+ - 左侧总进度 / 必填进度。
11
+ - 右侧 `TfCard` 分区。
12
+ - 目录点击与右侧卡片滚动联动。
13
+ - 校验失败时定位到第一个未完成分区,并短暂高亮。
14
+
15
+ ## Generation Contract
16
+
17
+ Agent 生成 `new-document` 页面时必须遵守以下机器可读 contract。平台可以从 `@tongfun/ui/skill.json` 读取同结构配置;Markdown 中保留这一份是为了让模型直接阅读示例时也不会退化成普通表单页。
18
+
19
+ ```json
20
+ {
21
+ "id": "new-document",
22
+ "title": "新建单据页面",
23
+ "intent": {
24
+ "keywords": [
25
+ "单据",
26
+ "新建单据",
27
+ "新增单据",
28
+ "创建单据",
29
+ "合同",
30
+ "采购合同",
31
+ "销售合同",
32
+ "采购单",
33
+ "销售单",
34
+ "付款申请",
35
+ "报销",
36
+ "document",
37
+ "bill",
38
+ "contract"
39
+ ]
40
+ },
41
+ "generationContract": {
42
+ "requiredComponents": [
43
+ "TfPageHeader",
44
+ "TfSidebarLayout",
45
+ "TfSideNav",
46
+ "TfProgress",
47
+ "TfStack",
48
+ "TfCard",
49
+ "TfForm",
50
+ "TfFormLayout"
51
+ ],
52
+ "recommendedComponents": [
53
+ "TfFormInput",
54
+ "TfFormSelect",
55
+ "TfFormDatePicker",
56
+ "TfFormTextarea",
57
+ "TfButton",
58
+ "TfAlert",
59
+ "TfTag"
60
+ ],
61
+ "minimumComponents": {
62
+ "TfCard": 3
63
+ },
64
+ "layoutMustInclude": [
65
+ "left-sidebar-progress-navigation",
66
+ "right-multi-section-cards"
67
+ ],
68
+ "forbiddenStructures": [
69
+ "plain-single-card-form",
70
+ "single-section-large-form",
71
+ "marketing-hero-layout"
72
+ ],
73
+ "requiredBehaviors": [
74
+ "section-navigation-scroll",
75
+ "section-progress",
76
+ "required-field-progress",
77
+ "validate-before-save",
78
+ "validation-failure-scroll-to-first-invalid-section"
79
+ ],
80
+ "stateModel": [
81
+ "form",
82
+ "sections",
83
+ "activeSection",
84
+ "sideNavItems",
85
+ "totalProgress",
86
+ "requiredProgress",
87
+ "saving",
88
+ "notice"
89
+ ]
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## 推荐结构
95
+
96
+ 1. `TfPageHeader`:页面标题、单据编号、返回、暂存、提交。
97
+ 2. `TfAlert`:页面提示或校验反馈。
98
+ 3. `TfSidebarLayout`:形成左目录 + 右内容的单据布局。
99
+ 4. 左侧 `TfCard` + `TfProgress`:展示总进度和必填进度。
100
+ 5. 左侧 `TfSideNav`:展示单据目录、每个分区完成状态和百分比。
101
+ 6. 右侧 `TfStack`:纵向排列多个 `TfCard`。
102
+ 7. 每个分区 `TfCard` 必须有稳定 `id`,用于 `scrollIntoView`。
103
+ 8. 每个 `TfCard` 内部用 `TfFormLayout` + `TfFormXxx` 字段组件。
104
+
105
+ ## 推荐组件
106
+
107
+ - `TfPageHeader`
108
+ - `TfSidebarLayout`
109
+ - `TfSideNav`
110
+ - `TfCard`
111
+ - `TfProgress`
112
+ - `TfStack`
113
+ - `TfForm`
114
+ - `TfFormLayout`
115
+ - `TfFormInput`
116
+ - `TfFormSelect`
117
+ - `TfFormDatePicker`
118
+ - `TfFormTextarea`
119
+ - `TfButton`
120
+ - `TfAlert`
121
+ - `TfTag`
122
+
123
+ ## 可替换区域
124
+
125
+ - `sections` 可替换为当前业务对象的分区。
126
+ - `form` 可替换为当前实体字段模型。
127
+ - `requiredMap` 可由实体字段元数据自动生成。
128
+ - `TfCard` 内字段可由低代码平台拖入 `TfFormInput`、`TfFormSelect` 等字段组件。
129
+ - 保存、提交、AI 识别等按钮逻辑可在业务壳子里扩展。
130
+
131
+ ## 不建议改动区域
132
+
133
+ - 左侧目录 + 右侧卡片的整体布局。
134
+ - `section.id` 与右侧 `TfCard id` 一一对应。
135
+ - 目录点击必须只做定位,不要重新挂载右侧内容。
136
+ - 校验失败时必须定位到第一个缺失字段所在分区。
137
+ - 进度应由字段完成情况计算,不要写死。
138
+ - 不要把所有字段放在一个大卡片中。
139
+
140
+ ## 状态覆盖
141
+
142
+ - active:当前目录项。
143
+ - progress:总进度、必填进度、分区进度。
144
+ - pending:分区未开始。
145
+ - doing:分区部分完成。
146
+ - done:分区已完成。
147
+ - error:提交校验失败时高亮未完成分区。
148
+ - collapsed-summary:卡片折叠后展示关键摘要。
149
+ - disabled:保存/提交中禁用按钮和表单。
150
+
151
+ ## Vue SFC 示例代码
152
+
153
+ ```vue
154
+ <template>
155
+ <div class="space-y-3">
156
+ <TfPageHeader
157
+ title="新建采购合同"
158
+ subtitle="编号 CT-20260702-0001 · 版本 V0.1 · 建材采购标准合同"
159
+ description="按分区录入合同主数据、供应商、采购方、价格和交付条款"
160
+ bordered
161
+ >
162
+ <template #actions>
163
+ <TfButton :disabled="busy" @click="handleBack">返回</TfButton>
164
+ <TfButton :loading="saving" @click="handleSaveDraft">暂存</TfButton>
165
+ <TfButton type="primary" :loading="submitting" @click="handleSubmit">提交</TfButton>
166
+ </template>
167
+ </TfPageHeader>
168
+
169
+ <TfAlert
170
+ v-if="notice"
171
+ class="mb-3"
172
+ :type="notice.type"
173
+ :title="notice.title"
174
+ :description="notice.description"
175
+ closable
176
+ @close="notice = null"
177
+ />
178
+
179
+ <TfForm :model="form" :disabled="busy">
180
+ <TfSidebarLayout
181
+ surface="card"
182
+ surface-tone="white"
183
+ sidebar-width="208px"
184
+ gap="md"
185
+ :show-divider="false"
186
+ :show-surface-border="false"
187
+ :full-height="false"
188
+ sticky-sidebar
189
+ >
190
+ <template #sidebar>
191
+ <TfStack gap="sm">
192
+ <TfCard padding="sm" shadow="sm" radius="lg" title="完成进度">
193
+ <TfStack gap="xs">
194
+ <TfProgress
195
+ :percentage="totalProgress"
196
+ type="primary"
197
+ size="sm"
198
+ :format="() => `总进度 ${totalProgress}%`"
199
+ />
200
+ <TfProgress
201
+ :percentage="requiredProgress"
202
+ type="success"
203
+ size="sm"
204
+ :format="() => `必填进度 ${requiredProgress}%`"
205
+ />
206
+ </TfStack>
207
+ </TfCard>
208
+
209
+ <TfSideNav
210
+ :items="sideNavItems"
211
+ :model-value="activeSection"
212
+ title="单据目录"
213
+ @update:model-value="scrollToSection"
214
+ @select="item => scrollToSection(item.id)"
215
+ />
216
+ </TfStack>
217
+ </template>
218
+
219
+ <template #main>
220
+ <TfStack gap="md">
221
+ <TfCard
222
+ v-for="section in sections"
223
+ :id="section.id"
224
+ :key="section.id"
225
+ shadow="md"
226
+ compact
227
+ collapsible
228
+ radius="lg"
229
+ header-style="gradient"
230
+ :tone="cardTone(section.id)"
231
+ :collapsed-summary="section.summary()"
232
+ :class="{ 'tf-new-document-section--highlight': highlightedSection === section.id }"
233
+ >
234
+ <template #title>
235
+ <div class="flex flex-wrap items-center gap-2">
236
+ <span>{{ section.title }}</span>
237
+ <span :class="sectionMetaClass(section.id)">
238
+ {{ sectionHeader(section.id) }}
239
+ </span>
240
+ </div>
241
+ </template>
242
+
243
+ <template #actions>
244
+ <TfTag size="sm" variant="light" :type="sectionTagType(section.id)">
245
+ {{ sectionStatusText(section.id) }}
246
+ </TfTag>
247
+ </template>
248
+
249
+ <component :is="section.component" />
250
+ </TfCard>
251
+ </TfStack>
252
+ </template>
253
+ </TfSidebarLayout>
254
+ </TfForm>
255
+ </div>
256
+ </template>
257
+
258
+ <script setup lang="ts">
259
+ import { computed, defineComponent, h, nextTick, reactive, ref } from 'vue'
260
+ import {
261
+ TfAlert,
262
+ TfButton,
263
+ TfCard,
264
+ TfForm,
265
+ TfFormDatePicker,
266
+ TfFormInput,
267
+ TfFormLayout,
268
+ TfFormSelect,
269
+ TfFormTextarea,
270
+ TfPageHeader,
271
+ TfProgress,
272
+ TfSidebarLayout,
273
+ TfSideNav,
274
+ TfStack,
275
+ TfTag
276
+ } from '@tongfun/ui'
277
+
278
+ type NoticeType = 'info' | 'success' | 'warning' | 'error'
279
+ type SectionStatus = 'done' | 'doing' | 'pending' | 'error'
280
+ type SectionTone = 'success' | 'warning' | 'empty' | 'danger'
281
+ type CardTone = 'default' | 'primary' | 'success' | 'warning' | 'error'
282
+
283
+ interface Notice {
284
+ type: NoticeType
285
+ title: string
286
+ description: string
287
+ }
288
+
289
+ interface ContractForm {
290
+ contractName: string
291
+ contractCode: string
292
+ contractType: string
293
+ signDate: string
294
+ projectName: string
295
+ supplierName: string
296
+ supplierCredit: string
297
+ supplierContact: string
298
+ buyerName: string
299
+ purchaseOrg: string
300
+ buyerEmployee: string
301
+ currency: string
302
+ settlementCycle: string
303
+ invoiceType: string
304
+ priceMode: string
305
+ deliveryPlace: string
306
+ deliveryMethod: string
307
+ deliveryWindow: string
308
+ paymentTerms: string
309
+ }
310
+
311
+ type FormKey = keyof ContractForm
312
+
313
+ interface SectionRequiredField {
314
+ key: FormKey
315
+ label: string
316
+ }
317
+
318
+ interface SectionConfig {
319
+ id: string
320
+ title: string
321
+ description: string
322
+ requiredFields: SectionRequiredField[]
323
+ component: ReturnType<typeof defineComponent>
324
+ summary: () => { label: string; value: string }[]
325
+ }
326
+
327
+ const activeSection = ref('basic')
328
+ const highlightedSection = ref('')
329
+ const saving = ref(false)
330
+ const submitting = ref(false)
331
+ const notice = ref<Notice | null>({
332
+ type: 'info',
333
+ title: '单据已初始化',
334
+ description: '左侧目录会根据右侧卡片必填字段完成情况自动更新。'
335
+ })
336
+
337
+ const form = reactive<ContractForm>({
338
+ contractName: '',
339
+ contractCode: '',
340
+ contractType: '',
341
+ signDate: '',
342
+ projectName: '',
343
+ supplierName: '',
344
+ supplierCredit: '',
345
+ supplierContact: '',
346
+ buyerName: '',
347
+ purchaseOrg: '',
348
+ buyerEmployee: '',
349
+ currency: '',
350
+ settlementCycle: '',
351
+ invoiceType: '',
352
+ priceMode: '',
353
+ deliveryPlace: '',
354
+ deliveryMethod: '',
355
+ deliveryWindow: '',
356
+ paymentTerms: ''
357
+ })
358
+
359
+ const busy = computed(() => saving.value || submitting.value)
360
+
361
+ const contractTypeOptions = [
362
+ { label: '框架采购合同', value: 'framework' },
363
+ { label: '单次采购合同', value: 'single' },
364
+ { label: '补充协议', value: 'supplement' }
365
+ ]
366
+
367
+ const currencyOptions = [{ label: '人民币 CNY', value: 'CNY' }]
368
+ const settlementOptions = [
369
+ { label: '月结', value: 'monthly' },
370
+ { label: '按批次结算', value: 'batch' }
371
+ ]
372
+ const invoiceOptions = [
373
+ { label: '13% 增值税专票', value: 'vat13' },
374
+ { label: '普通发票', value: 'normal' }
375
+ ]
376
+ const priceModeOptions = [
377
+ { label: '浮动价', value: 'floating' },
378
+ { label: '固定单价', value: 'fixed' }
379
+ ]
380
+
381
+ const sections = computed<SectionConfig[]>(() => [
382
+ {
383
+ id: 'basic',
384
+ title: '基本信息',
385
+ description: '合同主数据、项目、签约日期等',
386
+ requiredFields: [
387
+ { key: 'contractName', label: '合同名称' },
388
+ { key: 'contractCode', label: '合同编号' },
389
+ { key: 'contractType', label: '合同类型' },
390
+ { key: 'signDate', label: '签约日期' },
391
+ { key: 'projectName', label: '项目名称' }
392
+ ],
393
+ component: BasicSection,
394
+ summary: () => [
395
+ { label: '合同', value: form.contractName },
396
+ { label: '编号', value: form.contractCode },
397
+ { label: '项目', value: form.projectName }
398
+ ]
399
+ },
400
+ {
401
+ id: 'supplier',
402
+ title: '供应商信息',
403
+ description: '供应单位资质与联系人',
404
+ requiredFields: [
405
+ { key: 'supplierName', label: '供应商名称' },
406
+ { key: 'supplierCredit', label: '统一社会信用代码' },
407
+ { key: 'supplierContact', label: '联系人' }
408
+ ],
409
+ component: SupplierSection,
410
+ summary: () => [
411
+ { label: '供应商', value: form.supplierName },
412
+ { label: '联系人', value: form.supplierContact }
413
+ ]
414
+ },
415
+ {
416
+ id: 'buyer',
417
+ title: '采购方信息',
418
+ description: '采购主体、组织与经办人',
419
+ requiredFields: [
420
+ { key: 'buyerName', label: '采购方名称' },
421
+ { key: 'purchaseOrg', label: '采购组织' },
422
+ { key: 'buyerEmployee', label: '采购员' }
423
+ ],
424
+ component: BuyerSection,
425
+ summary: () => [
426
+ { label: '采购方', value: form.buyerName },
427
+ { label: '采购员', value: form.buyerEmployee }
428
+ ]
429
+ },
430
+ {
431
+ id: 'pricing',
432
+ title: '价格结算',
433
+ description: '币种、发票、结算周期与价格机制',
434
+ requiredFields: [
435
+ { key: 'currency', label: '币种' },
436
+ { key: 'settlementCycle', label: '结算周期' },
437
+ { key: 'invoiceType', label: '发票类型' },
438
+ { key: 'priceMode', label: '价格模式' }
439
+ ],
440
+ component: PricingSection,
441
+ summary: () => [
442
+ { label: '币种', value: form.currency },
443
+ { label: '结算', value: form.settlementCycle }
444
+ ]
445
+ },
446
+ {
447
+ id: 'delivery',
448
+ title: '交付条款',
449
+ description: '交付地点、方式、窗口期',
450
+ requiredFields: [
451
+ { key: 'deliveryPlace', label: '交付地点' },
452
+ { key: 'deliveryMethod', label: '交付方式' },
453
+ { key: 'deliveryWindow', label: '交付窗口' }
454
+ ],
455
+ component: DeliverySection,
456
+ summary: () => [
457
+ { label: '地点', value: form.deliveryPlace },
458
+ { label: '方式', value: form.deliveryMethod }
459
+ ]
460
+ },
461
+ {
462
+ id: 'payment',
463
+ title: '付款条款',
464
+ description: '付款节点、发票校验、账期规则',
465
+ requiredFields: [
466
+ { key: 'paymentTerms', label: '付款条款' }
467
+ ],
468
+ component: PaymentSection,
469
+ summary: () => [
470
+ { label: '付款', value: form.paymentTerms }
471
+ ]
472
+ }
473
+ ])
474
+
475
+ const BasicSection = defineComponent({
476
+ name: 'BasicSection',
477
+ setup() {
478
+ return () => h(TfFormLayout, { columns: 6, density: 'compact' }, () => [
479
+ h(TfFormInput, { modelValue: form.contractName, 'onUpdate:modelValue': (value: string) => form.contractName = value, label: '合同名称', size: 'sm', required: true, span: 2 }),
480
+ h(TfFormInput, { modelValue: form.contractCode, 'onUpdate:modelValue': (value: string) => form.contractCode = value, label: '合同编号', size: 'sm', required: true }),
481
+ h(TfFormSelect, { modelValue: form.contractType, 'onUpdate:modelValue': (value: string) => form.contractType = value, label: '合同类型', options: contractTypeOptions, size: 'sm', required: true }),
482
+ h(TfFormDatePicker, { modelValue: form.signDate, 'onUpdate:modelValue': (value: string) => form.signDate = value, label: '签约日期', size: 'sm', required: true }),
483
+ h(TfFormInput, { modelValue: form.projectName, 'onUpdate:modelValue': (value: string) => form.projectName = value, label: '项目名称', size: 'sm', required: true, span: 2 })
484
+ ])
485
+ }
486
+ })
487
+
488
+ const SupplierSection = defineComponent({
489
+ name: 'SupplierSection',
490
+ setup() {
491
+ return () => h(TfFormLayout, { columns: 6, density: 'compact' }, () => [
492
+ h(TfFormInput, { modelValue: form.supplierName, 'onUpdate:modelValue': (value: string) => form.supplierName = value, label: '供应商名称', size: 'sm', required: true, span: 2 }),
493
+ h(TfFormInput, { modelValue: form.supplierCredit, 'onUpdate:modelValue': (value: string) => form.supplierCredit = value, label: '统一社会信用代码', size: 'sm', required: true }),
494
+ h(TfFormInput, { modelValue: form.supplierContact, 'onUpdate:modelValue': (value: string) => form.supplierContact = value, label: '联系人', size: 'sm', required: true })
495
+ ])
496
+ }
497
+ })
498
+
499
+ const BuyerSection = defineComponent({
500
+ name: 'BuyerSection',
501
+ setup() {
502
+ return () => h(TfFormLayout, { columns: 6, density: 'compact' }, () => [
503
+ h(TfFormInput, { modelValue: form.buyerName, 'onUpdate:modelValue': (value: string) => form.buyerName = value, label: '采购方名称', size: 'sm', required: true, span: 2 }),
504
+ h(TfFormInput, { modelValue: form.purchaseOrg, 'onUpdate:modelValue': (value: string) => form.purchaseOrg = value, label: '采购组织', size: 'sm', required: true }),
505
+ h(TfFormInput, { modelValue: form.buyerEmployee, 'onUpdate:modelValue': (value: string) => form.buyerEmployee = value, label: '采购员', size: 'sm', required: true })
506
+ ])
507
+ }
508
+ })
509
+
510
+ const PricingSection = defineComponent({
511
+ name: 'PricingSection',
512
+ setup() {
513
+ return () => h(TfFormLayout, { columns: 6, density: 'compact' }, () => [
514
+ h(TfFormSelect, { modelValue: form.currency, 'onUpdate:modelValue': (value: string) => form.currency = value, label: '币种', options: currencyOptions, size: 'sm', required: true }),
515
+ h(TfFormSelect, { modelValue: form.settlementCycle, 'onUpdate:modelValue': (value: string) => form.settlementCycle = value, label: '结算周期', options: settlementOptions, size: 'sm', required: true }),
516
+ h(TfFormSelect, { modelValue: form.invoiceType, 'onUpdate:modelValue': (value: string) => form.invoiceType = value, label: '发票类型', options: invoiceOptions, size: 'sm', required: true }),
517
+ h(TfFormSelect, { modelValue: form.priceMode, 'onUpdate:modelValue': (value: string) => form.priceMode = value, label: '价格模式', options: priceModeOptions, size: 'sm', required: true })
518
+ ])
519
+ }
520
+ })
521
+
522
+ const DeliverySection = defineComponent({
523
+ name: 'DeliverySection',
524
+ setup() {
525
+ return () => h(TfFormLayout, { columns: 6, density: 'compact' }, () => [
526
+ h(TfFormInput, { modelValue: form.deliveryPlace, 'onUpdate:modelValue': (value: string) => form.deliveryPlace = value, label: '交付地点', size: 'sm', required: true }),
527
+ h(TfFormInput, { modelValue: form.deliveryMethod, 'onUpdate:modelValue': (value: string) => form.deliveryMethod = value, label: '交付方式', size: 'sm', required: true }),
528
+ h(TfFormTextarea, { modelValue: form.deliveryWindow, 'onUpdate:modelValue': (value: string) => form.deliveryWindow = value, label: '交付窗口', size: 'sm', required: true, rows: 2, span: 'full' })
529
+ ])
530
+ }
531
+ })
532
+
533
+ const PaymentSection = defineComponent({
534
+ name: 'PaymentSection',
535
+ setup() {
536
+ return () => h(TfFormLayout, { columns: 1, density: 'compact' }, () => [
537
+ h(TfFormTextarea, { modelValue: form.paymentTerms, 'onUpdate:modelValue': (value: string) => form.paymentTerms = value, label: '付款条款', size: 'sm', required: true, rows: 3, span: 'full' })
538
+ ])
539
+ }
540
+ })
541
+
542
+ const sectionProgressMap = computed(() => {
543
+ const result: Record<string, { done: number; total: number; percent: number; status: SectionStatus }> = {}
544
+
545
+ for (const section of sections.value) {
546
+ const total = section.requiredFields.length
547
+ const done = section.requiredFields.filter(field => isFilled(form[field.key])).length
548
+ const percent = total ? Math.round(done / total * 100) : 100
549
+ const status: SectionStatus = highlightedSection.value === section.id && percent < 100
550
+ ? 'error'
551
+ : percent === 100
552
+ ? 'done'
553
+ : percent > 0
554
+ ? 'doing'
555
+ : 'pending'
556
+
557
+ result[section.id] = { done, total, percent, status }
558
+ }
559
+
560
+ return result
561
+ })
562
+
563
+ const sideNavItems = computed(() => sections.value.map(section => {
564
+ const progress = sectionProgress(section.id)
565
+ return {
566
+ id: section.id,
567
+ label: section.title,
568
+ status: progress.status,
569
+ percent: progress.percent,
570
+ highlighted: highlightedSection.value === section.id && progress.percent < 100
571
+ }
572
+ }))
573
+
574
+ const completedRequiredCount = computed(() => {
575
+ return Object.values(sectionProgressMap.value).reduce((sum, item) => sum + item.done, 0)
576
+ })
577
+
578
+ const totalRequiredCount = computed(() => {
579
+ return sections.value.reduce((sum, section) => sum + section.requiredFields.length, 0)
580
+ })
581
+
582
+ const requiredProgress = computed(() => {
583
+ if (!totalRequiredCount.value) return 100
584
+ return Math.round(completedRequiredCount.value / totalRequiredCount.value * 100)
585
+ })
586
+
587
+ const totalProgress = computed(() => {
588
+ return Math.min(100, Math.round(requiredProgress.value * 0.86 + 14))
589
+ })
590
+
591
+ function sectionProgress(id: string) {
592
+ return sectionProgressMap.value[id] || { done: 0, total: 0, percent: 100, status: 'done' as SectionStatus }
593
+ }
594
+
595
+ function sectionHeader(id: string) {
596
+ const progress = sectionProgress(id)
597
+ return progress.total ? `必填 ${progress.done}/${progress.total}` : '辅助信息'
598
+ }
599
+
600
+ function sectionTone(id: string): SectionTone {
601
+ const progress = sectionProgress(id)
602
+ if (highlightedSection.value === id && progress.percent < 100) return 'danger'
603
+ if (progress.percent === 100) return 'success'
604
+ if (progress.percent > 0) return 'warning'
605
+ return 'empty'
606
+ }
607
+
608
+ function cardTone(id: string): CardTone {
609
+ const tone = sectionTone(id)
610
+ if (tone === 'danger') return 'error'
611
+ if (tone === 'success') return 'success'
612
+ if (tone === 'warning') return 'warning'
613
+ return 'default'
614
+ }
615
+
616
+ function sectionTagType(id: string) {
617
+ const progress = sectionProgress(id)
618
+ if (progress.status === 'error') return 'danger'
619
+ if (progress.status === 'done') return 'success'
620
+ if (progress.status === 'doing') return 'warning'
621
+ return 'default'
622
+ }
623
+
624
+ function sectionStatusText(id: string) {
625
+ const progress = sectionProgress(id)
626
+ if (progress.status === 'error') return '待完善'
627
+ if (progress.status === 'done') return '已完成'
628
+ if (progress.status === 'doing') return '进行中'
629
+ return '未开始'
630
+ }
631
+
632
+ function sectionMetaClass(id: string) {
633
+ const tone = sectionTone(id)
634
+ const base = 'rounded-full border px-2 py-0.5 text-xs font-semibold'
635
+ if (tone === 'danger') return `${base} border-[var(--error-200)] bg-[var(--error-50)] text-[var(--tf-color-error)]`
636
+ if (tone === 'success') return `${base} border-[var(--success-200)] bg-[var(--success-50)] text-[var(--tf-color-success)]`
637
+ if (tone === 'warning') return `${base} border-[var(--warning-200)] bg-[var(--warning-50)] text-[var(--tf-color-warning)]`
638
+ return `${base} border-[var(--tf-color-border)] bg-[var(--neutral-50)] text-[var(--tf-color-text-secondary)]`
639
+ }
640
+
641
+ function isFilled(value: unknown) {
642
+ return value !== undefined && value !== null && String(value).trim() !== ''
643
+ }
644
+
645
+ function collectMissingItems() {
646
+ const missing: { sectionId: string; sectionTitle: string; fieldLabel: string }[] = []
647
+
648
+ for (const section of sections.value) {
649
+ for (const field of section.requiredFields) {
650
+ if (!isFilled(form[field.key])) {
651
+ missing.push({
652
+ sectionId: section.id,
653
+ sectionTitle: section.title,
654
+ fieldLabel: field.label
655
+ })
656
+ }
657
+ }
658
+ }
659
+
660
+ return missing
661
+ }
662
+
663
+ function scrollToSection(id: string, highlight = false) {
664
+ activeSection.value = id
665
+ if (highlight) highlightedSection.value = id
666
+
667
+ nextTick(() => {
668
+ document.getElementById(id)?.scrollIntoView({
669
+ behavior: 'smooth',
670
+ block: 'start'
671
+ })
672
+ })
673
+
674
+ if (highlight) {
675
+ window.setTimeout(() => {
676
+ if (highlightedSection.value === id) highlightedSection.value = ''
677
+ }, 2600)
678
+ }
679
+ }
680
+
681
+ function handleBack() {
682
+ notice.value = {
683
+ type: 'info',
684
+ title: '返回',
685
+ description: '业务项目中这里通常返回单据列表。'
686
+ }
687
+ }
688
+
689
+ async function handleSaveDraft() {
690
+ saving.value = true
691
+ try {
692
+ await new Promise(resolve => window.setTimeout(resolve, 500))
693
+ notice.value = {
694
+ type: 'success',
695
+ title: '暂存成功',
696
+ description: `当前必填进度 ${requiredProgress.value}%。`
697
+ }
698
+ } finally {
699
+ saving.value = false
700
+ }
701
+ }
702
+
703
+ async function handleSubmit() {
704
+ const missing = collectMissingItems()
705
+
706
+ if (missing.length) {
707
+ const first = missing[0]
708
+ notice.value = {
709
+ type: 'error',
710
+ title: `还有 ${missing.length} 项必填未完成`,
711
+ description: `请先完善“${first.sectionTitle} - ${first.fieldLabel}”。左侧目录已标红,并已自动定位到该分区。`
712
+ }
713
+ scrollToSection(first.sectionId, true)
714
+ return
715
+ }
716
+
717
+ submitting.value = true
718
+ try {
719
+ await new Promise(resolve => window.setTimeout(resolve, 600))
720
+ notice.value = {
721
+ type: 'success',
722
+ title: '提交成功',
723
+ description: '必填校验全部通过,单据已进入下一流程节点。'
724
+ }
725
+ } finally {
726
+ submitting.value = false
727
+ }
728
+ }
729
+ </script>
730
+
731
+ <style scoped>
732
+ .tf-new-document-section--highlight {
733
+ outline: 2px solid var(--tf-color-error);
734
+ outline-offset: 2px;
735
+ }
736
+ </style>
737
+ ```
738
+
739
+ ## 设计说明
740
+
741
+ - 这个示例完全围绕 `NewDocumentDemo.vue` 的核心布局:左侧目录和右侧分区卡片。
742
+ - 左侧目录的数据不手写状态,而是从右侧分区的必填字段完成度计算。
743
+ - `section.id` 是联动核心,必须同时用于 `TfSideNav.items[].id` 和右侧 `TfCard id`。
744
+ - 点击目录只滚动定位,不切换路由、不卸载卡片,避免表单状态丢失。
745
+ - 提交时先收集缺失字段,再定位到第一个未完成分区。
746
+ - 高亮只做短暂视觉提示,避免长期错误态干扰用户。
747
+ - `TfFormLayout` 使用紧凑密度和多列布局,保持企业后台单据页的信息密度。
748
+ - Tailwind 只用于布局和少量状态 class,颜色使用 `--tf-*` tokens。