@skillre/dsh-plugin-work-dashboard 0.10.0 → 0.11.0

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.
package/lib/form.js CHANGED
@@ -42,6 +42,73 @@ export const G0_FIELDS = Object.freeze([
42
42
  'decision_chain',
43
43
  'post_poc_decision',
44
44
  ]);
45
+ /** The stage ids, local to keep the browser payload free of the frozen tuple. */
46
+ const STAGE_IDS = ['G0', 'G1', 'G2', 'G3', 'G4'];
47
+ /**
48
+ * Which sections each stage is about.
49
+ *
50
+ * Derived from the ledger's own structure rather than invented: `schemas/poc-schema.md`
51
+ * groups fields into ①identity ②gate0 ③plan ④progress ⑤outcome, each gate's
52
+ * verdict lives in its group, and the 16 gap rules judge by the same grouping
53
+ * (R1–R3 gate0, R4–R6 plan, R8–R10 progress, R11 outcome). So "G1 fills the plan"
54
+ * is the data model, not a convention this form invented.
55
+ */
56
+ const SECTIONS_FOR_STAGE = {
57
+ G0: ['identity', 'gate0'],
58
+ G1: ['plan', 'gate12'],
59
+ G2: ['plan', 'gate12', 'progress'],
60
+ G3: ['progress'],
61
+ G4: ['progress', 'outcome'],
62
+ };
63
+ /**
64
+ * The sections one intent may EDIT.
65
+ *
66
+ * `new` asks only for what a project needs to exist: identity plus the five G0
67
+ * prerequisites. It deliberately does not ask for a plan — gap rule R3 only
68
+ * demands a plan *after* G0 passes, so asking earlier pushes people to write a
69
+ * plan before they have thought one through, which R4/R5 then reject.
70
+ *
71
+ * `progress` edits nothing but the appended round: it is the highest-frequency
72
+ * form and must fit one screen.
73
+ */
74
+ const EDITABLE_FOR_INTENT = {
75
+ new: ['identity', 'gate0'],
76
+ supplement: ['identity', 'gate0', 'plan', 'gate12', 'progress', 'outcome'],
77
+ progress: ['progress'],
78
+ };
79
+ /**
80
+ * Resolve what a form should ask, given the intent and the project's stage.
81
+ *
82
+ * Returns the editable sections (the subject) and the context sections (shown
83
+ * read-only so the colleague knows what they are adding to). An unknown stage
84
+ * falls back to G0's set: a project whose stage is unrecognised is, for form
85
+ * purposes, still being set up.
86
+ */
87
+ export function resolveSections(intent, stage) {
88
+ const key = (STAGE_IDS.find((id) => stage === id || stage.startsWith(`${id}-`)) ?? 'G0');
89
+ const stageSections = SECTIONS_FOR_STAGE[key];
90
+ const allowed = EDITABLE_FOR_INTENT[intent];
91
+ if (intent === 'new' || intent === 'progress') {
92
+ const editable = allowed.filter((section) => section === 'identity' || section === 'gate0' || section === 'progress');
93
+ return { editable: [...editable], context: [] };
94
+ }
95
+ // `supplement` edits the current stage's subject, and shows only what came
96
+ // BEFORE it as read-only context — never a later stage, which has not
97
+ // happened yet. Showing a G4 project's empty conclusion block to someone
98
+ // filling in G1 invites them to invent a conclusion.
99
+ const editable = stageSections.filter((section) => allowed.includes(section));
100
+ const order = ['identity', 'gate0', 'plan', 'gate12', 'progress', 'outcome'];
101
+ const currentIndex = stageSections.length === 0 ? -1 : Math.max(...stageSections.map((section) => order.indexOf(section)));
102
+ const context = order.filter((section) => {
103
+ if (section === 'progress')
104
+ return false;
105
+ if (editable.includes(section))
106
+ return false;
107
+ // Only sections that precede the current stage's subject.
108
+ return order.indexOf(section) < currentIndex;
109
+ });
110
+ return { editable: [...editable], context };
111
+ }
45
112
  /** Coerce a stored value to the string the form edits. */
46
113
  function text(value) {
47
114
  if (value === null || value === undefined)
@@ -66,6 +133,7 @@ function dateText(value) {
66
133
  export function projectForForm(record) {
67
134
  const gate0 = record.gate0 ?? {};
68
135
  const plan = record.plan ?? {};
136
+ const outcome = record.outcome ?? {};
69
137
  const progress = Array.isArray(record.progress) ? record.progress : [];
70
138
  const org = record.org ?? {};
71
139
  const review = gate0.review ?? {};
@@ -127,6 +195,21 @@ export function projectForForm(record) {
127
195
  },
128
196
  progress: blankProgress(progress.length),
129
197
  existingProgressCount: progress.length,
198
+ // G4 only. Read here so a G4 form opens with the current conclusion in
199
+ // place rather than blank, which would invite overwriting it by omission.
200
+ outcome: {
201
+ achievement: text(outcome.achievement),
202
+ customer_recognition: text(outcome.customer_recognition),
203
+ our_proof: text(outcome.our_proof),
204
+ proved: text((outcome.conclusion ?? {}).proved),
205
+ recognized: text((outcome.conclusion ?? {}).recognized),
206
+ next_business: text((outcome.conclusion ?? {}).next_business),
207
+ milestone: text((outcome.business ?? {}).milestone),
208
+ businessOwner: text((outcome.business ?? {}).owner),
209
+ businessDeadline: dateText((outcome.business ?? {}).deadline),
210
+ businessStatus: text((outcome.business ?? {}).status),
211
+ overall: text(outcome.overall),
212
+ },
130
213
  };
131
214
  }
132
215
  /** A numeric field as the form's string, keeping `0` distinct from blank. */
@@ -196,6 +279,19 @@ export function blankProject() {
196
279
  },
197
280
  progress: blankProgress(0),
198
281
  existingProgressCount: 0,
282
+ outcome: {
283
+ achievement: '',
284
+ customer_recognition: '',
285
+ our_proof: '',
286
+ proved: '',
287
+ recognized: '',
288
+ next_business: '',
289
+ milestone: '',
290
+ businessOwner: '',
291
+ businessDeadline: '',
292
+ businessStatus: '',
293
+ overall: '',
294
+ },
199
295
  };
200
296
  }
201
297
  /**
@@ -224,6 +320,13 @@ function compact(values) {
224
320
  * Empty plan/progress blocks are emitted as empty collections, not omitted: the
225
321
  * ledger's parser tolerates absence, but a colleague reopening the file should
226
322
  * see the shape they are expected to fill.
323
+ *
324
+ * **This is not the download format.** The form ships a change set (see
325
+ * {@link projectToChangeSet}); a complete file would have to carry the ledger's
326
+ * derived fields (`gate0.missing`, `priority`, scenario status), and those are
327
+ * owned by `tools/derive.mjs` — writing them here would either be wrong or be
328
+ * overwritten by CI. `projectToYaml` remains for tests and for a full-file
329
+ * preview.
227
330
  */
228
331
  export function projectToYaml(project) {
229
332
  const document = {
@@ -259,21 +362,21 @@ export function projectToYaml(project) {
259
362
  customer_pain: project.plan.customer_pain === '' ? null : project.plan.customer_pain,
260
363
  expected_recognition: project.plan.expected_recognition === '' ? null : project.plan.expected_recognition,
261
364
  criteria: project.plan.criteria
262
- .filter((criterion) => criterion.name.trim() !== '')
365
+ .filter((criterion) => (criterion.name ?? '').trim() !== '')
263
366
  .map((criterion) => ({
264
367
  // Never renumber: a returned criterion keeps the id evidence cites.
265
- id: criterion.id.trim() === '' ? null : criterion.id.trim(),
368
+ id: (criterion.id ?? '').trim() === '' ? null : (criterion.id ?? '').trim(),
266
369
  name: criterion.name.trim(),
267
- metric: criterion.metric.trim() === '' ? null : criterion.metric.trim(),
268
- baseline: criterion.baseline.trim() === '' ? null : criterion.baseline.trim(),
269
- target: criterion.target.trim() === '' ? null : criterion.target.trim(),
370
+ metric: (criterion.metric ?? '').trim() === '' ? null : criterion.metric.trim(),
371
+ baseline: (criterion.baseline ?? '').trim() === '' ? null : criterion.baseline.trim(),
372
+ target: (criterion.target ?? '').trim() === '' ? null : criterion.target.trim(),
270
373
  })),
271
374
  scenarios: project.plan.scenarios
272
- .filter((scenario) => scenario.name.trim() !== '')
375
+ .filter((scenario) => (scenario.name ?? '').trim() !== '')
273
376
  .map((scenario) => ({
274
- id: scenario.id.trim() === '' ? null : scenario.id.trim(),
377
+ id: (scenario.id ?? '').trim() === '' ? null : (scenario.id ?? '').trim(),
275
378
  name: scenario.name.trim(),
276
- goal: scenario.goal.trim() === '' ? null : scenario.goal.trim(),
379
+ goal: (scenario.goal ?? '').trim() === '' ? null : scenario.goal.trim(),
277
380
  })),
278
381
  our_edge: project.plan.our_edge === '' ? null : project.plan.our_edge,
279
382
  timeline: {
@@ -304,6 +407,96 @@ export function projectToYaml(project) {
304
407
  };
305
408
  return YAML.stringify(document, { lineWidth: 0 });
306
409
  }
410
+ /** `''` becomes `null`: the ledger's "absent" is null, never the string "". */
411
+ function orNull(value) {
412
+ return value === '' ? null : value;
413
+ }
414
+ /**
415
+ * Build one project's change set from the form state.
416
+ *
417
+ * Every field the form can edit appears, so `poc-submit` can apply the whole
418
+ * object with `setIfPresent` semantics: a blank field means "I did not change
419
+ * this", which the merge step must not read as "delete it".
420
+ */
421
+ export function projectToChangeSet(project) {
422
+ return {
423
+ schema_version: FORM_SCHEMA_VERSION,
424
+ poc_id: project.pocId.trim(),
425
+ name: project.name.trim(),
426
+ org: {
427
+ system: orNull(project.system.trim()),
428
+ company: orNull(project.company.trim()),
429
+ department: orNull(project.department.trim()),
430
+ },
431
+ amount_wan: project.amountWan === '' ? null : Number(project.amountWan),
432
+ poc_type: orNull(project.pocType.trim()),
433
+ owner: orNull(project.owner.trim()),
434
+ sales: orNull(project.sales.trim()),
435
+ tech_owner: orNull(project.techOwner.trim()),
436
+ exec_sponsor: orNull(project.execSponsor.trim()),
437
+ stage: project.stage,
438
+ status: project.status,
439
+ stage_since: orNull(project.stageSince.trim()),
440
+ gate0: {
441
+ why_customer: orNull(project.gate0.why_customer.trim()),
442
+ why_us: orNull(project.gate0.why_us.trim()),
443
+ decision_chain: orNull(project.gate0.decision_chain.trim()),
444
+ post_poc_decision: orNull(project.gate0.post_poc_decision.trim()),
445
+ competitor: orNull(project.gate0.competitor.trim()),
446
+ review: {
447
+ conclusion: orNull(project.gate0.conclusion.trim()),
448
+ reviewer: orNull(project.gate0.reviewer.trim()),
449
+ reviewed_at: orNull(project.gate0.reviewed_at.trim()),
450
+ },
451
+ },
452
+ plan: {
453
+ customer_pain: orNull(project.plan.customer_pain.trim()),
454
+ expected_recognition: orNull(project.plan.expected_recognition.trim()),
455
+ our_edge: orNull(project.plan.our_edge.trim()),
456
+ criteria: project.plan.criteria
457
+ .filter((item) => (item.name ?? '').trim() !== '')
458
+ .map((item) => ({
459
+ id: orNull((item.id ?? '').trim()),
460
+ name: item.name.trim(),
461
+ metric: orNull((item.metric ?? '').trim()),
462
+ baseline: orNull((item.baseline ?? '').trim()),
463
+ target: orNull((item.target ?? '').trim()),
464
+ })),
465
+ scenarios: project.plan.scenarios
466
+ .filter((item) => (item.name ?? '').trim() !== '')
467
+ .map((item) => ({
468
+ id: orNull((item.id ?? '').trim()),
469
+ name: item.name.trim(),
470
+ goal: orNull((item.goal ?? '').trim()),
471
+ })),
472
+ risks: project.plan.risks
473
+ .filter((item) => item.name.trim() !== '')
474
+ .map((item) => ({
475
+ name: item.name.trim(),
476
+ level: orNull(item.level.trim()),
477
+ mitigation: orNull(item.mitigation.trim()),
478
+ })),
479
+ timeline: {
480
+ start: orNull(project.plan.timeline_start.trim()),
481
+ end: orNull(project.plan.timeline_end.trim()),
482
+ },
483
+ gate1: { conclusion: orNull(project.plan.gate1_conclusion.trim()) },
484
+ gate2: { ready: orNull(project.plan.gate2_ready.trim()) },
485
+ },
486
+ // Append-only: this is the list of NEW rounds, never the existing history.
487
+ progress: progressIsEmpty(project.progress) ? [] : [serializeProgress(project.progress)],
488
+ };
489
+ }
490
+ /** Build the document a colleague sends back. */
491
+ export function buildChangeDocument(options) {
492
+ return {
493
+ schemaVersion: FORM_SCHEMA_VERSION,
494
+ generatedAt: (options.now ?? new Date()).toISOString(),
495
+ generatedBy: 'POC 信息收集表单 v3.1',
496
+ intent: options.intent,
497
+ changes: options.projects.map((project) => projectToChangeSet(project)),
498
+ };
499
+ }
307
500
  /** `true` when the form's progress entry carries no user content. */
308
501
  function progressIsEmpty(entry) {
309
502
  return (entry.date === '' &&
@@ -384,17 +577,28 @@ const ENUMS = {
384
577
  gate3_2: ['已确认', '待确认'],
385
578
  evidenceType: ['文档', '截图', '数据', '邮件', '链接'],
386
579
  system: ['人保体系', '国寿体系'],
580
+ // G4 only: the outcome block is the one thing no earlier stage asks for.
581
+ achievement: ['达成', '部分达成', '未达成'],
582
+ businessStatus: ['已进入下一里程碑', '待推进', '补救中', '无后续动作'],
387
583
  };
388
584
  /**
389
585
  * The schema generation this form emits.
390
586
  *
391
587
  * Stamped into every generated page so a returned form can be checked against
392
- * the schema that will read it. A v3.0 form uses `items` and string scenarios;
393
- * importing it as v3.1 would silently drop every scenario and criterion
394
- * reference, which is exactly the failure this constant exists to catch.
588
+ * the schema that will read it. There is deliberately **no older-shape
589
+ * fallback**: the ledger declares one shape version and its validator rejects
590
+ * anything else outright (`E-VERSION`). A tolerant reader here would only move
591
+ * that failure later — to a point where the colleague already believes their
592
+ * work was recorded.
395
593
  */
396
594
  export const FORM_SCHEMA_VERSION = '3.1';
397
- /** The schema generation a v3.0 form emitted; recognised only to reject it. */
595
+ /**
596
+ * The stamp a pre-v3.1 form carries.
597
+ *
598
+ * A named constant only so the refusal message can name it. This is not a
599
+ * supported shape: nothing parses it, nothing converts it, and importing one is
600
+ * refused rather than half-applied.
601
+ */
398
602
  export const LEGACY_FORM_SCHEMA_VERSION = '3.0';
399
603
  /** The G0 prompts: the label and the reason each field exists. */
400
604
  const G0_PROMPTS = [
@@ -412,18 +616,27 @@ const G0_PROMPTS = [
412
616
  export function buildFormHtml(options) {
413
617
  const now = options.now ?? new Date();
414
618
  const projects = options.mode === 'blank' ? [blankProject()] : options.projects;
619
+ const intent = options.intent ?? (options.mode === 'blank' ? 'new' : 'supplement');
415
620
  const payload = {
416
621
  mode: options.mode,
622
+ intent,
417
623
  schemaVersion: FORM_SCHEMA_VERSION,
418
624
  generatedAt: now.toISOString(),
419
625
  today: now.toISOString().slice(0, 10),
420
626
  projects,
627
+ // Each project's stage decides which sections are the subject, so the
628
+ // resolution is per project rather than per document.
629
+ sections: projects.map((project) => resolveSections(intent, project.stage)),
421
630
  draftKey: draftKeyFor(options.mode, projects.map((project) => project.pocId).filter((id) => id !== '')),
422
631
  enums: ENUMS,
423
632
  g0Fields: G0_PROMPTS,
424
633
  };
425
634
  const data = scriptSafe(JSON.stringify(payload));
426
- const title = options.mode === 'blank' ? 'POC 新建项目表单 v3' : `POC 信息收集表单 v3(${projects.length} 个项目)`;
635
+ const title = intent === 'new'
636
+ ? 'POC 新建项目表单 v3'
637
+ : intent === 'progress'
638
+ ? `POC 进展记录表单 v3(${projects.length} 个项目)`
639
+ : `POC 信息补充表单 v3(${projects.length} 个项目)`;
427
640
  return `<!DOCTYPE html>
428
641
  <html lang="zh-CN">
429
642
  <head>
@@ -434,24 +647,16 @@ export function buildFormHtml(options) {
434
647
  </head>
435
648
  <body>
436
649
  <div class="shell">
437
- <header class="topbar">
438
- <div class="topbar-text">
439
- <h1 class="topbar-title">${escapeHtml(title)}</h1>
440
- <p class="topbar-sub">按台账 v3 字段收集。填完点「下载 YAML」,把文件发回项目负责人;保存的是真实 YAML,可以直接提交。</p>
441
- </div>
442
- <div class="topbar-actions">
443
- <span class="save-status" id="saveStatus">已就绪</span>
444
- <button type="button" class="btn" id="clearBtn">清空草稿</button>
445
- </div>
446
- </header>
447
650
  <div class="notice" id="restoreNotice" hidden>已恢复上次未提交的草稿。</div>
448
651
  <div class="notice notice-warn" id="draftNotice" hidden></div>
652
+ <!-- The banner is rendered by the script from DATA, so it carries the project's
653
+ real identity instead of a static page title that says nothing. -->
449
654
  <main id="formBody"></main>
450
655
  <footer class="footer">
451
656
  <div class="footer-info" id="footerInfo">正在初始化…</div>
452
657
  <div class="footer-actions">
453
- <button type="button" class="btn" id="previewBtn">预览 YAML</button>
454
- <button type="button" class="btn btn-primary" id="downloadBtn">下载 YAML</button>
658
+ <button type="button" class="btn" id="previewBtn">预览变更集</button>
659
+ <button type="button" class="btn btn-primary" id="downloadBtn">下载变更集</button>
455
660
  </div>
456
661
  </footer>
457
662
  </div>
@@ -509,9 +714,9 @@ export function checkFormCompatibility(payload) {
509
714
  return {
510
715
  compatible: false,
511
716
  declared: declared === '' ? LEGACY_FORM_SCHEMA_VERSION : declared,
512
- reason: `这个表单是 v${LEGACY_FORM_SCHEMA_VERSION} 版本导出的,当前台账已升级到 v${FORM_SCHEMA_VERSION}。` +
513
- '场景与指标改为按 id 关联,旧表单里的场景名无法对应,直接导入会丢失全部场景与指标引用。' +
514
- '请重新导出一份 v' + FORM_SCHEMA_VERSION + ' 表单再填。',
717
+ reason: `这个表单是 v${LEGACY_FORM_SCHEMA_VERSION} 或更早版本导出的,台账只接受 v${FORM_SCHEMA_VERSION}。` +
718
+ '旧表单的场景是字符串、指标没有 id,而证据按 id 挂靠,导入后会丢失全部场景与指标引用。' +
719
+ '台账不做旧结构兼容,请重新导出一份 v' + FORM_SCHEMA_VERSION + ' 表单再填。',
515
720
  };
516
721
  }
517
722
  return {
@@ -522,60 +727,205 @@ export function checkFormCompatibility(payload) {
522
727
  }
523
728
  /** Styles: one inline sheet, the console's own design tokens. */
524
729
  const FORM_CSS = `
525
- :root{--primary:#2864E8;--text:#192638;--bg:#F5F7FB;--border:#E6EBF2;--green:#218568;--amber:#B77919;--red:#C0392B;--muted:#6B7C93}
730
+ /* ===========================================================================
731
+ * The form mirrors the detail page, not a generic settings screen.
732
+ *
733
+ * A colleague filling this in is answering the same questions the detail page
734
+ * asks: what does Gate 0 say, what are the criteria and scenarios, what happened
735
+ * this round. So the layout follows the detail page's own contract — a banner,
736
+ * then a fixed two-column body (commitments left, record right), then a
737
+ * full-width closing block — instead of one long stack of generic cards.
738
+ *
739
+ * The tokens are the dashboard's: same palette, same 8px rhythm, same type
740
+ * scale. Nothing here invents a new visual language, because the form is the
741
+ * same product seen from the other side.
742
+ * ======================================================================== */
743
+ :root{
744
+ --primary:#2864E8;--primary-soft:rgba(40,100,232,.09);
745
+ --text:#192638;--text-2:#4A5A70;--text-3:#7A8AA0;
746
+ --bg:#F5F7FB;--surface:#fff;--inset:#F7F9FC;
747
+ --border:#E6EBF2;--green:#218568;--green-soft:rgba(33,133,104,.10);
748
+ --amber:#B77919;--amber-soft:rgba(183,121,25,.11);
749
+ --red:#C0392B;--red-soft:rgba(192,57,43,.10);
750
+ --slate:#5A6A80;--slate-soft:rgba(90,106,128,.10);
751
+ --shadow-1:0 1px 2px rgba(20,32,52,.05);
752
+ --shadow-2:0 2px 6px rgba(20,32,52,.07),0 1px 2px rgba(20,32,52,.04);
753
+ --mono:ui-monospace,SFMono-Regular,Menlo,monospace;
754
+ }
526
755
  *{box-sizing:border-box;margin:0;padding:0}
527
- body{font-family:'Avenir Next','PingFang SC','Microsoft YaHei',system-ui,sans-serif;background:var(--bg);color:var(--text);font-size:14px;line-height:1.6;padding:24px}
528
- .shell{max-width:920px;margin:0 auto}
529
- .topbar{display:flex;justify-content:space-between;align-items:flex-start;gap:16px;background:#fff;padding:16px 24px;border-radius:8px;border:1px solid var(--border);margin-bottom:12px;position:sticky;top:0;z-index:100}
530
- .topbar-title{font-size:18px;font-weight:600;line-height:1.4}
531
- .topbar-sub{font-size:12px;color:var(--muted);margin-top:2px}
532
- .topbar-actions{display:flex;align-items:center;gap:8px;flex:none}
533
- .save-status{font-size:12px;color:var(--green);white-space:nowrap}
534
- .notice{background:#E8EFFC;border:1px solid #C9DCFB;border-radius:6px;padding:10px 14px;font-size:13px;margin-bottom:12px}
535
- .notice-warn{background:#FDF4E3;border-color:#F0E2C8;color:#8A5E12}
536
- .card{background:#fff;border-radius:8px;border:1px solid var(--border);padding:20px 24px;margin-bottom:14px}
537
- .card-title{font-size:15px;font-weight:600;margin-bottom:4px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
538
- .card-hint{font-size:12px;color:var(--muted);margin-bottom:14px}
539
- .field{margin-bottom:16px}
540
- .field:last-child{margin-bottom:0}
541
- .field-label{display:block;font-weight:500;margin-bottom:5px;font-size:13px}
756
+ body{
757
+ font-family:'Avenir Next','PingFang SC','Microsoft YaHei',system-ui,sans-serif;
758
+ background:var(--bg);color:var(--text);font-size:13px;line-height:20px;
759
+ -webkit-font-smoothing:antialiased;padding:20px 28px 96px;
760
+ }
761
+ .shell{max-width:1200px;margin:0 auto;display:flex;flex-direction:column;gap:16px}
762
+
763
+ /* ---------- banner: identity + progress, the detail page's header ---------- */
764
+ .banner{
765
+ display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px 18px;
766
+ padding:16px 20px;background:var(--surface);border:1px solid var(--border);
767
+ border-radius:10px;position:sticky;top:0;z-index:100;box-shadow:var(--shadow-1);
768
+ }
769
+ .banner-main{display:flex;flex-direction:column;gap:4px;min-width:0}
770
+ .banner-kicker{font-size:10px;font-weight:650;letter-spacing:.05em;text-transform:uppercase;color:var(--primary)}
771
+ .banner-title{margin:0;font-size:20px;line-height:28px;font-weight:700;letter-spacing:-.01em;overflow-wrap:anywhere}
772
+ .banner-meta{display:flex;flex-wrap:wrap;align-items:baseline;gap:10px;font-size:10.5px;color:var(--text-3)}
773
+ .banner-id{font-family:var(--mono);font-size:10px}
774
+ .banner-side{display:flex;flex-direction:column;align-items:flex-end;gap:6px}
775
+ .banner-pills{display:flex;flex-wrap:wrap;gap:5px;justify-content:flex-end}
776
+ .banner-actions{display:flex;align-items:center;gap:8px}
777
+ .save-status{font-size:10.5px;color:var(--green);white-space:nowrap}
778
+ .banner-nav{
779
+ grid-column:1/-1;display:flex;align-items:center;gap:10px;
780
+ padding-top:10px;border-top:1px solid var(--border);
781
+ }
782
+ .banner-step{margin:0 auto;font-size:10px;color:var(--text-3);font-variant-numeric:tabular-nums}
783
+
784
+ /* ---------- the fixed two-column contract, same ratio as the detail page --- */
785
+ .columns{display:grid;grid-template-columns:minmax(0,1.72fr) minmax(0,1fr);gap:18px;align-items:start}
786
+ @media(max-width:1080px){.columns{grid-template-columns:minmax(0,1fr)}}
787
+ .col{display:flex;flex-direction:column;gap:18px;min-width:0}
788
+
789
+ /* ---------- section: one block with a heading and a rule ---------- */
790
+ .sec{display:flex;flex-direction:column;gap:10px;min-width:0}
791
+ .sec-head{display:flex;align-items:baseline;gap:9px;padding-bottom:7px;border-bottom:1px solid var(--border)}
792
+ .sec-title{margin:0;font-size:13.5px;line-height:20px;font-weight:650;letter-spacing:-.005em}
793
+ .sec-kicker{margin-left:auto;font-size:10.5px;color:var(--text-3);font-variant-numeric:tabular-nums}
794
+ .sec-hint{margin:0;font-size:11px;line-height:17px;color:var(--text-2)}
795
+
796
+ /* ---------- Gate 0 as the same 2x3 card grid the detail page uses ---------- */
797
+ .g0-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
798
+ @media(max-width:720px){.g0-grid{grid-template-columns:minmax(0,1fr)}}
799
+ .g0-card{
800
+ display:flex;flex-direction:column;gap:5px;padding:10px 12px;
801
+ border-radius:8px;background:var(--surface);border:1px solid var(--border);
802
+ }
803
+ .g0-card[data-present="false"]{background:var(--inset);border-style:dashed}
804
+ .g0-card-head{display:flex;align-items:baseline;gap:8px}
805
+ .g0-card-label{font-size:11px;line-height:16px;font-weight:650}
806
+ .g0-card-label .req{color:var(--red);margin-left:2px}
807
+ .g0-card-missing{
808
+ margin-left:auto;font-size:9px;line-height:13px;font-weight:650;white-space:nowrap;
809
+ color:var(--amber);background:var(--amber-soft);padding:1px 5px;border-radius:4px;
810
+ }
811
+ .g0-card .textarea{min-height:54px;font-size:11px;line-height:16px;border-color:transparent;background:transparent;padding:2px 0}
812
+ .g0-card .textarea:hover{border-color:var(--border);background:var(--surface);padding:6px 8px}
813
+ .g0-card .textarea:focus{border-color:var(--primary);background:var(--surface);padding:6px 8px}
814
+ .g0-help{font-size:10px;line-height:14px;color:var(--text-3)}
815
+
816
+ /* ---------- list rows: criteria and scenarios as cards, not bare inputs --- */
817
+ .row-card{
818
+ display:flex;flex-direction:column;gap:6px;padding:9px 11px;
819
+ border-radius:8px;background:var(--surface);border:1px solid var(--border);
820
+ }
821
+ .row-card-head{display:flex;align-items:center;gap:8px}
822
+ .row-card-id{
823
+ flex:none;font-family:var(--mono);font-size:9px;line-height:13px;
824
+ color:var(--text-3);background:var(--inset);border:1px solid var(--border);
825
+ padding:1px 5px;border-radius:4px;
826
+ }
827
+ .row-card-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
828
+ @media(max-width:720px){.row-card-grid{grid-template-columns:minmax(0,1fr)}}
829
+ .mini{display:flex;flex-direction:column;gap:2px;min-width:0}
830
+ .mini-wide{margin-top:2px}
831
+ .mini-label{font-size:9.5px;font-weight:600;letter-spacing:.03em;color:var(--text-3)}
832
+
833
+ /* ---------- fields ---------- */
834
+ .field{display:flex;flex-direction:column;gap:4px;min-width:0}
835
+ .field-label{font-size:11px;font-weight:650;color:var(--text)}
542
836
  .field-label .req{color:var(--red);margin-left:2px}
543
- .field-help{font-size:12px;color:var(--muted);margin-bottom:5px}
544
- .input,.textarea,.select{width:100%;padding:8px 11px;border:1px solid var(--border);border-radius:6px;font-family:inherit;font-size:13px;background:#fff;color:var(--text)}
545
- .input:focus,.textarea:focus,.select:focus{outline:none;border-color:var(--primary)}
546
- .textarea{min-height:66px;resize:vertical}
547
- .field-error{color:var(--red);font-size:12px;margin-top:4px;display:none}
837
+ .field-help{font-size:10px;line-height:15px;color:var(--text-3)}
838
+ .input,.textarea,.select{
839
+ width:100%;padding:6px 9px;border:1px solid var(--border);border-radius:6px;
840
+ font-family:inherit;font-size:12px;line-height:18px;background:var(--surface);color:var(--text);
841
+ }
842
+ .input-flush{border-color:transparent;background:transparent;padding:2px 0;font-size:13px;font-weight:600}
843
+ .input-flush:hover{border-color:var(--border);background:var(--surface);padding:5px 8px}
844
+ .input-flush:focus{border-color:var(--primary);background:var(--surface);padding:5px 8px}
845
+ .input:focus,.textarea:focus,.select:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-soft)}
846
+ .textarea{min-height:60px;resize:vertical}
847
+ .grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px 14px}
848
+ @media(max-width:720px){.grid-2{grid-template-columns:minmax(0,1fr)}}
548
849
  .field.has-error .input,.field.has-error .textarea,.field.has-error .select{border-color:var(--red)}
850
+ .field-error{color:var(--red);font-size:10px;display:none}
549
851
  .field.has-error .field-error{display:block}
550
- .grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 14px}
551
- @media(max-width:640px){.grid-2{grid-template-columns:minmax(0,1fr)}}
552
- .list-item{display:flex;gap:8px;margin-bottom:8px;align-items:flex-start}
553
- .list-item .input{flex:1}
554
- .btn{padding:7px 14px;border-radius:6px;border:1px solid var(--border);background:#fff;cursor:pointer;font-family:inherit;font-size:13px;color:var(--text)}
555
- .btn:hover{background:#F8F9FB}
556
- .btn-primary{background:var(--primary);color:#fff;border-color:var(--primary)}
852
+
853
+ /* ---------- id pickers: which scenario / criterion this round touched ------ */
854
+ .pick-list{display:flex;flex-wrap:wrap;gap:6px}
855
+ .pick{
856
+ display:flex;align-items:center;gap:6px;padding:5px 9px;border-radius:7px;
857
+ border:1px solid var(--border);background:var(--surface);cursor:pointer;font-size:11px;
858
+ }
859
+ .pick:hover{border-color:var(--primary)}
860
+ .pick:has(input:checked){background:var(--primary-soft);border-color:var(--primary)}
861
+ .pick input{accent-color:var(--primary);margin:0}
862
+ .pick-id{font-family:var(--mono);font-size:9px;color:var(--text-3)}
863
+ .pick-name{overflow-wrap:anywhere}
864
+
865
+ /* ---------- atoms ---------- */
866
+ .btn{
867
+ padding:6px 12px;border-radius:6px;border:1px solid var(--border);background:var(--surface);
868
+ cursor:pointer;font-family:inherit;font-size:12px;color:var(--text);white-space:nowrap;
869
+ }
870
+ .btn:hover{background:var(--inset)}
871
+ .btn-primary{background:var(--primary);color:#fff;border-color:var(--primary);font-weight:600}
557
872
  .btn-primary:hover{background:#1E54C9}
558
- .btn-sm{padding:4px 10px;font-size:12px}
559
- .btn-remove{color:var(--red);border-color:#F0D0CB}
560
- .badge{display:inline-block;padding:1px 8px;border-radius:4px;font-size:11px;font-weight:500}
561
- .badge-ok{background:#E6F4EE;color:var(--green)}
562
- .badge-warn{background:#FDF4E3;color:var(--amber)}
563
- .badge-error{background:#FBEAE8;color:var(--red)}
564
- .badge-info{background:#E8EFFC;color:var(--primary)}
565
- .gaps{background:#FDF8F0;border:1px solid #F0E2C8;border-radius:6px;padding:10px 14px;margin-bottom:14px}
566
- .gap-item{font-size:13px;padding:3px 0;display:flex;gap:8px}
567
- .gap-high{color:var(--red)}
568
- .gap-medium{color:var(--amber)}
569
- .g0-summary{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:14px}
570
- .g0-chip{font-size:12px;padding:3px 10px;border-radius:12px;border:1px solid var(--border);background:#F7F9FC}
571
- .g0-chip[data-present="true"]{background:#E6F4EE;border-color:#BFE3D3;color:var(--green)}
572
- .g0-chip[data-present="false"]{background:#FBEAE8;border-color:#F0D0CB;color:var(--red)}
573
- .footer{position:sticky;bottom:0;background:#fff;border:1px solid var(--border);border-radius:8px;padding:14px 24px;margin-top:14px;display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;box-shadow:0 -4px 12px rgba(0,0,0,.04)}
574
- .footer-info{font-size:13px;color:var(--muted)}
873
+ .btn-sm{padding:3px 9px;font-size:11px}
874
+ .btn-remove{color:var(--red);border-color:rgba(192,57,43,.28);flex:none}
875
+ .badge{display:inline-block;padding:1px 7px;border-radius:4px;font-size:10px;font-weight:600;white-space:nowrap}
876
+ .badge-ok{background:var(--green-soft);color:var(--green)}
877
+ .badge-warn{background:var(--amber-soft);color:var(--amber)}
878
+ .badge-error{background:var(--red-soft);color:var(--red)}
879
+ .badge-info{background:var(--primary-soft);color:var(--primary)}
880
+ .pill{display:inline-flex;align-items:center;gap:5px;padding:2px 9px;border-radius:13px;font-size:10.5px;font-weight:600}
881
+ .pill-dot{width:6px;height:6px;border-radius:50%;background:currentColor;flex:none}
882
+ .pill-blue{background:var(--primary-soft);color:var(--primary)}
883
+ .pill-slate{background:var(--slate-soft);color:var(--slate)}
884
+ .pill-amber{background:var(--amber-soft);color:var(--amber)}
885
+ .pill-green{background:var(--green-soft);color:var(--green)}
886
+ .pill-red{background:var(--red-soft);color:var(--red)}
887
+
888
+ /* ---------- readiness strip: the same reminder band as the detail page ----- */
889
+ .readiness{
890
+ display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;
891
+ padding:11px 14px;border-radius:10px;background:var(--surface);
892
+ border:1px solid var(--border);border-left:3px solid var(--slate);
893
+ }
894
+ .readiness[data-tone="green"]{border-left-color:var(--green)}
895
+ .readiness[data-tone="amber"]{border-left-color:var(--amber)}
896
+ .readiness[data-tone="red"]{border-left-color:var(--red)}
897
+ @media(max-width:720px){.readiness{grid-template-columns:minmax(0,1fr)}}
898
+ .ready-cell{display:flex;flex-direction:column;gap:2px;min-width:0}
899
+ .ready-label{font-size:9.5px;font-weight:650;letter-spacing:.05em;text-transform:uppercase;color:var(--text-3)}
900
+ .ready-value{font-size:11px;line-height:17px;color:var(--text-2);overflow-wrap:anywhere}
901
+
902
+ /* ---------- notices / footer ---------- */
903
+ .notice{
904
+ background:var(--primary-soft);border:1px solid rgba(40,100,232,.22);border-radius:8px;
905
+ padding:9px 13px;font-size:11.5px;color:var(--text-2);
906
+ }
907
+ .notice-warn{background:var(--amber-soft);border-color:rgba(183,121,25,.24);color:#8A5E12}
908
+ .footer{
909
+ position:fixed;bottom:0;left:0;right:0;z-index:150;
910
+ background:var(--surface);border-top:1px solid var(--border);
911
+ padding:11px 28px;display:flex;justify-content:space-between;align-items:center;gap:12px;
912
+ flex-wrap:wrap;box-shadow:0 -4px 12px rgba(20,32,52,.06);
913
+ }
914
+ .footer-info{font-size:11.5px;color:var(--text-3)}
575
915
  .footer-actions{display:flex;gap:8px;flex-wrap:wrap}
576
- .yaml-preview{background:#fff;padding:16px;border-radius:8px;border:1px solid var(--border);overflow:auto;font-size:12px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;margin-top:14px;white-space:pre-wrap}
577
- .toast{position:fixed;top:80px;left:50%;transform:translateX(-50%);background:var(--green);color:#fff;padding:9px 18px;border-radius:6px;font-size:13px;z-index:200}
578
- @media print{.topbar,.footer,.topbar-actions{position:static}}
916
+ .yaml-preview{
917
+ background:var(--surface);padding:16px;border-radius:10px;border:1px solid var(--border);
918
+ overflow:auto;font-size:11px;font-family:var(--mono);white-space:pre-wrap;line-height:1.55;
919
+ }
920
+ .toast{
921
+ position:fixed;top:76px;left:50%;transform:translateX(-50%);
922
+ background:var(--green);color:#fff;padding:8px 17px;border-radius:7px;
923
+ font-size:12px;z-index:200;box-shadow:var(--shadow-2);
924
+ }
925
+ @media print{
926
+ .banner,.footer{position:static;box-shadow:none}
927
+ body{padding:0}
928
+ }
579
929
  `;
580
930
  /**
581
931
  * The generated page script.
@@ -675,6 +1025,25 @@ const FORM_SCRIPT = `
675
1025
 
676
1026
  function current() { return DATA.projects[state.active]; }
677
1027
 
1028
+ /**
1029
+ * A new list row, carrying the next free stable id.
1030
+ *
1031
+ * v3.1 requires an id on every scenario and criterion because evidence and
1032
+ * progress reference them. A row added without one used to crash the YAML
1033
+ * writer outright (it called '.trim()' on an absent id), and even when it did
1034
+ * not, the row could never be referenced. The id is derived from the highest
1035
+ * existing suffix so deleting a row never renumbers the survivors.
1036
+ */
1037
+ function nextRow(prefix, list, fields) {
1038
+ var highest = 0;
1039
+ for (var i = 0; i < list.length; i += 1) {
1040
+ var match = new RegExp('^' + prefix + '-(\\\\d+)$').exec(text(list[i].id));
1041
+ if (match) highest = Math.max(highest, Number(match[1]));
1042
+ }
1043
+ fields.id = prefix + '-' + ('0' + (highest + 1)).slice(-2);
1044
+ return fields;
1045
+ }
1046
+
678
1047
  function setPath(target, path, value) {
679
1048
  var parts = path.split('.');
680
1049
  var node = target;
@@ -710,51 +1079,95 @@ const FORM_SCRIPT = `
710
1079
  '<label class="field-label">' + escapeHtml(label) + req + '</label>' + help + input + '</div>';
711
1080
  }
712
1081
 
1082
+ /**
1083
+ * Gate 0 as the same 2x3 card grid the detail page uses.
1084
+ *
1085
+ * A generic stack of labelled textareas hid the thing a colleague most needs
1086
+ * to see: WHICH of the five prerequisites is still missing. The grid makes a
1087
+ * blank cell a visible gap rather than one empty box among many.
1088
+ */
713
1089
  function g0Card(project) {
714
- var chips = '';
1090
+ var cards = '';
1091
+ var present = 0;
715
1092
  for (var i = 0; i < DATA.g0Fields.length; i += 1) {
716
1093
  var def = DATA.g0Fields[i];
717
- var present = text(project.gate0[def.key]).trim() !== '';
718
- chips += '<span class="g0-chip" data-present="' + (present ? 'true' : 'false') + '">' +
719
- (present ? '✓ ' : '✗ ') + escapeHtml(def.label) + '</span>';
720
- }
721
- var body = '';
722
- for (var j = 0; j < DATA.g0Fields.length; j += 1) {
723
- var field0 = DATA.g0Fields[j];
724
- body += field(field0.label, 'gate0.' + field0.key, project.gate0[field0.key], { multiline: true, help: field0.hint, required: true });
1094
+ var filled = text(project.gate0[def.key]).trim() !== '';
1095
+ if (filled) present += 1;
1096
+ cards += '<div class="g0-card" data-present="' + (filled ? 'true' : 'false') + '">' +
1097
+ '<div class="g0-card-head"><span class="g0-card-label">' + escapeHtml(def.label) +
1098
+ '<span class="req">*</span></span>' +
1099
+ (filled ? '' : '<span class="g0-card-missing">缺失</span>') + '</div>' +
1100
+ '<textarea class="textarea" data-path="gate0.' + def.key + '" placeholder="' +
1101
+ escapeHtml(def.hint) + '">' + escapeHtml(project.gate0[def.key]) + '</textarea>' +
1102
+ '</div>';
725
1103
  }
726
- body += '<div class="grid-2">' +
727
- field('主要竞争对手', 'gate0.competitor', project.gate0.competitor, {}) +
728
- field('G0 评审结论', 'gate0.conclusion', project.gate0.conclusion, { enum: DATA.enums.g0Conclusion }) +
729
- field('G0 评审人', 'gate0.reviewer', project.gate0.reviewer, {}) +
730
- field('评审日期', 'gate0.reviewed_at', project.gate0.reviewed_at, { date: true }) +
1104
+ // The fifth prerequisite lives in the identity block, so it is counted here
1105
+ // but edited there — showing it twice would let the two copies disagree.
1106
+ var techFilled = text(project.techOwner).trim() !== '';
1107
+ if (techFilled) present += 1;
1108
+ cards += '<div class="g0-card" data-present="' + (techFilled ? 'true' : 'false') + '">' +
1109
+ '<div class="g0-card-head"><span class="g0-card-label">客户技术责任人' +
1110
+ '<span class="req">*</span></span>' +
1111
+ (techFilled ? '' : '<span class="g0-card-missing">缺失</span>') + '</div>' +
1112
+ '<input class="input" data-path="techOwner" value="' + escapeHtml(project.techOwner) + '" placeholder="第五项必填,在下方身份区也能改">' +
731
1113
  '</div>';
732
- return '<section class="card"><h2 class="card-title">G0 · 值不值得做<span class="badge badge-info">五必填</span></h2>' +
733
- '<p class="card-hint">四项在 G0 区,第五项是身份区的「客户技术责任人」。这五项齐了,评审才有意义。</p>' +
734
- '<div class="g0-summary">' + chips + '</div>' + body + '</section>';
1114
+
1115
+ var tone = present === 5 ? 'badge-ok' : present === 0 ? 'badge-warn' : 'badge-info';
1116
+ return '<section class="sec">' +
1117
+ '<header class="sec-head"><h2 class="sec-title">Gate 0 · 值不值得做</h2>' +
1118
+ '<span class="sec-kicker">五必填 <span class="badge ' + tone + '">' + present + ' / 5</span></span></header>' +
1119
+ '<p class="sec-hint">这五项齐了,G0 评审才有意义。四项在 gate0 区,第五项是身份区的「客户技术责任人」——两处都能改,改的是同一个字段。</p>' +
1120
+ '<div class="g0-grid">' + cards + '</div>' +
1121
+ '<div class="grid-2">' +
1122
+ field('主要竞争对手', 'gate0.competitor', project.gate0.competitor, {}) +
1123
+ field('G0 评审结论', 'gate0.conclusion', project.gate0.conclusion, { enum: DATA.enums.g0Conclusion }) +
1124
+ field('G0 评审人', 'gate0.reviewer', project.gate0.reviewer, {}) +
1125
+ field('评审日期', 'gate0.reviewed_at', project.gate0.reviewed_at, { date: true }) +
1126
+ '</div></section>';
735
1127
  }
736
1128
 
737
1129
  function criteriaList(project) {
738
1130
  var rows = '';
739
1131
  for (var i = 0; i < project.plan.criteria.length; i += 1) {
740
1132
  var criterion = project.plan.criteria[i];
741
- rows += '<div class="list-item">' +
742
- '<input class="input" data-path="plan.criteria.' + i + '.name" value="' + escapeHtml(criterion.name) + '" placeholder="指标名称,如「200 人并发稳定 7 天」">' +
743
- '<input class="input" data-path="plan.criteria.' + i + '.metric" value="' + escapeHtml(criterion.metric) + '" placeholder="度量,如「成功率」">' +
744
- '<input class="input" data-path="plan.criteria.' + i + '.baseline" value="' + escapeHtml(criterion.baseline) + '" placeholder="基线">' +
745
- '<input class="input" data-path="plan.criteria.' + i + '.target" value="' + escapeHtml(criterion.target) + '" placeholder="目标,如 ≥99.5%">' +
746
- '<button type="button" class="btn btn-sm btn-remove" data-remove="criteria" data-index="' + i + '">删</button>' +
747
- '</div>';
1133
+ rows += '<div class="row-card">' +
1134
+ '<div class="row-card-head">' +
1135
+ '<span class="row-card-id mono">' + escapeHtml(criterion.id) + '</span>' +
1136
+ '<input class="input input-flush" data-path="plan.criteria.' + i + '.name" value="' + escapeHtml(criterion.name) + '" placeholder="指标名称,如「200 人并发稳定 7 天」">' +
1137
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="criteria" data-index="' + i + '" title="删除这条指标">删</button>' +
1138
+ '</div>' +
1139
+ '<div class="row-card-grid">' +
1140
+ '<label class="mini"><span class="mini-label">度量</span>' +
1141
+ '<input class="input" data-path="plan.criteria.' + i + '.metric" value="' + escapeHtml(criterion.metric) + '" placeholder="如「成功率」"></label>' +
1142
+ '<label class="mini"><span class="mini-label">基线</span>' +
1143
+ '<input class="input" data-path="plan.criteria.' + i + '.baseline" value="' + escapeHtml(criterion.baseline) + '" placeholder="当前值"></label>' +
1144
+ '<label class="mini"><span class="mini-label">目标</span>' +
1145
+ '<input class="input" data-path="plan.criteria.' + i + '.target" value="' + escapeHtml(criterion.target) + '" placeholder="如 ≥99.5%"></label>' +
1146
+ '</div></div>';
748
1147
  }
749
1148
  return rows + '<button type="button" class="btn btn-sm" data-add="criteria">+ 加一条指标</button>';
750
1149
  }
751
1150
 
1151
+ /**
1152
+ * The scenario list.
1153
+ *
1154
+ * v3.1 made a scenario an object with a stable id, not a bare string. The old
1155
+ * renderer still printed the object, which is why every scenario row showed
1156
+ * "[object Object]" — the id is carried through untouched because evidence
1157
+ * attaches to it, and 'name' / 'goal' are the two editable parts.
1158
+ */
752
1159
  function scenarioList(project) {
753
1160
  var rows = '';
754
1161
  for (var i = 0; i < project.plan.scenarios.length; i += 1) {
755
- rows += '<div class="list-item">' +
756
- '<input class="input" data-path="plan.scenarios.' + i + '" value="' + escapeHtml(project.plan.scenarios[i]) + '" placeholder="测试场景">' +
757
- '<button type="button" class="btn btn-sm btn-remove" data-remove="scenarios" data-index="' + i + '">删</button>' +
1162
+ var scenario = project.plan.scenarios[i];
1163
+ rows += '<div class="row-card">' +
1164
+ '<div class="row-card-head">' +
1165
+ '<span class="row-card-id mono">' + escapeHtml(scenario.id) + '</span>' +
1166
+ '<input class="input input-flush" data-path="plan.scenarios.' + i + '.name" value="' + escapeHtml(scenario.name) + '" placeholder="场景名称,如「办公网远程接入」">' +
1167
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="scenarios" data-index="' + i + '" title="删除这个场景">删</button>' +
1168
+ '</div>' +
1169
+ '<label class="mini mini-wide"><span class="mini-label">成功目标</span>' +
1170
+ '<input class="input" data-path="plan.scenarios.' + i + '.goal" value="' + escapeHtml(scenario.goal) + '" placeholder="如 5000 人并发成功率 ≥99.5%,稳定 7 天"></label>' +
758
1171
  '</div>';
759
1172
  }
760
1173
  return rows + '<button type="button" class="btn btn-sm" data-add="scenarios">+ 加一个场景</button>';
@@ -781,6 +1194,7 @@ const FORM_SCRIPT = `
781
1194
  return rows + '<button type="button" class="btn btn-sm" data-add="risks">+ 加一条风险</button>';
782
1195
  }
783
1196
 
1197
+ /** The plan block: how we win, split into what we commit to and the limits. */
784
1198
  function planCard(project) {
785
1199
  var criteria = project.plan.criteria.length;
786
1200
  var scenarios = project.plan.scenarios.length;
@@ -791,107 +1205,399 @@ const FORM_SCRIPT = `
791
1205
  var scenarioBadge = scenarios === 0 ? '<span class="badge badge-warn">还没有场景</span>'
792
1206
  : (scenarios >= 3 && scenarios <= 5 ? '<span class="badge badge-ok">' + scenarios + ' 个,符合 3–5</span>'
793
1207
  : '<span class="badge badge-error">' + scenarios + ' 个,要求 3–5</span>');
794
- var riskBadge = risks === 0 ? '<span class="badge badge-warn">还没有风险</span>'
795
- : (risks <= 3 ? '<span class="badge badge-ok">' + risks + ' 条,≤3</span>'
796
- : '<span class="badge badge-error">' + risks + ' 条,超过 3</span>');
797
- return '<section class="card"><h2 class="card-title">计划 · 怎么赢<span class="badge badge-info">G1 / G2</span></h2>' +
798
- '<p class="card-hint">指标和场景都有数量要求:指标 2–3 条、场景 3–5 个、风险不超过 3 条。数量不对会在缺口清单里被点名。</p>' +
1208
+ return '<section class="sec">' +
1209
+ '<header class="sec-head"><h2 class="sec-title">成功指标与测试场景</h2>' +
1210
+ '<span class="sec-kicker">G1 / G2</span></header>' +
1211
+ '<p class="sec-hint">指标 2–3 条、场景 3–5 个。数量不对会在缺口清单里被点名。id 由系统分配,不要改——证据靠它挂靠。</p>' +
1212
+ '<div class="sec"><label class="field-label">关键成功指标 ' + criteriaBadge + '</label>' + criteriaList(project) + '</div>' +
1213
+ '<div class="sec"><label class="field-label">关键测试场景 ' + scenarioBadge + '</label>' + scenarioList(project) + '</div>' +
1214
+ '</section>';
1215
+ }
1216
+
1217
+ /** The plan's narrative + its limits, which belong on the record side. */
1218
+ function planNarrative(project) {
1219
+ return '<section class="sec">' +
1220
+ '<header class="sec-head"><h2 class="sec-title">方案要点</h2></header>' +
799
1221
  field('客户核心痛点', 'plan.customer_pain', project.plan.customer_pain, { multiline: true }) +
800
1222
  field('期望客户认可什么', 'plan.expected_recognition', project.plan.expected_recognition, { multiline: true }) +
801
1223
  field('我方优势 / 赢点', 'plan.our_edge', project.plan.our_edge, { multiline: true }) +
802
- '<div class="field"><label class="field-label">关键成功指标 ' + criteriaBadge + '</label>' + criteriaList(project) + '</div>' +
803
- '<div class="field"><label class="field-label">关键测试场景 ' + scenarioBadge + '</label>' + scenarioList(project) + '</div>' +
804
- '<div class="field"><label class="field-label">最大风险 ' + riskBadge + '</label>' + riskList(project) + '</div>' +
1224
+ '</section>';
1225
+ }
1226
+
1227
+ function riskCard(project) {
1228
+ var risks = project.plan.risks.length;
1229
+ var riskBadge = risks === 0 ? '<span class="badge badge-warn">还没有风险</span>'
1230
+ : (risks <= 3 ? '<span class="badge badge-ok">' + risks + ' 条,≤3</span>'
1231
+ : '<span class="badge badge-error">' + risks + ' 条,超过 3</span>');
1232
+ return '<section class="sec">' +
1233
+ '<header class="sec-head"><h2 class="sec-title">最大风险</h2>' +
1234
+ '<span class="sec-kicker">' + riskBadge + '</span></header>' +
1235
+ riskList(project) + '</section>';
1236
+ }
1237
+
1238
+ function gateCard(project) {
1239
+ return '<section class="sec">' +
1240
+ '<header class="sec-head"><h2 class="sec-title">Gate 结论与时间</h2></header>' +
805
1241
  '<div class="grid-2">' +
806
- field('计划开始', 'plan.timeline_start', project.plan.timeline_start, { date: true }) +
807
- field('计划结束', 'plan.timeline_end', project.plan.timeline_end, { date: true }) +
808
- field('G1 结论', 'plan.gate1_conclusion', project.plan.gate1_conclusion, { enum: DATA.enums.g1Conclusion }) +
809
- field('G2 Ready 状态', 'plan.gate2_ready', project.plan.gate2_ready, { enum: DATA.enums.g2Ready }) +
1242
+ field('计划开始', 'plan.timeline_start', project.plan.timeline_start, { date: true }) +
1243
+ field('计划结束', 'plan.timeline_end', project.plan.timeline_end, { date: true }) +
1244
+ field('G1 结论', 'plan.gate1_conclusion', project.plan.gate1_conclusion, { enum: DATA.enums.g1Conclusion }) +
1245
+ field('G2 Ready 状态', 'plan.gate2_ready', project.plan.gate2_ready, { enum: DATA.enums.g2Ready }) +
810
1246
  '</div></section>';
811
1247
  }
812
1248
 
1249
+ /**
1250
+ * This round's entry — the append-only half of the ledger.
1251
+ *
1252
+ * Kept as one section rather than split across the columns: a progress entry is
1253
+ * read as a single unit ("what happened, what proves it, who said so, what
1254
+ * next"), and splitting it would let a colleague fill the top half and forget
1255
+ * the evidence below.
1256
+ */
1257
+ /**
1258
+ * A checkbox group that picks which scenarios / criteria this round touched.
1259
+ *
1260
+ * v3.1 requires scenario_ids / criteria_ids on every progress entry, and they
1261
+ * are what makes a scenario's status derivable at all. The form shipped without
1262
+ * any way to set them, so every returned form carried an empty list and the
1263
+ * ledger could never work out which scenario a proof belonged to.
1264
+ *
1265
+ * The two lists are deliberately independent: a round can prove a criterion
1266
+ * without touching any scenario, which is why they are separate groups rather
1267
+ * than a nested scenario -> criteria tree.
1268
+ */
1269
+ function idPicker(label, path, unused, options, selected, hint) {
1270
+ if (options.length === 0) {
1271
+ return '<div class="field"><label class="field-label">' + escapeHtml(label) + '</label>' +
1272
+ '<p class="field-help">' + escapeHtml(hint) + '</p>' +
1273
+ '<p class="field-help">先在左边的计划里加上,再来勾选。</p></div>';
1274
+ }
1275
+ var chosen = {};
1276
+ for (var i = 0; i < selected.length; i += 1) chosen[text(selected[i])] = true;
1277
+ var boxes = '';
1278
+ for (var j = 0; j < options.length; j += 1) {
1279
+ var option = options[j];
1280
+ boxes += '<label class="pick">' +
1281
+ '<input type="checkbox" data-pick="' + escapeHtml(path) + '" value="' + escapeHtml(option.id) + '"' +
1282
+ (chosen[option.id] ? ' checked' : '') + '>' +
1283
+ '<span class="pick-id">' + escapeHtml(option.id) + '</span>' +
1284
+ '<span class="pick-name">' + escapeHtml(option.name || '(未命名)') + '</span>' +
1285
+ '</label>';
1286
+ }
1287
+ return '<div class="field"><label class="field-label">' + escapeHtml(label) + '</label>' +
1288
+ '<p class="field-help">' + escapeHtml(hint) + '</p>' +
1289
+ '<div class="pick-list">' + boxes + '</div></div>';
1290
+ }
1291
+
813
1292
  function progressCard(project) {
814
1293
  var entry = project.progress;
815
1294
  var evidenceRows = '';
816
1295
  for (var i = 0; i < entry.evidence.length; i += 1) {
817
- evidenceRows += '<div class="list-item">' +
1296
+ evidenceRows += '<div class="row-card"><div class="row-card-head">' +
818
1297
  '<input class="input" data-path="progress.evidence.' + i + '.title" value="' + escapeHtml(entry.evidence[i].title) + '" placeholder="证据名称,如「压测报告」">' +
819
1298
  '<input class="input" data-path="progress.evidence.' + i + '.link" value="' + escapeHtml(entry.evidence[i].link) + '" placeholder="链接(可空)">' +
820
1299
  '<button type="button" class="btn btn-sm btn-remove" data-remove="evidence" data-index="' + i + '">删</button>' +
821
- '</div>';
1300
+ '</div></div>';
822
1301
  }
823
- var head = '<section class="card"><h2 class="card-title">进展 · 这一次做了什么' +
824
- (project.existingProgressCount > 0 ? '<span class="badge badge-info">已有 ' + project.existingProgressCount + ' 条</span>' : '<span class="badge badge-warn">第一条进展</span>') +
825
- '</h2><p class="card-hint">进展是追加式的:这里填的是一条新记录,不会覆盖已有历史。日期、实际结果和下一步是必填项。</p>';
826
- var body = '<div class="grid-2">' +
827
- field('日期', 'progress.date', entry.date, { date: true, required: true }) +
828
- field('类型', 'progress.type', entry.type, { enum: DATA.enums.progressType, required: true }) +
829
- field('目标', 'progress.goal', entry.goal, {}) +
830
- field('完成度', 'progress.completion', entry.completion, { enum: DATA.enums.completion }) +
1302
+ var countBadge = project.existingProgressCount > 0
1303
+ ? '<span class="badge badge-info">已有 ' + project.existingProgressCount + ' 条</span>'
1304
+ : '<span class="badge badge-warn">第一条进展</span>';
1305
+ return '<section class="sec">' +
1306
+ '<header class="sec-head"><h2 class="sec-title">这一轮进展</h2>' +
1307
+ '<span class="sec-kicker">' + countBadge + '</span></header>' +
1308
+ '<p class="sec-hint">追加式:这里填的是第 ' + (project.existingProgressCount + 1) + ' 条新记录,不会覆盖已有历史。</p>' +
1309
+ '<div class="grid-2">' +
1310
+ field('日期', 'progress.date', entry.date, { date: true, required: true }) +
1311
+ field('类型', 'progress.type', entry.type, { enum: DATA.enums.progressType, required: true }) +
1312
+ field('这一次什么变了', 'progress.change', entry.change, { enum: DATA.enums.progressChange, required: true, help: 'v3.1 必填。「无实质进展」也是正当答案——比写空话好。' }) +
1313
+ field('完成度', 'progress.completion', entry.completion, { enum: DATA.enums.completion }) +
831
1314
  '</div>' +
1315
+ field('目标', 'progress.goal', entry.goal, {}) +
832
1316
  field('实际结果', 'progress.actual', entry.actual, { multiline: true, required: true, help: '做了什么、结果如何。没有证据的结果会被缺口规则点名。' }) +
833
- '<div class="field"><label class="field-label">证据(没有证据的结果会被点名)</label>' + evidenceRows +
834
- '<button type="button" class="btn btn-sm" data-add="evidence">+ 加一条证据</button></div>' +
1317
+ idPicker('这一轮推进了哪些场景', 'progress.scenarioIds', null, project.plan.scenarios, entry.scenarioIds,
1318
+ '勾选这一轮实际验证过的场景。场景状态(已证明 / 待客户确认 / 无证据)由这里的勾选加上证据推导出来。') +
1319
+ idPicker('这一轮验证了哪些指标', 'progress.criteriaIds', null, project.plan.criteria, entry.criteriaIds,
1320
+ '与场景相互独立:一条指标可以被验证而没有推进任何场景。') +
1321
+ '<div class="field"><label class="field-label">证据<span class="req">*</span></label>' +
1322
+ '<p class="field-help">没有证据的结果会被缺口规则点名。证据挂到勾选的场景上。</p>' + evidenceRows +
1323
+ '<button type="button" class="btn btn-sm" data-add="evidence">+ 加一条证据</button></div>' +
835
1324
  '<div class="grid-2">' +
836
- field('同步对象', 'progress.customer.synced_with', entry.customer.synced_with, {}) +
837
- field('客户认可度', 'progress.customer.recognition', entry.customer.recognition, { enum: DATA.enums.recognition }) +
838
- field('G3-1', 'progress.gate3_1', entry.gate3_1, { enum: DATA.enums.gate3_1 }) +
839
- field('G3-2', 'progress.gate3_2', entry.gate3_2, { enum: DATA.enums.gate3_2 }) +
1325
+ field('同步对象', 'progress.customer.synced_with', entry.customer.synced_with, {}) +
1326
+ field('客户认可度', 'progress.customer.recognition', entry.customer.recognition, { enum: DATA.enums.recognition }) +
1327
+ field('G3-1', 'progress.gate3_1', entry.gate3_1, { enum: DATA.enums.gate3_1 }) +
1328
+ field('G3-2', 'progress.gate3_2', entry.gate3_2, { enum: DATA.enums.gate3_2 }) +
840
1329
  '</div>' +
841
1330
  field('客户反馈', 'progress.customer.feedback', entry.customer.feedback, { multiline: true }) +
1331
+ '</section>';
1332
+ }
1333
+
1334
+ /** The closing block: next actions, spanning both columns like the detail page. */
1335
+ function nextCard(project) {
1336
+ var next = project.progress.next;
1337
+ return '<section class="sec">' +
1338
+ '<header class="sec-head"><h2 class="sec-title">下一步工作目标及计划</h2>' +
1339
+ '<span class="sec-kicker">承接 progress[].next</span></header>' +
842
1340
  '<div class="grid-2">' +
843
- field('下一步目标', 'progress.next.goal', entry.next.goal, { multiline: true, required: true }) +
844
- field('下一步负责人', 'progress.next.owner', entry.next.owner, {}) +
845
- field('下一步截止', 'progress.next.deadline', entry.next.deadline, { date: true }) +
1341
+ field('下一步目标', 'progress.next.goal', next.goal, { multiline: true, required: true }) +
1342
+ field('负责人', 'progress.next.owner', next.owner, {}) +
1343
+ field('截止日期', 'progress.next.deadline', next.deadline, { date: true }) +
846
1344
  '</div></section>';
847
- return head + body;
848
1345
  }
849
1346
 
1347
+ /** Identity: the fields the detail page keeps in its right-hand column. */
850
1348
  function identityCard(project) {
851
- return '<section class="card"><h2 class="card-title">身份</h2>' +
852
- '<p class="card-hint">立项时确定,之后很少变。客户技术责任人算 G0 五必填之一。</p>' +
1349
+ return '<section class="sec">' +
1350
+ '<header class="sec-head"><h2 class="sec-title">基本信息</h2></header>' +
853
1351
  '<div class="grid-2">' +
854
- field('项目编号', 'pocId', project.pocId, { required: DATA.mode === 'blank', help: DATA.mode === 'blank' ? '新建时必填,格式 POC-XXX。' : '' }) +
855
- field('项目名称', 'name', project.name, { required: true }) +
856
- field('体系', 'system', project.system, { enum: DATA.enums.system }) +
857
- field('客户公司', 'company', project.company, {}) +
858
- field('部门', 'department', project.department, {}) +
859
- field('预计金额(万元)', 'amountWan', project.amountWan, { number: true }) +
860
- field('项目类型', 'pocType', project.pocType, { enum: DATA.enums.pocType }) +
861
- field('阶段', 'stage', project.stage, { enum: DATA.enums.stage }) +
862
- field('状态', 'status', project.status, { enum: DATA.enums.status }) +
863
- field('进入阶段日期', 'stageSince', project.stageSince, { date: true, help: '不填就算不出停滞天数。' }) +
864
- field('负责人(我方)', 'owner', project.owner, { required: true }) +
865
- field('销售', 'sales', project.sales, {}) +
866
- field('客户技术责任人', 'techOwner', project.techOwner, { required: true, help: 'G0 五必填之一。' }) +
867
- field('客户业务决策人', 'execSponsor', project.execSponsor, {}) +
1352
+ field('项目编号', 'pocId', project.pocId, { required: DATA.mode === 'blank', help: DATA.mode === 'blank' ? '新建时必填,格式 POC-XXX。' : '' }) +
1353
+ field('项目名称', 'name', project.name, { required: true }) +
1354
+ field('体系', 'system', project.system, { enum: DATA.enums.system }) +
1355
+ field('客户公司', 'company', project.company, {}) +
1356
+ field('部门', 'department', project.department, {}) +
1357
+ field('预计金额(万元)', 'amountWan', project.amountWan, { number: true }) +
1358
+ field('项目类型', 'pocType', project.pocType, { enum: DATA.enums.pocType }) +
1359
+ field('阶段', 'stage', project.stage, { enum: DATA.enums.stage }) +
1360
+ field('状态', 'status', project.status, { enum: DATA.enums.status }) +
1361
+ field('进入阶段日期', 'stageSince', project.stageSince, { date: true, help: '不填就算不出停滞天数。' }) +
1362
+ field('负责人(我方)', 'owner', project.owner, { required: true }) +
1363
+ field('销售', 'sales', project.sales, {}) +
1364
+ field('客户技术责任人', 'techOwner', project.techOwner, { required: true, help: 'G0 五必填之一。' }) +
1365
+ field('客户业务决策人', 'execSponsor', project.execSponsor, {}) +
868
1366
  '</div></section>';
869
1367
  }
870
1368
 
1369
+ /**
1370
+ * The readiness strip: what this form will still be missing after it is filled.
1371
+ *
1372
+ * Mirrors the dashboard's reminder band. A colleague filling a form cannot know
1373
+ * that a blank 'stage_since' makes the stall clock uncomputable, or that an
1374
+ * unpassed G0 blocks the upgrade review — so the form says it while they can
1375
+ * still fix it, rather than surfacing it weeks later on the dashboard.
1376
+ */
1377
+ function readinessCard(project, canEdit) {
1378
+ var editable = canEdit || {};
1379
+ var gate0Filled = 0;
1380
+ for (var i = 0; i < DATA.g0Fields.length; i += 1) {
1381
+ if (text(project.gate0[DATA.g0Fields[i].key]).trim() !== '') gate0Filled += 1;
1382
+ }
1383
+ if (text(project.techOwner).trim() !== '') gate0Filled += 1;
1384
+
1385
+ var clocks = [];
1386
+ if (text(project.stageSince).trim() === '') clocks.push('进入阶段日期');
1387
+ if (text(project.gate0.reviewed_at).trim() === '') clocks.push('G0 评审日期');
1388
+ var clockTone = clocks.length === 0 ? 'green' : 'slate';
1389
+ var clockValue = clocks.length === 0
1390
+ ? '两个时钟都已启动,停滞与陈旧能算出来'
1391
+ : '缺 ' + clocks.join('、') + ' —— 补了才算得出停滞和陈旧';
1392
+
1393
+ var conclusion = text(project.gate0.conclusion).trim();
1394
+ var gateTone = 'slate';
1395
+ var gateValue = '还没有 G0 评审结论';
1396
+ if (conclusion === '通过' && gate0Filled === 5) {
1397
+ gateTone = 'amber';
1398
+ gateValue = '五必填已齐且评审通过 —— 可以申请升 G1';
1399
+ } else if (conclusion === '未通过-退出' || conclusion === '未通过-降级') {
1400
+ gateTone = 'red';
1401
+ gateValue = 'G0 结论「' + conclusion + '」,不再提示升级';
1402
+ } else if (gate0Filled === 5) {
1403
+ gateTone = 'green';
1404
+ gateValue = '五必填已齐,可以安排 G0 评审';
1405
+ } else {
1406
+ gateValue = '还缺 ' + (5 - gate0Filled) + ' 项,评审前要补齐';
1407
+ }
1408
+
1409
+ var crit = project.plan.criteria.length;
1410
+ var scn = project.plan.scenarios.length;
1411
+ var focusTone = (crit >= 2 && crit <= 3 && scn >= 3 && scn <= 5) ? 'green' : 'amber';
1412
+ var focusValue = '指标 ' + crit + ' 条、场景 ' + scn + ' 个';
1413
+
1414
+ var tone = gateTone === 'red' ? 'red' : (clockTone === 'slate' || focusTone === 'amber' || gateTone === 'amber') ? 'amber' : 'green';
1415
+ return '<section class="readiness" data-tone="' + tone + '">' +
1416
+ '<div class="ready-cell"><span class="ready-label">Gate 0 五必填</span>' +
1417
+ '<span class="ready-value">' + gate0Filled + ' / 5 · ' + escapeHtml(gateValue) + '</span></div>' +
1418
+ '<div class="ready-cell"><span class="ready-label">陈旧度时钟</span>' +
1419
+ '<span class="ready-value">' + escapeHtml(clockValue) + '</span></div>' +
1420
+ // The focus cell only means something once a plan is expected. A brand-new
1421
+ // project has no plan by design (R3 asks for one only after G0 passes), so
1422
+ // showing "0 条指标,要求 2–3" would invent a failure.
1423
+ (DATA.intent === 'new' ? '' :
1424
+ '<div class="ready-cell"><span class="ready-label">计划聚焦</span>' +
1425
+ '<span class="ready-value">' + escapeHtml(focusValue) +
1426
+ (focusTone === 'green' ? '' : ' · 要求指标 2–3、场景 3–5') + '</span></div>') +
1427
+ '</section>';
1428
+ }
1429
+
1430
+ /**
1431
+ * The page: banner, readiness strip, then the detail page's fixed two columns.
1432
+ *
1433
+ * Commitments left (Gate 0, criteria, scenarios), the record right (identity,
1434
+ * plan narrative, risks, gates), next actions closing across both. That is the
1435
+ * same contract the detail page holds at every gate, so the person filling the
1436
+ * form and the person reading the dashboard are looking at the same layout.
1437
+ */
871
1438
  function render() {
872
1439
  var project = current();
1440
+ var title = project.name || project.pocId || '新建项目';
1441
+ var meta = [];
1442
+ if (project.pocId) meta.push('<span class="banner-id">' + escapeHtml(project.pocId) + '</span>');
1443
+ var org = [project.system, project.company, project.pocType].filter(function (item) { return text(item).trim() !== ''; });
1444
+ if (org.length) meta.push('<span>' + escapeHtml(org.join(' · ')) + '</span>');
1445
+ if (text(project.owner).trim() !== '') meta.push('<span>我方 Owner ' + escapeHtml(project.owner) + '</span>');
1446
+
1447
+ var pills = '';
1448
+ if (text(project.stage).trim() !== '') pills += '<span class="pill pill-blue"><span class="pill-dot"></span>' + escapeHtml(project.stage) + '</span>';
1449
+ if (text(project.status).trim() !== '') pills += '<span class="pill pill-slate"><span class="pill-dot"></span>' + escapeHtml(project.status) + '</span>';
1450
+ var amount = text(project.amountWan).trim();
1451
+ if (amount !== '') pills += '<span class="pill pill-amber">' + escapeHtml(amount) + ' 万元</span>';
1452
+
873
1453
  var switcher = '';
874
1454
  if (DATA.projects.length > 1) {
875
- switcher = '<div class="notice">当前编辑:第 ' + (state.active + 1) + ' / ' + DATA.projects.length + ' 个项目' +
876
- ' <select class="select" id="projectSwitch" style="width:auto;display:inline-block;margin-left:8px">';
1455
+ switcher = '<div class="banner-step">第 ' + (state.active + 1) + ' / ' + DATA.projects.length + ' 个项目' +
1456
+ ' <select class="select" id="projectSwitch" style="width:auto;display:inline-block">';
877
1457
  for (var i = 0; i < DATA.projects.length; i += 1) {
878
1458
  switcher += '<option value="' + i + '"' + (i === state.active ? ' selected' : '') + '>' +
879
1459
  escapeHtml(DATA.projects[i].name || DATA.projects[i].pocId || '未命名') + '</option>';
880
1460
  }
881
1461
  switcher += '</select></div>';
882
1462
  }
883
- byId('formBody').innerHTML = switcher + identityCard(project) + g0Card(project) + planCard(project) + progressCard(project);
884
- var switchNode = byId('projectSwitch');
885
- if (switchNode) {
886
- switchNode.addEventListener('change', function (event) {
887
- state.active = Number(event.target.value);
888
- render();
889
- });
1463
+
1464
+ var banner = '<header class="banner">' +
1465
+ '<div class="banner-main">' +
1466
+ '<span class="banner-kicker">POC 信息收集 · ' + intentLabel() + '</span>' +
1467
+ '<h1 class="banner-title">' + escapeHtml(title) + '</h1>' +
1468
+ '<div class="banner-meta">' + meta.join('') + '</div>' +
1469
+ '</div>' +
1470
+ '<div class="banner-side">' +
1471
+ '<div class="banner-pills">' + pills + '</div>' +
1472
+ '<div class="banner-actions"><span class="save-status" id="saveStatus">已就绪</span>' +
1473
+ '<button type="button" class="btn" id="clearBtn">清空草稿</button></div>' +
1474
+ '</div>' +
1475
+ (switcher ? '<nav class="banner-nav">' + switcher + '</nav>' : '') +
1476
+ '</header>';
1477
+
1478
+ // Which sections this page is about, resolved on the Host from the intent
1479
+ // and the project's stage. Everything outside 'editable' is shown collapsed
1480
+ // and read-only, so a colleague adding a progress round never scrolls past
1481
+ // twenty fields they are not editing.
1482
+ var plan_ = DATA.sections[state.active] || { editable: ['identity', 'gate0', 'plan', 'progress'], context: [] };
1483
+ var canEdit = {};
1484
+ for (var e = 0; e < plan_.editable.length; e += 1) canEdit[plan_.editable[e]] = true;
1485
+
1486
+ var body = banner + readinessCard(project, canEdit);
1487
+
1488
+ // 'progress' intent is the one-screen case: the round and nothing else.
1489
+ if (DATA.intent === 'progress') {
1490
+ body += progressCard(project) + nextCard(project);
1491
+ byId('formBody').innerHTML = body;
1492
+ bindSwitch();
1493
+ markFooter();
1494
+ return;
890
1495
  }
1496
+
1497
+ var left = '';
1498
+ if (canEdit.gate0) left += g0Card(project); else left += contextGate0(project);
1499
+ // A new project has no plan yet, so there is nothing to show read-only —
1500
+ // an empty "方案 · 只读" block would only suggest work that does not exist.
1501
+ if (canEdit.plan) left += planCard(project);
1502
+ else if (DATA.intent !== 'new') left += contextPlan(project);
1503
+
1504
+ var right = '';
1505
+ if (canEdit.identity) right += identityCard(project); else right += contextIdentity(project);
1506
+ if (canEdit.plan) right += planNarrative(project) + riskCard(project);
1507
+ if (canEdit.gate12) right += gateCard(project);
1508
+ if (canEdit.outcome) right += outcomeCard(project);
1509
+
1510
+ if (left !== '') body += '<div class="columns"><div class="col">' + left + '</div><div class="col">' + right + '</div></div>';
1511
+ else if (right !== '') body += '<div class="columns"><div class="col"></div><div class="col">' + right + '</div></div>';
1512
+
1513
+ if (canEdit.progress || DATA.intent === 'new') body += progressCard(project) + nextCard(project);
1514
+
1515
+ byId('formBody').innerHTML = body;
1516
+ bindSwitch();
1517
+ markFooter();
1518
+ }
1519
+
1520
+ /** Wire the project switcher, if the batch has more than one project. */
1521
+ function bindSwitch() {
1522
+ var switchNode = byId('projectSwitch');
1523
+ if (!switchNode) return;
1524
+ switchNode.addEventListener('change', function (event) {
1525
+ state.active = Number(event.target.value);
1526
+ render();
1527
+ });
1528
+ }
1529
+
1530
+ /** The intent, as a phrase for the banner and the footer. */
1531
+ function intentLabel() {
1532
+ return DATA.intent === 'new' ? '新建项目' : DATA.intent === 'progress' ? '记录进展' : '补充信息';
1533
+ }
1534
+
1535
+ function markFooter() {
891
1536
  var info = byId('footerInfo');
892
- if (info) {
893
- info.textContent = '共 ' + DATA.projects.length + ' 个项目 · 草稿自动保存在本机浏览器';
1537
+ if (!info) return;
1538
+ info.textContent = intentLabel() + ' · 共 ' + DATA.projects.length + ' 个项目 · 草稿自动保存在本机浏览器';
1539
+ }
1540
+
1541
+ /** Read-only Gate 0 summary: a completed stage is context, not a task. */
1542
+ function contextGate0(project) {
1543
+ var present = 0;
1544
+ for (var i = 0; i < DATA.g0Fields.length; i += 1) {
1545
+ if (text(project.gate0[DATA.g0Fields[i].key]).trim() !== '') present += 1;
894
1546
  }
1547
+ if (text(project.techOwner).trim() !== '') present += 1;
1548
+ var tone = present === 5 ? 'badge-ok' : 'badge-warn';
1549
+ return '<section class="sec">' +
1550
+ '<header class="sec-head"><h2 class="sec-title">Gate 0 · 只读</h2>' +
1551
+ '<span class="sec-kicker"><span class="badge ' + tone + '">五必填 ' + present + ' / 5</span></span></header>' +
1552
+ '<p class="sec-hint">这一阶段已完成,内容作为上下文展示。要修改请单独导出「补充信息」表单并选择 G0。</p>' +
1553
+ '</section>';
1554
+ }
1555
+
1556
+ /** Read-only plan summary. */
1557
+ function contextPlan(project) {
1558
+ var crit = project.plan.criteria.length;
1559
+ var scn = project.plan.scenarios.length;
1560
+ return '<section class="sec">' +
1561
+ '<header class="sec-head"><h2 class="sec-title">方案 · 只读</h2>' +
1562
+ '<span class="sec-kicker">指标 ' + crit + ' · 场景 ' + scn + '</span></header>' +
1563
+ '<p class="sec-hint">方案已锁定为只读。要改计划,请导出「补充信息」表单并选择对应阶段。</p>' +
1564
+ '</section>';
1565
+ }
1566
+
1567
+ /** Read-only identity summary: the fields a colleague must not re-edit here. */
1568
+ function contextIdentity(project) {
1569
+ var bits = [];
1570
+ if (project.pocId) bits.push(project.pocId);
1571
+ if (project.system) bits.push(project.system);
1572
+ if (project.company) bits.push(project.company);
1573
+ if (project.owner) bits.push('Owner ' + project.owner);
1574
+ return '<section class="sec">' +
1575
+ '<header class="sec-head"><h2 class="sec-title">基本信息 · 只读</h2></header>' +
1576
+ '<p class="sec-hint">' + escapeHtml(bits.join(' · ') || '未填写') + '</p>' +
1577
+ '</section>';
1578
+ }
1579
+
1580
+ /** The G4 block: conclusion and conversion, which no other stage asks for. */
1581
+ function outcomeCard(project) {
1582
+ var o = project.outcome || {};
1583
+ return '<section class="sec">' +
1584
+ '<header class="sec-head"><h2 class="sec-title">结论与转化</h2>' +
1585
+ '<span class="sec-kicker">G4</span></header>' +
1586
+ '<p class="sec-hint">这一阶段要回答:证明了什么、客户认可什么、下一步业务动作是什么。</p>' +
1587
+ field('我们证明了什么', 'outcome.conclusion.proved', o.proved || '', { multiline: true }) +
1588
+ field('客户认可了什么', 'outcome.conclusion.recognized', o.recognized || '', { multiline: true }) +
1589
+ field('下一步业务动作', 'outcome.conclusion.next_business', o.next_business || '', { multiline: true }) +
1590
+ field('我方证据', 'outcome.our_proof', o.our_proof || '', { multiline: true }) +
1591
+ '<div class="grid-2">' +
1592
+ field('目标达成', 'outcome.achievement', o.achievement || '', { enum: DATA.enums.achievement }) +
1593
+ field('客户认可', 'outcome.customer_recognition', o.customer_recognition || '', { enum: DATA.enums.recognition }) +
1594
+ field('Next Milestone', 'outcome.business.milestone', o.milestone || '') +
1595
+ field('业务负责人', 'outcome.business.owner', o.businessOwner || '') +
1596
+ field('业务截止', 'outcome.business.deadline', o.businessDeadline || '', { date: true }) +
1597
+ field('业务状态', 'outcome.business.status', o.businessStatus || '', { enum: DATA.enums.businessStatus }) +
1598
+ '</div>' +
1599
+ field('总体结论', 'outcome.overall', o.overall || '', { multiline: true }) +
1600
+ '</section>';
895
1601
  }
896
1602
 
897
1603
  function setPathOn(project, path, value) {
@@ -917,6 +1623,19 @@ const FORM_SCRIPT = `
917
1623
  document.addEventListener('change', function (event) {
918
1624
  var target = event.target;
919
1625
  if (!target || !target.getAttribute) return;
1626
+ // A picker checkbox writes an id LIST, not a scalar, so it takes its own
1627
+ // branch: routing it through setPath would replace the array with "on".
1628
+ var pickPath = target.getAttribute('data-pick');
1629
+ if (pickPath) {
1630
+ var entry = current().progress;
1631
+ var list = pickPath === 'progress.scenarioIds' ? entry.scenarioIds : entry.criteriaIds;
1632
+ var id = target.value;
1633
+ var at = list.indexOf(id);
1634
+ if (target.checked && at < 0) list.push(id);
1635
+ if (!target.checked && at >= 0) list.splice(at, 1);
1636
+ scheduleSave();
1637
+ return;
1638
+ }
920
1639
  var path = target.getAttribute('data-path');
921
1640
  if (!path) return;
922
1641
  setPathOn(current(), path, target.value);
@@ -930,8 +1649,8 @@ const FORM_SCRIPT = `
930
1649
  var addKey = target.getAttribute('data-add');
931
1650
  var removeKey = target.getAttribute('data-remove');
932
1651
  if (addKey) {
933
- if (addKey === 'criteria') project.plan.criteria.push({ name: '', metric: '', baseline: '', target: '' });
934
- if (addKey === 'scenarios') project.plan.scenarios.push('');
1652
+ if (addKey === 'criteria') project.plan.criteria.push(nextRow('cri', project.plan.criteria, { name: '', metric: '', baseline: '', target: '' }));
1653
+ if (addKey === 'scenarios') project.plan.scenarios.push(nextRow('scn', project.plan.scenarios, { name: '', goal: '' }));
935
1654
  if (addKey === 'risks') project.plan.risks.push({ name: '', level: '', mitigation: '' });
936
1655
  if (addKey === 'evidence') project.progress.evidence.push({ title: '', link: '', type: '' });
937
1656
  scheduleSave();
@@ -1011,14 +1730,20 @@ const FORM_SCRIPT = `
1011
1730
  var criteria = project.plan.criteria.filter(function (item) { return text(item.name).trim() !== ''; });
1012
1731
  if (criteria.length === 0) { lines[lines.length - 1] = ' criteria: []'; }
1013
1732
  for (i = 0; i < criteria.length; i += 1) {
1014
- lines.push(' - name: ' + scalar(criteria[i].name));
1733
+ // v3.1: the id comes first because it is the join key evidence uses.
1734
+ lines.push(' - id: ' + scalar(criteria[i].id));
1735
+ lines.push(' name: ' + scalar(criteria[i].name));
1015
1736
  lines.push(' metric: ' + scalar(criteria[i].metric));
1016
1737
  lines.push(' baseline: ' + scalar(criteria[i].baseline));
1017
1738
  lines.push(' target: ' + scalar(criteria[i].target));
1018
1739
  }
1019
- var scenarios = project.plan.scenarios.filter(function (item) { return text(item).trim() !== ''; });
1740
+ var scenarios = project.plan.scenarios.filter(function (item) { return text(item.name).trim() !== ''; });
1020
1741
  lines.push(' scenarios:' + (scenarios.length === 0 ? ' []' : ''));
1021
- for (i = 0; i < scenarios.length; i += 1) lines.push(' - ' + scalar(scenarios[i]));
1742
+ for (i = 0; i < scenarios.length; i += 1) {
1743
+ lines.push(' - id: ' + scalar(scenarios[i].id));
1744
+ lines.push(' name: ' + scalar(scenarios[i].name));
1745
+ lines.push(' goal: ' + scalar(scenarios[i].goal));
1746
+ }
1022
1747
  var risks = project.plan.risks.filter(function (item) { return text(item.name).trim() !== ''; });
1023
1748
  lines.push(' risks:' + (risks.length === 0 ? ' []' : ''));
1024
1749
  for (i = 0; i < risks.length; i += 1) {
@@ -1064,17 +1789,138 @@ const FORM_SCRIPT = `
1064
1789
  return lines.join('\\n') + '\\n';
1065
1790
  }
1066
1791
 
1792
+ /**
1793
+ * Serialize the whole page to the change document a colleague sends back.
1794
+ *
1795
+ * This is the DOWNLOAD format. It carries only the fields a human filled in,
1796
+ * never the ledger's derived values: 'gate0.missing', 'gate0.complete',
1797
+ * 'priority' and the per-scenario statuses are computed by 'tools/derive.mjs'
1798
+ * and asserted by CI, so a form that wrote them would be either wrong or
1799
+ * overwritten. 'poc-submit' merges this object into the existing project file
1800
+ * and leaves everything else — including 'gate_decisions', existing progress
1801
+ * history and gate verdicts — untouched.
1802
+ */
1803
+ function toChangeDocument() {
1804
+ var changes = [];
1805
+ for (var i = 0; i < DATA.projects.length; i += 1) {
1806
+ changes.push(changeSetOf(DATA.projects[i]));
1807
+ }
1808
+ return {
1809
+ schemaVersion: DATA.schemaVersion,
1810
+ generatedAt: new Date().toISOString(),
1811
+ generatedBy: 'POC 信息收集表单 v3.1',
1812
+ intent: DATA.intent,
1813
+ changes: changes
1814
+ };
1815
+ }
1816
+
1817
+ /** One project's human-authored fields, with '' collapsed to null. */
1818
+ function changeSetOf(project) {
1819
+ function orNull(value) {
1820
+ var raw = text(value).trim();
1821
+ return raw === '' ? null : raw;
1822
+ }
1823
+ var criteria = [];
1824
+ for (var i = 0; i < project.plan.criteria.length; i += 1) {
1825
+ var c = project.plan.criteria[i];
1826
+ if (text(c.name).trim() === '') continue;
1827
+ criteria.push({ id: orNull(c.id), name: text(c.name).trim(), metric: orNull(c.metric), baseline: orNull(c.baseline), target: orNull(c.target) });
1828
+ }
1829
+ var scenarios = [];
1830
+ for (var j = 0; j < project.plan.scenarios.length; j += 1) {
1831
+ var sc = project.plan.scenarios[j];
1832
+ if (text(sc.name).trim() === '') continue;
1833
+ scenarios.push({ id: orNull(sc.id), name: text(sc.name).trim(), goal: orNull(sc.goal) });
1834
+ }
1835
+ var risks = [];
1836
+ for (var k = 0; k < project.plan.risks.length; k += 1) {
1837
+ var r = project.plan.risks[k];
1838
+ if (text(r.name).trim() === '') continue;
1839
+ risks.push({ name: text(r.name).trim(), level: orNull(r.level), mitigation: orNull(r.mitigation) });
1840
+ }
1841
+ var rounds = [];
1842
+ var entry = project.progress;
1843
+ var touched = text(entry.date).trim() !== '' || text(entry.actual).trim() !== '' || text(entry.goal).trim() !== '';
1844
+ if (touched) rounds.push(progressEntryOf(entry));
1845
+ return {
1846
+ schema_version: DATA.schemaVersion,
1847
+ poc_id: text(project.pocId).trim(),
1848
+ name: text(project.name).trim(),
1849
+ org: { system: orNull(project.system), company: orNull(project.company), department: orNull(project.department) },
1850
+ amount_wan: text(project.amountWan).trim() === '' ? null : Number(project.amountWan),
1851
+ poc_type: orNull(project.pocType),
1852
+ owner: orNull(project.owner),
1853
+ sales: orNull(project.sales),
1854
+ tech_owner: orNull(project.techOwner),
1855
+ exec_sponsor: orNull(project.execSponsor),
1856
+ stage: project.stage,
1857
+ status: project.status,
1858
+ stage_since: orNull(project.stageSince),
1859
+ gate0: {
1860
+ why_customer: orNull(project.gate0.why_customer),
1861
+ why_us: orNull(project.gate0.why_us),
1862
+ decision_chain: orNull(project.gate0.decision_chain),
1863
+ post_poc_decision: orNull(project.gate0.post_poc_decision),
1864
+ competitor: orNull(project.gate0.competitor),
1865
+ review: { conclusion: orNull(project.gate0.conclusion), reviewer: orNull(project.gate0.reviewer), reviewed_at: orNull(project.gate0.reviewed_at) }
1866
+ },
1867
+ plan: {
1868
+ customer_pain: orNull(project.plan.customer_pain),
1869
+ expected_recognition: orNull(project.plan.expected_recognition),
1870
+ our_edge: orNull(project.plan.our_edge),
1871
+ criteria: criteria,
1872
+ scenarios: scenarios,
1873
+ risks: risks,
1874
+ timeline: { start: orNull(project.plan.timeline_start), end: orNull(project.plan.timeline_end) },
1875
+ gate1: { conclusion: orNull(project.plan.gate1_conclusion) },
1876
+ gate2: { ready: orNull(project.plan.gate2_ready) }
1877
+ },
1878
+ progress: rounds
1879
+ };
1880
+ }
1881
+
1882
+ /** One appended round, in the ledger's v3.1 shape. */
1883
+ function progressEntryOf(entry) {
1884
+ function orNull(value) {
1885
+ var raw = text(value).trim();
1886
+ return raw === '' ? null : raw;
1887
+ }
1888
+ var evidence = [];
1889
+ for (var i = 0; i < entry.evidence.length; i += 1) {
1890
+ var item = entry.evidence[i];
1891
+ if (text(item.title).trim() === '') continue;
1892
+ evidence.push({ title: text(item.title).trim(), link: orNull(item.link), type: orNull(item.type) });
1893
+ }
1894
+ var scnIds = [];
1895
+ for (var j = 0; j < entry.scenarioIds.length; j += 1) if (text(entry.scenarioIds[j]).trim() !== '') scnIds.push(text(entry.scenarioIds[j]).trim());
1896
+ var criIds = [];
1897
+ for (var k = 0; k < entry.criteriaIds.length; k += 1) if (text(entry.criteriaIds[k]).trim() !== '') criIds.push(text(entry.criteriaIds[k]).trim());
1898
+ return {
1899
+ date: orNull(entry.date),
1900
+ type: orNull(entry.type),
1901
+ change: orNull(entry.change),
1902
+ goal: orNull(entry.goal),
1903
+ scenario_ids: scnIds,
1904
+ criteria_ids: criIds,
1905
+ actual: orNull(entry.actual),
1906
+ completion: orNull(entry.completion),
1907
+ evidence: evidence,
1908
+ customer: { synced_with: orNull(entry.customer.synced_with), feedback: orNull(entry.customer.feedback), recognition: orNull(entry.customer.recognition) },
1909
+ gate3_1: orNull(entry.gate3_1),
1910
+ gate3_2: orNull(entry.gate3_2),
1911
+ next: { goal: orNull(entry.next.goal), owner: orNull(entry.next.owner), deadline: orNull(entry.next.deadline) }
1912
+ };
1913
+ }
1914
+
1067
1915
  function previewYaml() {
1068
1916
  var node = byId('yamlPreview');
1069
1917
  if (!node) return;
1070
- var all = [];
1071
- for (var i = 0; i < DATA.projects.length; i += 1) {
1072
- all.push('# ' + (DATA.projects[i].pocId || '新项目'));
1073
- all.push(toYaml(DATA.projects[i]));
1074
- }
1075
- node.textContent = all.join('\\n');
1918
+ node.textContent = JSON.stringify(toChangeDocument(), null, 2);
1076
1919
  node.hidden = false;
1077
- node.scrollIntoView({ behavior: 'smooth', block: 'start' });
1920
+ // Guarded: scrollIntoView is absent in jsdom and in a few older embedded
1921
+ // webviews. Scrolling is a convenience, so a missing implementation must not
1922
+ // throw after the preview has already been rendered.
1923
+ if (node.scrollIntoView) node.scrollIntoView({ behavior: 'smooth', block: 'start' });
1078
1924
  }
1079
1925
 
1080
1926
  function downloadYaml() {
@@ -1083,23 +1929,23 @@ const FORM_SCRIPT = `
1083
1929
  return;
1084
1930
  }
1085
1931
  var stamp = DATA.today.replace(/-/g, '');
1086
- for (var i = 0; i < DATA.projects.length; i += 1) {
1087
- var project = DATA.projects[i];
1088
- var blob = new Blob([toYaml(project)], { type: 'text/yaml;charset=utf-8' });
1089
- var url = URL.createObjectURL(blob);
1090
- var anchor = document.createElement('a');
1091
- anchor.href = url;
1092
- anchor.download = (project.pocId.trim() === '' ? 'new' : project.pocId.trim()) + '-' + stamp + '.yaml';
1093
- document.body.appendChild(anchor);
1094
- anchor.click();
1095
- document.body.removeChild(anchor);
1096
- setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
1097
- }
1098
- showToast('已下载 ' + DATA.projects.length + ' 个 YAML 文件');
1932
+ var document_ = toChangeDocument();
1933
+ var blob = new Blob([JSON.stringify(document_, null, 2)], { type: 'application/json;charset=utf-8' });
1934
+ var url = URL.createObjectURL(blob);
1935
+ var anchor = document.createElement('a');
1936
+ anchor.href = url;
1937
+ // One file for the whole batch: the merge step keys off 'changes[]', and a
1938
+ // batch is what the colleague was handed.
1939
+ anchor.download = 'poc-changes-' + stamp + '.json';
1940
+ document.body.appendChild(anchor);
1941
+ anchor.click();
1942
+ document.body.removeChild(anchor);
1943
+ setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
1944
+ showToast('已下载 poc-changes-' + stamp + '.json');
1099
1945
  save(true);
1100
1946
  }
1101
1947
 
1102
- /** The three bare-minimum required fields, checked before a download. */
1948
+ /** The bare-minimum required fields, checked before a download. */
1103
1949
  function validateRequired() {
1104
1950
  var ok = true;
1105
1951
  var project = current();
@@ -1108,6 +1954,10 @@ const FORM_SCRIPT = `
1108
1954
  ['owner', project.owner],
1109
1955
  ['techOwner', project.techOwner],
1110
1956
  ['progress.date', project.progress.date],
1957
+ // v3.1 makes 'change' mandatory: a round that does not say what moved is
1958
+ // how a timeline decays into "communicated with customer". The ledger
1959
+ // rejects a null, so the form must refuse to download one.
1960
+ ['progress.change', project.progress.change],
1111
1961
  ['progress.actual', project.progress.actual],
1112
1962
  ['progress.next.goal', project.progress.next.goal]
1113
1963
  ];