@skillre/dsh-plugin-work-dashboard 0.6.0 → 0.9.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 ADDED
@@ -0,0 +1,1075 @@
1
+ /**
2
+ * The v3 collection form: a self-contained HTML file a colleague can fill in.
3
+ *
4
+ * ## What changed from the v1 form
5
+ *
6
+ * The v1 generator modelled `why_customer_test` / `success_criteria` /
7
+ * `result` / `timeline` — all removed by v3. Shipping it would have handed
8
+ * colleagues a file the ledger can no longer read, so it was held back while
9
+ * this replacement was written, and then deleted.
10
+ *
11
+ * v3 is **progress-centred**: `gate0` says whether the project is worth doing,
12
+ * `plan` says how to win, and `progress[]` is the append-only history. The form
13
+ * therefore asks for exactly those three, and nothing else:
14
+ *
15
+ * 1. **G0** — the five prerequisites (four here; `tech_owner` is identity, which
16
+ * the blank form asks for too), each with a "why this matters" hint.
17
+ * 2. **Plan** — pain, expected recognition, 2–3 criteria, 3–5 scenarios, ≤3
18
+ * risks, edge. The counts are validated live because the gap rules enforce
19
+ * them and a colleague cannot know that.
20
+ * 3. **Progress** — one new entry, appended. The form never rewrites history.
21
+ *
22
+ * ## What is kept from v1 because it was hard-won
23
+ *
24
+ * - **One file, no server, no CDN.** Everything inlined, works offline.
25
+ * - **Autosave keyed by the project set**, not by a timestamp: regenerating the
26
+ * form for the same projects must find the same draft.
27
+ * - **Real YAML out**, via `yaml`'s own stringifier, so `name: 某某:试点` stays
28
+ * valid.
29
+ * - **One file per project** on download, so two colleagues never clobber a
30
+ * shared file.
31
+ *
32
+ * ## What it deliberately does NOT do
33
+ *
34
+ * It does not write to the ledger. The output is a `.yaml` the owner reviews and
35
+ * commits; submission stays a human-merged PR, which is the ledger's design.
36
+ */
37
+ import YAML from 'yaml';
38
+ /** The four G0 prerequisites that live under `gate0` (the fifth is identity). */
39
+ export const G0_FIELDS = Object.freeze([
40
+ 'why_customer',
41
+ 'why_us',
42
+ 'decision_chain',
43
+ 'post_poc_decision',
44
+ ]);
45
+ /** Coerce a stored value to the string the form edits. */
46
+ function text(value) {
47
+ if (value === null || value === undefined)
48
+ return '';
49
+ if (typeof value === 'string')
50
+ return value;
51
+ if (typeof value === 'number' || typeof value === 'boolean')
52
+ return String(value);
53
+ return '';
54
+ }
55
+ /** A `YYYY-MM-DD` date, or `''`. */
56
+ function dateText(value) {
57
+ const raw = text(value);
58
+ return /^\d{4}-\d{2}-\d{2}$/.test(raw) ? raw : '';
59
+ }
60
+ /**
61
+ * Convert one ledger record into the form's project shape.
62
+ *
63
+ * Every field becomes a string or a list of strings. A missing block becomes an
64
+ * empty one rather than `undefined`, so the generated script never has to guard.
65
+ */
66
+ export function projectForForm(record) {
67
+ const gate0 = record.gate0 ?? {};
68
+ const plan = record.plan ?? {};
69
+ const progress = Array.isArray(record.progress) ? record.progress : [];
70
+ const org = record.org ?? {};
71
+ const review = gate0.review ?? {};
72
+ return {
73
+ pocId: text(record.poc_id),
74
+ name: text(record.name),
75
+ system: text(org.system),
76
+ company: text(org.company),
77
+ department: text(org.department),
78
+ amountWan: numberText(record.amount_wan),
79
+ pocType: text(record.poc_type),
80
+ owner: text(record.owner),
81
+ sales: text(record.sales),
82
+ techOwner: text(record.tech_owner),
83
+ execSponsor: text(record.exec_sponsor),
84
+ stage: text(record.stage),
85
+ status: text(record.status),
86
+ stageSince: dateText(record.stage_since),
87
+ gate0: {
88
+ why_customer: text(gate0.why_customer),
89
+ why_us: text(gate0.why_us),
90
+ decision_chain: text(gate0.decision_chain),
91
+ post_poc_decision: text(gate0.post_poc_decision),
92
+ competitor: text(gate0.competitor),
93
+ conclusion: text(review.conclusion),
94
+ reviewer: text(review.reviewer),
95
+ reviewed_at: dateText(review.reviewed_at),
96
+ },
97
+ plan: {
98
+ customer_pain: text(plan.customer_pain),
99
+ expected_recognition: text(plan.expected_recognition),
100
+ our_edge: text(plan.our_edge),
101
+ criteria: (Array.isArray(plan.criteria) ? plan.criteria : []).map((item) => ({
102
+ name: text(item?.name),
103
+ metric: text(item?.metric),
104
+ baseline: text(item?.baseline),
105
+ target: text(item?.target),
106
+ })),
107
+ scenarios: (Array.isArray(plan.scenarios) ? plan.scenarios : []).map(text).filter((item) => item !== ''),
108
+ risks: (Array.isArray(plan.risks) ? plan.risks : []).map((item) => ({
109
+ name: text(item?.name),
110
+ level: text(item?.level).toLowerCase(),
111
+ mitigation: text(item?.mitigation),
112
+ })),
113
+ timeline_start: dateText(plan.timeline?.start),
114
+ timeline_end: dateText(plan.timeline?.end),
115
+ gate1_conclusion: text(plan.gate1?.conclusion),
116
+ gate2_ready: text(plan.gate2?.ready),
117
+ },
118
+ progress: blankProgress(progress.length),
119
+ existingProgressCount: progress.length,
120
+ };
121
+ }
122
+ /** A numeric field as the form's string, keeping `0` distinct from blank. */
123
+ function numberText(value) {
124
+ if (typeof value === 'number' && Number.isFinite(value))
125
+ return String(value);
126
+ const raw = text(value);
127
+ return raw === '' ? '' : raw;
128
+ }
129
+ /** One empty progress entry, with `seq` continuing the existing count. */
130
+ export function blankProgress(existingCount) {
131
+ return {
132
+ seq: existingCount + 1,
133
+ date: '',
134
+ type: '',
135
+ goal: '',
136
+ items: [''],
137
+ actual: '',
138
+ completion: '',
139
+ evidence: [],
140
+ customer: { synced_with: '', feedback: '', recognition: '' },
141
+ gate3_1: '',
142
+ gate3_2: '',
143
+ next: { goal: '', owner: '', deadline: '' },
144
+ };
145
+ }
146
+ /** The blank project a `blank`-mode form edits. */
147
+ export function blankProject() {
148
+ return {
149
+ pocId: '',
150
+ name: '',
151
+ system: '',
152
+ company: '',
153
+ department: '',
154
+ amountWan: '',
155
+ pocType: '',
156
+ owner: '',
157
+ sales: '',
158
+ techOwner: '',
159
+ execSponsor: '',
160
+ stage: 'G0-立项',
161
+ status: '进行中',
162
+ stageSince: '',
163
+ gate0: {
164
+ why_customer: '',
165
+ why_us: '',
166
+ decision_chain: '',
167
+ post_poc_decision: '',
168
+ competitor: '',
169
+ conclusion: '',
170
+ reviewer: '',
171
+ reviewed_at: '',
172
+ },
173
+ plan: {
174
+ customer_pain: '',
175
+ expected_recognition: '',
176
+ our_edge: '',
177
+ criteria: [],
178
+ scenarios: [],
179
+ risks: [],
180
+ timeline_start: '',
181
+ timeline_end: '',
182
+ gate1_conclusion: '',
183
+ gate2_ready: '',
184
+ },
185
+ progress: blankProgress(0),
186
+ existingProgressCount: 0,
187
+ };
188
+ }
189
+ /**
190
+ * Build the stable draft key.
191
+ *
192
+ * Sorting the ids makes the key independent of selection order, so the same set
193
+ * of projects always resumes the same draft — even if the user regenerates the
194
+ * form later. A blank form gets a constant key so its draft survives too.
195
+ */
196
+ export function draftKeyFor(mode, pocIds) {
197
+ if (mode === 'blank')
198
+ return 'poc-v3-form-draft-blank';
199
+ return `poc-v3-form-draft-${[...pocIds].sort().join('+')}`;
200
+ }
201
+ /** Drop empty strings from a list, so a stored YAML has no blank rows. */
202
+ function compact(values) {
203
+ return values.map((value) => value.trim()).filter((value) => value !== '');
204
+ }
205
+ /**
206
+ * Serialize one project back to the v3 YAML shape.
207
+ *
208
+ * `yaml`'s own stringifier rather than concatenation: a value containing `: `,
209
+ * `#`, quotes or a newline must be quoted correctly, which hand-built strings
210
+ * get wrong (`name: 某某:试点` produced invalid YAML in the reference tool).
211
+ *
212
+ * Empty plan/progress blocks are emitted as empty collections, not omitted: the
213
+ * ledger's parser tolerates absence, but a colleague reopening the file should
214
+ * see the shape they are expected to fill.
215
+ */
216
+ export function projectToYaml(project) {
217
+ const document = {
218
+ poc_id: project.pocId,
219
+ name: project.name,
220
+ org: {
221
+ system: project.system === '' ? null : project.system,
222
+ company: project.company === '' ? null : project.company,
223
+ department: project.department === '' ? null : project.department,
224
+ },
225
+ amount_wan: project.amountWan === '' ? null : Number(project.amountWan),
226
+ poc_type: project.pocType === '' ? null : project.pocType,
227
+ owner: project.owner === '' ? null : project.owner,
228
+ sales: project.sales === '' ? null : project.sales,
229
+ tech_owner: project.techOwner === '' ? null : project.techOwner,
230
+ exec_sponsor: project.execSponsor === '' ? null : project.execSponsor,
231
+ stage: project.stage,
232
+ status: project.status,
233
+ stage_since: project.stageSince === '' ? null : project.stageSince,
234
+ gate0: {
235
+ why_customer: project.gate0.why_customer === '' ? null : project.gate0.why_customer,
236
+ why_us: project.gate0.why_us === '' ? null : project.gate0.why_us,
237
+ decision_chain: project.gate0.decision_chain === '' ? null : project.gate0.decision_chain,
238
+ post_poc_decision: project.gate0.post_poc_decision === '' ? null : project.gate0.post_poc_decision,
239
+ competitor: project.gate0.competitor === '' ? null : project.gate0.competitor,
240
+ review: {
241
+ conclusion: project.gate0.conclusion === '' ? null : project.gate0.conclusion,
242
+ reviewer: project.gate0.reviewer === '' ? null : project.gate0.reviewer,
243
+ reviewed_at: project.gate0.reviewed_at === '' ? null : project.gate0.reviewed_at,
244
+ },
245
+ },
246
+ plan: {
247
+ customer_pain: project.plan.customer_pain === '' ? null : project.plan.customer_pain,
248
+ expected_recognition: project.plan.expected_recognition === '' ? null : project.plan.expected_recognition,
249
+ criteria: project.plan.criteria
250
+ .filter((criterion) => criterion.name.trim() !== '')
251
+ .map((criterion) => ({
252
+ name: criterion.name.trim(),
253
+ metric: criterion.metric.trim() === '' ? null : criterion.metric.trim(),
254
+ baseline: criterion.baseline.trim() === '' ? null : criterion.baseline.trim(),
255
+ target: criterion.target.trim() === '' ? null : criterion.target.trim(),
256
+ })),
257
+ scenarios: compact(project.plan.scenarios),
258
+ our_edge: project.plan.our_edge === '' ? null : project.plan.our_edge,
259
+ timeline: {
260
+ start: project.plan.timeline_start === '' ? null : project.plan.timeline_start,
261
+ end: project.plan.timeline_end === '' ? null : project.plan.timeline_end,
262
+ },
263
+ risks: project.plan.risks
264
+ .filter((risk) => risk.name.trim() !== '')
265
+ .map((risk) => ({
266
+ name: risk.name.trim(),
267
+ level: risk.level === '' ? null : risk.level,
268
+ mitigation: risk.mitigation.trim() === '' ? null : risk.mitigation.trim(),
269
+ })),
270
+ gate1: { conclusion: project.plan.gate1_conclusion === '' ? null : project.plan.gate1_conclusion },
271
+ gate2: { ready: project.plan.gate2_ready === '' ? null : project.plan.gate2_ready },
272
+ },
273
+ progress: progressIsEmpty(project.progress) ? [] : [serializeProgress(project.progress)],
274
+ outcome: {
275
+ achievement: null,
276
+ customer_recognition: null,
277
+ our_proof: null,
278
+ remaining_risks: null,
279
+ conclusion: { proved: null, recognized: null, next_business: null },
280
+ business: { milestone: null, owner: null, deadline: null, status: null },
281
+ overall: null,
282
+ reviewed_at: null,
283
+ },
284
+ };
285
+ return YAML.stringify(document, { lineWidth: 0 });
286
+ }
287
+ /** `true` when the form's progress entry carries no user content. */
288
+ function progressIsEmpty(entry) {
289
+ return (entry.date === '' &&
290
+ entry.type === '' &&
291
+ entry.goal === '' &&
292
+ entry.actual === '' &&
293
+ compact(entry.items).length === 0 &&
294
+ entry.evidence.every((item) => item.title.trim() === ''));
295
+ }
296
+ /** One progress entry in the ledger's own shape. */
297
+ function serializeProgress(entry) {
298
+ return {
299
+ seq: entry.seq,
300
+ date: entry.date,
301
+ type: entry.type === '' ? null : entry.type,
302
+ goal: entry.goal === '' ? null : entry.goal,
303
+ items: compact(entry.items),
304
+ actual: entry.actual === '' ? null : entry.actual,
305
+ completion: entry.completion === '' ? null : entry.completion,
306
+ evidence: entry.evidence
307
+ .filter((item) => item.title.trim() !== '')
308
+ .map((item) => ({
309
+ title: item.title.trim(),
310
+ link: item.link.trim() === '' ? null : item.link.trim(),
311
+ type: item.type === '' ? null : item.type,
312
+ })),
313
+ customer: {
314
+ synced_with: entry.customer.synced_with === '' ? null : entry.customer.synced_with,
315
+ feedback: entry.customer.feedback === '' ? null : entry.customer.feedback,
316
+ recognition: entry.customer.recognition === '' ? null : entry.customer.recognition,
317
+ },
318
+ gate3_1: entry.gate3_1 === '' ? null : entry.gate3_1,
319
+ gate3_2: entry.gate3_2 === '' ? null : entry.gate3_2,
320
+ next: {
321
+ goal: entry.next.goal === '' ? null : entry.next.goal,
322
+ owner: entry.next.owner === '' ? null : entry.next.owner,
323
+ deadline: entry.next.deadline === '' ? null : entry.next.deadline,
324
+ },
325
+ };
326
+ }
327
+ /** Escape a value for embedding inside a `<script>` block. */
328
+ function scriptSafe(json) {
329
+ return json
330
+ .replace(/</g, '\\u003c')
331
+ .replace(/>/g, '\\u003e')
332
+ .replace(/\u2028/g, '\\u2028')
333
+ .replace(/\u2029/g, '\\u2029');
334
+ }
335
+ /** Escape text for HTML content. */
336
+ function escapeHtml(value) {
337
+ return value
338
+ .replace(/&/g, '&amp;')
339
+ .replace(/</g, '&lt;')
340
+ .replace(/>/g, '&gt;')
341
+ .replace(/"/g, '&quot;');
342
+ }
343
+ /** The enums, mirrored from `schemas/enums.yaml`. */
344
+ const ENUMS = {
345
+ pocType: ['SDL', 'ACG', 'AI安全', '保护AI', '虚拟化', '大体量项目'],
346
+ stage: ['G0-立项', 'G1-方案设计', 'G2-方案验证', 'G3-结果验证', 'G4-结果转化', 'closed'],
347
+ status: ['进行中', '暂停', '已关闭', '已取消'],
348
+ g0Conclusion: ['通过', '未通过-退出', '未通过-降级', '待评审'],
349
+ g1Conclusion: ['通过', '补充后进入', '未通过'],
350
+ g2Ready: ['Ready', '有风险', '未Ready'],
351
+ recognition: ['认可', '部分认可', '未认可', '待确认'],
352
+ progressType: ['内部Review', '客户阶段同步', 'Checkpoint'],
353
+ completion: ['0%', '25%', '50%', '75%', '100%'],
354
+ riskLevel: ['high', 'medium', 'low'],
355
+ gate3_1: ['可证明', '待补证据'],
356
+ gate3_2: ['已确认', '待确认'],
357
+ evidenceType: ['文档', '截图', '数据', '邮件', '链接'],
358
+ system: ['人保体系', '国寿体系'],
359
+ };
360
+ /** The G0 prompts: the label and the reason each field exists. */
361
+ const G0_PROMPTS = [
362
+ { key: 'why_customer', label: '客户为什么要测', hint: '客户自己的痛点与压力,不是我们的卖点。' },
363
+ { key: 'why_us', label: '我们为什么测', hint: '对我们的价值:突破点、可复制的样板、后续生意。' },
364
+ { key: 'decision_chain', label: '项目流程 / 决策链', hint: '谁提需求、谁评审、谁签字、按什么流程走。' },
365
+ { key: 'post_poc_decision', label: '测完之后客户会做什么决定', hint: '采购、扩容、试点转正,还是就此结束。' },
366
+ ];
367
+ /**
368
+ * Generate the complete HTML form.
369
+ *
370
+ * The returned string is the whole document: no external stylesheet, script,
371
+ * font or image reference.
372
+ */
373
+ export function buildFormHtml(options) {
374
+ const now = options.now ?? new Date();
375
+ const projects = options.mode === 'blank' ? [blankProject()] : options.projects;
376
+ const payload = {
377
+ mode: options.mode,
378
+ generatedAt: now.toISOString(),
379
+ today: now.toISOString().slice(0, 10),
380
+ projects,
381
+ draftKey: draftKeyFor(options.mode, projects.map((project) => project.pocId).filter((id) => id !== '')),
382
+ enums: ENUMS,
383
+ g0Fields: G0_PROMPTS,
384
+ };
385
+ const data = scriptSafe(JSON.stringify(payload));
386
+ const title = options.mode === 'blank' ? 'POC 新建项目表单 v3' : `POC 信息收集表单 v3(${projects.length} 个项目)`;
387
+ return `<!DOCTYPE html>
388
+ <html lang="zh-CN">
389
+ <head>
390
+ <meta charset="UTF-8">
391
+ <meta name="viewport" content="width=device-width, initial-scale=1">
392
+ <title>${escapeHtml(title)}</title>
393
+ <style>${FORM_CSS}</style>
394
+ </head>
395
+ <body>
396
+ <div class="shell">
397
+ <header class="topbar">
398
+ <div class="topbar-text">
399
+ <h1 class="topbar-title">${escapeHtml(title)}</h1>
400
+ <p class="topbar-sub">按台账 v3 字段收集。填完点「下载 YAML」,把文件发回项目负责人;保存的是真实 YAML,可以直接提交。</p>
401
+ </div>
402
+ <div class="topbar-actions">
403
+ <span class="save-status" id="saveStatus">已就绪</span>
404
+ <button type="button" class="btn" id="clearBtn">清空草稿</button>
405
+ </div>
406
+ </header>
407
+ <div class="notice" id="restoreNotice" hidden>已恢复上次未提交的草稿。</div>
408
+ <div class="notice notice-warn" id="draftNotice" hidden></div>
409
+ <main id="formBody"></main>
410
+ <footer class="footer">
411
+ <div class="footer-info" id="footerInfo">正在初始化…</div>
412
+ <div class="footer-actions">
413
+ <button type="button" class="btn" id="previewBtn">预览 YAML</button>
414
+ <button type="button" class="btn btn-primary" id="downloadBtn">下载 YAML</button>
415
+ </div>
416
+ </footer>
417
+ </div>
418
+ <pre class="yaml-preview" id="yamlPreview" hidden></pre>
419
+ <div class="toast" id="toast" hidden></div>
420
+ <script>
421
+ (function () {
422
+ 'use strict';
423
+ var DATA = ${data};
424
+ ${FORM_SCRIPT}
425
+ })();
426
+ </script>
427
+ </body>
428
+ </html>
429
+ `;
430
+ }
431
+ /** A file name for the generated form. */
432
+ export function formFileName(options) {
433
+ const now = options.now ?? new Date();
434
+ const stamp = now.toISOString().slice(0, 10).replace(/-/g, '');
435
+ if (options.mode === 'blank')
436
+ return `poc-form-v3-new-${stamp}.html`;
437
+ if (options.pocIds.length === 1)
438
+ return `poc-form-v3-${options.pocIds[0]}-${stamp}.html`;
439
+ return `poc-forms-v3-${options.pocIds.length}-${stamp}.html`;
440
+ }
441
+ /** The file name a colleague should save one project's YAML under. */
442
+ export function yamlFileName(project, now = new Date()) {
443
+ const id = project.pocId.trim() === '' ? 'new' : project.pocId.trim();
444
+ const stamp = now.toISOString().slice(0, 10).replace(/-/g, '');
445
+ return `${id}-${stamp}.yaml`;
446
+ }
447
+ /** Re-export the YAML library's parse for the round-trip test. */
448
+ export { YAML };
449
+ /** Styles: one inline sheet, the console's own design tokens. */
450
+ const FORM_CSS = `
451
+ :root{--primary:#2864E8;--text:#192638;--bg:#F5F7FB;--border:#E6EBF2;--green:#218568;--amber:#B77919;--red:#C0392B;--muted:#6B7C93}
452
+ *{box-sizing:border-box;margin:0;padding:0}
453
+ 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}
454
+ .shell{max-width:920px;margin:0 auto}
455
+ .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}
456
+ .topbar-title{font-size:18px;font-weight:600;line-height:1.4}
457
+ .topbar-sub{font-size:12px;color:var(--muted);margin-top:2px}
458
+ .topbar-actions{display:flex;align-items:center;gap:8px;flex:none}
459
+ .save-status{font-size:12px;color:var(--green);white-space:nowrap}
460
+ .notice{background:#E8EFFC;border:1px solid #C9DCFB;border-radius:6px;padding:10px 14px;font-size:13px;margin-bottom:12px}
461
+ .notice-warn{background:#FDF4E3;border-color:#F0E2C8;color:#8A5E12}
462
+ .card{background:#fff;border-radius:8px;border:1px solid var(--border);padding:20px 24px;margin-bottom:14px}
463
+ .card-title{font-size:15px;font-weight:600;margin-bottom:4px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
464
+ .card-hint{font-size:12px;color:var(--muted);margin-bottom:14px}
465
+ .field{margin-bottom:16px}
466
+ .field:last-child{margin-bottom:0}
467
+ .field-label{display:block;font-weight:500;margin-bottom:5px;font-size:13px}
468
+ .field-label .req{color:var(--red);margin-left:2px}
469
+ .field-help{font-size:12px;color:var(--muted);margin-bottom:5px}
470
+ .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)}
471
+ .input:focus,.textarea:focus,.select:focus{outline:none;border-color:var(--primary)}
472
+ .textarea{min-height:66px;resize:vertical}
473
+ .field-error{color:var(--red);font-size:12px;margin-top:4px;display:none}
474
+ .field.has-error .input,.field.has-error .textarea,.field.has-error .select{border-color:var(--red)}
475
+ .field.has-error .field-error{display:block}
476
+ .grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 14px}
477
+ @media(max-width:640px){.grid-2{grid-template-columns:minmax(0,1fr)}}
478
+ .list-item{display:flex;gap:8px;margin-bottom:8px;align-items:flex-start}
479
+ .list-item .input{flex:1}
480
+ .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)}
481
+ .btn:hover{background:#F8F9FB}
482
+ .btn-primary{background:var(--primary);color:#fff;border-color:var(--primary)}
483
+ .btn-primary:hover{background:#1E54C9}
484
+ .btn-sm{padding:4px 10px;font-size:12px}
485
+ .btn-remove{color:var(--red);border-color:#F0D0CB}
486
+ .badge{display:inline-block;padding:1px 8px;border-radius:4px;font-size:11px;font-weight:500}
487
+ .badge-ok{background:#E6F4EE;color:var(--green)}
488
+ .badge-warn{background:#FDF4E3;color:var(--amber)}
489
+ .badge-error{background:#FBEAE8;color:var(--red)}
490
+ .badge-info{background:#E8EFFC;color:var(--primary)}
491
+ .gaps{background:#FDF8F0;border:1px solid #F0E2C8;border-radius:6px;padding:10px 14px;margin-bottom:14px}
492
+ .gap-item{font-size:13px;padding:3px 0;display:flex;gap:8px}
493
+ .gap-high{color:var(--red)}
494
+ .gap-medium{color:var(--amber)}
495
+ .g0-summary{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:14px}
496
+ .g0-chip{font-size:12px;padding:3px 10px;border-radius:12px;border:1px solid var(--border);background:#F7F9FC}
497
+ .g0-chip[data-present="true"]{background:#E6F4EE;border-color:#BFE3D3;color:var(--green)}
498
+ .g0-chip[data-present="false"]{background:#FBEAE8;border-color:#F0D0CB;color:var(--red)}
499
+ .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)}
500
+ .footer-info{font-size:13px;color:var(--muted)}
501
+ .footer-actions{display:flex;gap:8px;flex-wrap:wrap}
502
+ .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}
503
+ .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}
504
+ @media print{.topbar,.footer,.topbar-actions{position:static}}
505
+ `;
506
+ /**
507
+ * The generated page script.
508
+ *
509
+ * Plain ES5 (no arrow functions, no template literals, no `const`): the file has
510
+ * to run from `file://` in any browser a colleague happens to have. It also
511
+ * keeps the generator's own template escaping simple.
512
+ *
513
+ * It renders a form from `DATA`, keeps a draft in localStorage, validates the
514
+ * counts the gap rules enforce, and downloads real YAML — one file per project.
515
+ */
516
+ const FORM_SCRIPT = `
517
+ var state = { active: 0 };
518
+ var saveTimer = null;
519
+ var storageAvailable = true;
520
+
521
+ function text(value) {
522
+ if (value === null || value === undefined) return '';
523
+ return String(value);
524
+ }
525
+
526
+ function byId(id) { return document.getElementById(id); }
527
+
528
+ function escapeHtml(value) {
529
+ return text(value).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
530
+ }
531
+
532
+ function showToast(message) {
533
+ var toast = byId('toast');
534
+ if (!toast) return;
535
+ toast.textContent = message;
536
+ toast.hidden = false;
537
+ clearTimeout(showToast.timer);
538
+ showToast.timer = setTimeout(function () { toast.hidden = true; }, 2200);
539
+ }
540
+
541
+ function probeStorage() {
542
+ try {
543
+ var probe = '__poc_v3_probe__';
544
+ window.localStorage.setItem(probe, '1');
545
+ window.localStorage.removeItem(probe);
546
+ return true;
547
+ } catch (error) {
548
+ return false;
549
+ }
550
+ }
551
+
552
+ function storageKey() { return DATA.draftKey; }
553
+
554
+ function loadDraft() {
555
+ if (!storageAvailable) return null;
556
+ try {
557
+ var raw = window.localStorage.getItem(storageKey());
558
+ if (!raw) return null;
559
+ var parsed = JSON.parse(raw);
560
+ if (!parsed || !parsed.projects || !parsed.projects.length) return null;
561
+ return parsed.projects;
562
+ } catch (error) {
563
+ return null;
564
+ }
565
+ }
566
+
567
+ function save(quiet) {
568
+ if (!storageAvailable) {
569
+ markSave('草稿无法保存(浏览器禁用了本地存储)');
570
+ return;
571
+ }
572
+ try {
573
+ window.localStorage.setItem(storageKey(), JSON.stringify({ projects: DATA.projects, savedAt: new Date().toISOString() }));
574
+ markSave('已自动保存');
575
+ } catch (error) {
576
+ markSave('草稿保存失败:可能空间不足');
577
+ }
578
+ }
579
+
580
+ function markSave(message) {
581
+ var node = byId('saveStatus');
582
+ if (node) node.textContent = message;
583
+ }
584
+
585
+ function scheduleSave() {
586
+ clearTimeout(saveTimer);
587
+ saveTimer = setTimeout(function () { save(false); }, 600);
588
+ }
589
+
590
+ function clearDraft() {
591
+ if (storageAvailable) {
592
+ try { window.localStorage.removeItem(storageKey()); } catch (error) {}
593
+ }
594
+ DATA.projects = DATA.mode === 'blank' ? [blankProject()] : DATA.projects;
595
+ location.reload();
596
+ }
597
+
598
+ function blankProject() {
599
+ return ${JSON.stringify(blankProjectPayload())};
600
+ }
601
+
602
+ function current() { return DATA.projects[state.active]; }
603
+
604
+ function setPath(target, path, value) {
605
+ var parts = path.split('.');
606
+ var node = target;
607
+ for (var i = 0; i < parts.length - 1; i += 1) {
608
+ var key = parts[i];
609
+ if (key === '') continue;
610
+ if (/^\\d+$/.test(key)) key = Number(key);
611
+ if (node[key] === null || node[key] === undefined) node[key] = {};
612
+ node = node[key];
613
+ }
614
+ node[parts[parts.length - 1]] = value;
615
+ }
616
+
617
+ function field(label, path, value, options) {
618
+ var opts = options || {};
619
+ var help = opts.help ? '<p class="field-help">' + escapeHtml(opts.help) + '</p>' : '';
620
+ var req = opts.required ? '<span class="req">*</span>' : '';
621
+ var input;
622
+ if (opts.multiline) {
623
+ input = '<textarea class="textarea" data-path="' + escapeHtml(path) + '">' + escapeHtml(value) + '</textarea>';
624
+ } else if (opts.enum) {
625
+ input = '<select class="select" data-path="' + escapeHtml(path) + '">';
626
+ input += '<option value="">— 未填 —</option>';
627
+ for (var i = 0; i < opts.enum.length; i += 1) {
628
+ var option = opts.enum[i];
629
+ input += '<option value="' + escapeHtml(option) + '"' + (option === value ? ' selected' : '') + '>' + escapeHtml(option) + '</option>';
630
+ }
631
+ input += '</select>';
632
+ } else {
633
+ input = '<input class="input" type="' + (opts.date ? 'date' : opts.number ? 'number' : 'text') + '" data-path="' + escapeHtml(path) + '" value="' + escapeHtml(value) + '">';
634
+ }
635
+ return '<div class="field" data-field="' + escapeHtml(path) + '">' +
636
+ '<label class="field-label">' + escapeHtml(label) + req + '</label>' + help + input + '</div>';
637
+ }
638
+
639
+ function g0Card(project) {
640
+ var chips = '';
641
+ for (var i = 0; i < DATA.g0Fields.length; i += 1) {
642
+ var def = DATA.g0Fields[i];
643
+ var present = text(project.gate0[def.key]).trim() !== '';
644
+ chips += '<span class="g0-chip" data-present="' + (present ? 'true' : 'false') + '">' +
645
+ (present ? '✓ ' : '✗ ') + escapeHtml(def.label) + '</span>';
646
+ }
647
+ var body = '';
648
+ for (var j = 0; j < DATA.g0Fields.length; j += 1) {
649
+ var field0 = DATA.g0Fields[j];
650
+ body += field(field0.label, 'gate0.' + field0.key, project.gate0[field0.key], { multiline: true, help: field0.hint, required: true });
651
+ }
652
+ body += '<div class="grid-2">' +
653
+ field('主要竞争对手', 'gate0.competitor', project.gate0.competitor, {}) +
654
+ field('G0 评审结论', 'gate0.conclusion', project.gate0.conclusion, { enum: DATA.enums.g0Conclusion }) +
655
+ field('G0 评审人', 'gate0.reviewer', project.gate0.reviewer, {}) +
656
+ field('评审日期', 'gate0.reviewed_at', project.gate0.reviewed_at, { date: true }) +
657
+ '</div>';
658
+ return '<section class="card"><h2 class="card-title">G0 · 值不值得做<span class="badge badge-info">五必填</span></h2>' +
659
+ '<p class="card-hint">四项在 G0 区,第五项是身份区的「客户技术责任人」。这五项齐了,评审才有意义。</p>' +
660
+ '<div class="g0-summary">' + chips + '</div>' + body + '</section>';
661
+ }
662
+
663
+ function criteriaList(project) {
664
+ var rows = '';
665
+ for (var i = 0; i < project.plan.criteria.length; i += 1) {
666
+ var criterion = project.plan.criteria[i];
667
+ rows += '<div class="list-item">' +
668
+ '<input class="input" data-path="plan.criteria.' + i + '.name" value="' + escapeHtml(criterion.name) + '" placeholder="指标名称,如「200 人并发稳定 7 天」">' +
669
+ '<input class="input" data-path="plan.criteria.' + i + '.metric" value="' + escapeHtml(criterion.metric) + '" placeholder="度量,如「成功率」">' +
670
+ '<input class="input" data-path="plan.criteria.' + i + '.baseline" value="' + escapeHtml(criterion.baseline) + '" placeholder="基线">' +
671
+ '<input class="input" data-path="plan.criteria.' + i + '.target" value="' + escapeHtml(criterion.target) + '" placeholder="目标,如 ≥99.5%">' +
672
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="criteria" data-index="' + i + '">删</button>' +
673
+ '</div>';
674
+ }
675
+ return rows + '<button type="button" class="btn btn-sm" data-add="criteria">+ 加一条指标</button>';
676
+ }
677
+
678
+ function scenarioList(project) {
679
+ var rows = '';
680
+ for (var i = 0; i < project.plan.scenarios.length; i += 1) {
681
+ rows += '<div class="list-item">' +
682
+ '<input class="input" data-path="plan.scenarios.' + i + '" value="' + escapeHtml(project.plan.scenarios[i]) + '" placeholder="测试场景">' +
683
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="scenarios" data-index="' + i + '">删</button>' +
684
+ '</div>';
685
+ }
686
+ return rows + '<button type="button" class="btn btn-sm" data-add="scenarios">+ 加一个场景</button>';
687
+ }
688
+
689
+ function riskList(project) {
690
+ var rows = '';
691
+ for (var i = 0; i < project.plan.risks.length; i += 1) {
692
+ var risk = project.plan.risks[i];
693
+ var select = '<select class="select" data-path="plan.risks.' + i + '.level">';
694
+ select += '<option value="">— 未评级 —</option>';
695
+ for (var j = 0; j < DATA.enums.riskLevel.length; j += 1) {
696
+ var level = DATA.enums.riskLevel[j];
697
+ select += '<option value="' + level + '"' + (level === risk.level ? ' selected' : '') + '>' + level + '</option>';
698
+ }
699
+ select += '</select>';
700
+ rows += '<div class="list-item">' +
701
+ '<input class="input" data-path="plan.risks.' + i + '.name" value="' + escapeHtml(risk.name) + '" placeholder="风险">' +
702
+ select +
703
+ '<input class="input" data-path="plan.risks.' + i + '.mitigation" value="' + escapeHtml(risk.mitigation) + '" placeholder="应对">' +
704
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="risks" data-index="' + i + '">删</button>' +
705
+ '</div>';
706
+ }
707
+ return rows + '<button type="button" class="btn btn-sm" data-add="risks">+ 加一条风险</button>';
708
+ }
709
+
710
+ function planCard(project) {
711
+ var criteria = project.plan.criteria.length;
712
+ var scenarios = project.plan.scenarios.length;
713
+ var risks = project.plan.risks.length;
714
+ var criteriaBadge = criteria === 0 ? '<span class="badge badge-warn">还没有指标</span>'
715
+ : (criteria >= 2 && criteria <= 3 ? '<span class="badge badge-ok">' + criteria + ' 条,符合 2–3</span>'
716
+ : '<span class="badge badge-error">' + criteria + ' 条,要求 2–3</span>');
717
+ var scenarioBadge = scenarios === 0 ? '<span class="badge badge-warn">还没有场景</span>'
718
+ : (scenarios >= 3 && scenarios <= 5 ? '<span class="badge badge-ok">' + scenarios + ' 个,符合 3–5</span>'
719
+ : '<span class="badge badge-error">' + scenarios + ' 个,要求 3–5</span>');
720
+ var riskBadge = risks === 0 ? '<span class="badge badge-warn">还没有风险</span>'
721
+ : (risks <= 3 ? '<span class="badge badge-ok">' + risks + ' 条,≤3</span>'
722
+ : '<span class="badge badge-error">' + risks + ' 条,超过 3</span>');
723
+ return '<section class="card"><h2 class="card-title">计划 · 怎么赢<span class="badge badge-info">G1 / G2</span></h2>' +
724
+ '<p class="card-hint">指标和场景都有数量要求:指标 2–3 条、场景 3–5 个、风险不超过 3 条。数量不对会在缺口清单里被点名。</p>' +
725
+ field('客户核心痛点', 'plan.customer_pain', project.plan.customer_pain, { multiline: true }) +
726
+ field('期望客户认可什么', 'plan.expected_recognition', project.plan.expected_recognition, { multiline: true }) +
727
+ field('我方优势 / 赢点', 'plan.our_edge', project.plan.our_edge, { multiline: true }) +
728
+ '<div class="field"><label class="field-label">关键成功指标 ' + criteriaBadge + '</label>' + criteriaList(project) + '</div>' +
729
+ '<div class="field"><label class="field-label">关键测试场景 ' + scenarioBadge + '</label>' + scenarioList(project) + '</div>' +
730
+ '<div class="field"><label class="field-label">最大风险 ' + riskBadge + '</label>' + riskList(project) + '</div>' +
731
+ '<div class="grid-2">' +
732
+ field('计划开始', 'plan.timeline_start', project.plan.timeline_start, { date: true }) +
733
+ field('计划结束', 'plan.timeline_end', project.plan.timeline_end, { date: true }) +
734
+ field('G1 结论', 'plan.gate1_conclusion', project.plan.gate1_conclusion, { enum: DATA.enums.g1Conclusion }) +
735
+ field('G2 Ready 状态', 'plan.gate2_ready', project.plan.gate2_ready, { enum: DATA.enums.g2Ready }) +
736
+ '</div></section>';
737
+ }
738
+
739
+ function progressCard(project) {
740
+ var entry = project.progress;
741
+ var evidenceRows = '';
742
+ for (var i = 0; i < entry.evidence.length; i += 1) {
743
+ evidenceRows += '<div class="list-item">' +
744
+ '<input class="input" data-path="progress.evidence.' + i + '.title" value="' + escapeHtml(entry.evidence[i].title) + '" placeholder="证据名称,如「压测报告」">' +
745
+ '<input class="input" data-path="progress.evidence.' + i + '.link" value="' + escapeHtml(entry.evidence[i].link) + '" placeholder="链接(可空)">' +
746
+ '<button type="button" class="btn btn-sm btn-remove" data-remove="evidence" data-index="' + i + '">删</button>' +
747
+ '</div>';
748
+ }
749
+ var head = '<section class="card"><h2 class="card-title">进展 · 这一次做了什么' +
750
+ (project.existingProgressCount > 0 ? '<span class="badge badge-info">已有 ' + project.existingProgressCount + ' 条</span>' : '<span class="badge badge-warn">第一条进展</span>') +
751
+ '</h2><p class="card-hint">进展是追加式的:这里填的是一条新记录,不会覆盖已有历史。日期、实际结果和下一步是必填项。</p>';
752
+ var body = '<div class="grid-2">' +
753
+ field('日期', 'progress.date', entry.date, { date: true, required: true }) +
754
+ field('类型', 'progress.type', entry.type, { enum: DATA.enums.progressType, required: true }) +
755
+ field('目标', 'progress.goal', entry.goal, {}) +
756
+ field('完成度', 'progress.completion', entry.completion, { enum: DATA.enums.completion }) +
757
+ '</div>' +
758
+ field('实际结果', 'progress.actual', entry.actual, { multiline: true, required: true, help: '做了什么、结果如何。没有证据的结果会被缺口规则点名。' }) +
759
+ '<div class="field"><label class="field-label">证据(没有证据的结果会被点名)</label>' + evidenceRows +
760
+ '<button type="button" class="btn btn-sm" data-add="evidence">+ 加一条证据</button></div>' +
761
+ '<div class="grid-2">' +
762
+ field('同步对象', 'progress.customer.synced_with', entry.customer.synced_with, {}) +
763
+ field('客户认可度', 'progress.customer.recognition', entry.customer.recognition, { enum: DATA.enums.recognition }) +
764
+ field('G3-1', 'progress.gate3_1', entry.gate3_1, { enum: DATA.enums.gate3_1 }) +
765
+ field('G3-2', 'progress.gate3_2', entry.gate3_2, { enum: DATA.enums.gate3_2 }) +
766
+ '</div>' +
767
+ field('客户反馈', 'progress.customer.feedback', entry.customer.feedback, { multiline: true }) +
768
+ '<div class="grid-2">' +
769
+ field('下一步目标', 'progress.next.goal', entry.next.goal, { multiline: true, required: true }) +
770
+ field('下一步负责人', 'progress.next.owner', entry.next.owner, {}) +
771
+ field('下一步截止', 'progress.next.deadline', entry.next.deadline, { date: true }) +
772
+ '</div></section>';
773
+ return head + body;
774
+ }
775
+
776
+ function identityCard(project) {
777
+ return '<section class="card"><h2 class="card-title">身份</h2>' +
778
+ '<p class="card-hint">立项时确定,之后很少变。客户技术责任人算 G0 五必填之一。</p>' +
779
+ '<div class="grid-2">' +
780
+ field('项目编号', 'pocId', project.pocId, { required: DATA.mode === 'blank', help: DATA.mode === 'blank' ? '新建时必填,格式 POC-XXX。' : '' }) +
781
+ field('项目名称', 'name', project.name, { required: true }) +
782
+ field('体系', 'system', project.system, { enum: DATA.enums.system }) +
783
+ field('客户公司', 'company', project.company, {}) +
784
+ field('部门', 'department', project.department, {}) +
785
+ field('预计金额(万元)', 'amountWan', project.amountWan, { number: true }) +
786
+ field('项目类型', 'pocType', project.pocType, { enum: DATA.enums.pocType }) +
787
+ field('阶段', 'stage', project.stage, { enum: DATA.enums.stage }) +
788
+ field('状态', 'status', project.status, { enum: DATA.enums.status }) +
789
+ field('进入阶段日期', 'stageSince', project.stageSince, { date: true, help: '不填就算不出停滞天数。' }) +
790
+ field('负责人(我方)', 'owner', project.owner, { required: true }) +
791
+ field('销售', 'sales', project.sales, {}) +
792
+ field('客户技术责任人', 'techOwner', project.techOwner, { required: true, help: 'G0 五必填之一。' }) +
793
+ field('客户业务决策人', 'execSponsor', project.execSponsor, {}) +
794
+ '</div></section>';
795
+ }
796
+
797
+ function render() {
798
+ var project = current();
799
+ var switcher = '';
800
+ if (DATA.projects.length > 1) {
801
+ switcher = '<div class="notice">当前编辑:第 ' + (state.active + 1) + ' / ' + DATA.projects.length + ' 个项目' +
802
+ ' <select class="select" id="projectSwitch" style="width:auto;display:inline-block;margin-left:8px">';
803
+ for (var i = 0; i < DATA.projects.length; i += 1) {
804
+ switcher += '<option value="' + i + '"' + (i === state.active ? ' selected' : '') + '>' +
805
+ escapeHtml(DATA.projects[i].name || DATA.projects[i].pocId || '未命名') + '</option>';
806
+ }
807
+ switcher += '</select></div>';
808
+ }
809
+ byId('formBody').innerHTML = switcher + identityCard(project) + g0Card(project) + planCard(project) + progressCard(project);
810
+ var switchNode = byId('projectSwitch');
811
+ if (switchNode) {
812
+ switchNode.addEventListener('change', function (event) {
813
+ state.active = Number(event.target.value);
814
+ render();
815
+ });
816
+ }
817
+ var info = byId('footerInfo');
818
+ if (info) {
819
+ info.textContent = '共 ' + DATA.projects.length + ' 个项目 · 草稿自动保存在本机浏览器';
820
+ }
821
+ }
822
+
823
+ function setPathOn(project, path, value) {
824
+ // "progress.*" paths address the pending entry; everything else addresses
825
+ // the project itself. Keeping the two apart is what stops a progress edit
826
+ // from overwriting a plan field with a same-named key.
827
+ if (path.indexOf('progress.') === 0) {
828
+ setPath({ progress: project.progress }, path, value);
829
+ return;
830
+ }
831
+ setPath(project, path, value);
832
+ }
833
+
834
+ function bind() {
835
+ document.addEventListener('input', function (event) {
836
+ var target = event.target;
837
+ if (!target || !target.getAttribute) return;
838
+ var path = target.getAttribute('data-path');
839
+ if (!path) return;
840
+ setPathOn(current(), path, target.value);
841
+ scheduleSave();
842
+ });
843
+ document.addEventListener('change', function (event) {
844
+ var target = event.target;
845
+ if (!target || !target.getAttribute) return;
846
+ var path = target.getAttribute('data-path');
847
+ if (!path) return;
848
+ setPathOn(current(), path, target.value);
849
+ scheduleSave();
850
+ if (target.tagName === 'SELECT') render();
851
+ });
852
+ document.addEventListener('click', function (event) {
853
+ var target = event.target;
854
+ if (!target || !target.getAttribute) return;
855
+ var project = current();
856
+ var addKey = target.getAttribute('data-add');
857
+ var removeKey = target.getAttribute('data-remove');
858
+ if (addKey) {
859
+ if (addKey === 'criteria') project.plan.criteria.push({ name: '', metric: '', baseline: '', target: '' });
860
+ if (addKey === 'scenarios') project.plan.scenarios.push('');
861
+ if (addKey === 'risks') project.plan.risks.push({ name: '', level: '', mitigation: '' });
862
+ if (addKey === 'evidence') project.progress.evidence.push({ title: '', link: '', type: '' });
863
+ scheduleSave();
864
+ render();
865
+ return;
866
+ }
867
+ if (removeKey) {
868
+ var index = Number(target.getAttribute('data-index'));
869
+ if (removeKey === 'criteria') project.plan.criteria.splice(index, 1);
870
+ if (removeKey === 'scenarios') project.plan.scenarios.splice(index, 1);
871
+ if (removeKey === 'risks') project.plan.risks.splice(index, 1);
872
+ if (removeKey === 'evidence') project.progress.evidence.splice(index, 1);
873
+ scheduleSave();
874
+ render();
875
+ }
876
+ });
877
+ }
878
+
879
+ /**
880
+ * Serialize one project to the v3 YAML shape.
881
+ *
882
+ * This mirrors the Host's own projectToYaml on purpose: the browser cannot call
883
+ * it, and the file a colleague downloads has to be byte-compatible with what
884
+ * the plugin's own generator would emit. The tests pin both sides to the same
885
+ * output, so a drift shows up as a failure rather than as an unreadable file.
886
+ */
887
+ function toYaml(project) {
888
+ var lines = [];
889
+ function scalar(value) {
890
+ if (value === null || value === undefined || value === '') return 'null';
891
+ var raw = String(value);
892
+ if (/[:#\\n"']/.test(raw) || raw !== raw.trim()) return JSON.stringify(raw);
893
+ return raw;
894
+ }
895
+ function push(key, value, indent) {
896
+ var pad = new Array(indent + 1).join(' ');
897
+ lines.push(pad + key + ': ' + scalar(value));
898
+ }
899
+ push('poc_id', project.pocId, 0);
900
+ push('name', project.name, 0);
901
+ lines.push('org:');
902
+ push('system', project.system, 2);
903
+ push('company', project.company, 2);
904
+ push('department', project.department, 2);
905
+ push('amount_wan', project.amountWan === '' ? '' : Number(project.amountWan), 0);
906
+ push('poc_type', project.pocType, 0);
907
+ push('owner', project.owner, 0);
908
+ push('sales', project.sales, 0);
909
+ push('tech_owner', project.techOwner, 0);
910
+ push('exec_sponsor', project.execSponsor, 0);
911
+ push('stage', project.stage, 0);
912
+ push('status', project.status, 0);
913
+ push('stage_since', project.stageSince, 0);
914
+ lines.push('gate0:');
915
+ push('why_customer', project.gate0.why_customer, 2);
916
+ push('why_us', project.gate0.why_us, 2);
917
+ push('decision_chain', project.gate0.decision_chain, 2);
918
+ push('post_poc_decision', project.gate0.post_poc_decision, 2);
919
+ push('competitor', project.gate0.competitor, 2);
920
+ lines.push(' review:');
921
+ push('conclusion', project.gate0.conclusion, 4);
922
+ push('reviewer', project.gate0.reviewer, 4);
923
+ push('reviewed_at', project.gate0.reviewed_at, 4);
924
+ lines.push('plan:');
925
+ push('customer_pain', project.plan.customer_pain, 2);
926
+ push('expected_recognition', project.plan.expected_recognition, 2);
927
+ push('our_edge', project.plan.our_edge, 2);
928
+ lines.push(' timeline:');
929
+ push('start', project.plan.timeline_start, 4);
930
+ push('end', project.plan.timeline_end, 4);
931
+ lines.push(' gate1:');
932
+ push('conclusion', project.plan.gate1_conclusion, 4);
933
+ lines.push(' gate2:');
934
+ push('ready', project.plan.gate2_ready, 4);
935
+ var i;
936
+ lines.push(' criteria:');
937
+ var criteria = project.plan.criteria.filter(function (item) { return text(item.name).trim() !== ''; });
938
+ if (criteria.length === 0) { lines[lines.length - 1] = ' criteria: []'; }
939
+ for (i = 0; i < criteria.length; i += 1) {
940
+ lines.push(' - name: ' + scalar(criteria[i].name));
941
+ lines.push(' metric: ' + scalar(criteria[i].metric));
942
+ lines.push(' baseline: ' + scalar(criteria[i].baseline));
943
+ lines.push(' target: ' + scalar(criteria[i].target));
944
+ }
945
+ var scenarios = project.plan.scenarios.filter(function (item) { return text(item).trim() !== ''; });
946
+ lines.push(' scenarios:' + (scenarios.length === 0 ? ' []' : ''));
947
+ for (i = 0; i < scenarios.length; i += 1) lines.push(' - ' + scalar(scenarios[i]));
948
+ var risks = project.plan.risks.filter(function (item) { return text(item.name).trim() !== ''; });
949
+ lines.push(' risks:' + (risks.length === 0 ? ' []' : ''));
950
+ for (i = 0; i < risks.length; i += 1) {
951
+ lines.push(' - name: ' + scalar(risks[i].name));
952
+ lines.push(' level: ' + scalar(risks[i].level));
953
+ lines.push(' mitigation: ' + scalar(risks[i].mitigation));
954
+ }
955
+ var entry = project.progress;
956
+ var hasEntry = text(entry.date) !== '' || text(entry.actual) !== '' || text(entry.goal) !== '';
957
+ lines.push('progress:' + (hasEntry ? '' : ' []'));
958
+ if (hasEntry) {
959
+ lines.push(' - seq: ' + (entry.seq === null ? 'null' : entry.seq));
960
+ lines.push(' date: ' + scalar(entry.date));
961
+ lines.push(' type: ' + scalar(entry.type));
962
+ lines.push(' goal: ' + scalar(entry.goal));
963
+ var items = entry.items.filter(function (item) { return text(item).trim() !== ''; });
964
+ lines.push(' items:' + (items.length === 0 ? ' []' : ''));
965
+ for (i = 0; i < items.length; i += 1) lines.push(' - ' + scalar(items[i]));
966
+ lines.push(' actual: ' + scalar(entry.actual));
967
+ lines.push(' completion: ' + scalar(entry.completion));
968
+ var evidence = entry.evidence.filter(function (item) { return text(item.title).trim() !== ''; });
969
+ lines.push(' evidence:' + (evidence.length === 0 ? ' []' : ''));
970
+ for (i = 0; i < evidence.length; i += 1) {
971
+ lines.push(' - title: ' + scalar(evidence[i].title));
972
+ lines.push(' link: ' + scalar(evidence[i].link));
973
+ lines.push(' type: ' + scalar(evidence[i].type));
974
+ }
975
+ lines.push(' customer:');
976
+ lines.push(' synced_with: ' + scalar(entry.customer.synced_with));
977
+ lines.push(' feedback: ' + scalar(entry.customer.feedback));
978
+ lines.push(' recognition: ' + scalar(entry.customer.recognition));
979
+ lines.push(' gate3_1: ' + scalar(entry.gate3_1));
980
+ lines.push(' gate3_2: ' + scalar(entry.gate3_2));
981
+ lines.push(' next:');
982
+ lines.push(' goal: ' + scalar(entry.next.goal));
983
+ lines.push(' owner: ' + scalar(entry.next.owner));
984
+ lines.push(' deadline: ' + scalar(entry.next.deadline));
985
+ }
986
+ return lines.join('\\n') + '\\n';
987
+ }
988
+
989
+ function previewYaml() {
990
+ var node = byId('yamlPreview');
991
+ if (!node) return;
992
+ var all = [];
993
+ for (var i = 0; i < DATA.projects.length; i += 1) {
994
+ all.push('# ' + (DATA.projects[i].pocId || '新项目'));
995
+ all.push(toYaml(DATA.projects[i]));
996
+ }
997
+ node.textContent = all.join('\\n');
998
+ node.hidden = false;
999
+ node.scrollIntoView({ behavior: 'smooth', block: 'start' });
1000
+ }
1001
+
1002
+ function downloadYaml() {
1003
+ if (!validateRequired()) {
1004
+ showToast('还有必填项没填');
1005
+ return;
1006
+ }
1007
+ var stamp = DATA.today.replace(/-/g, '');
1008
+ for (var i = 0; i < DATA.projects.length; i += 1) {
1009
+ var project = DATA.projects[i];
1010
+ var blob = new Blob([toYaml(project)], { type: 'text/yaml;charset=utf-8' });
1011
+ var url = URL.createObjectURL(blob);
1012
+ var anchor = document.createElement('a');
1013
+ anchor.href = url;
1014
+ anchor.download = (project.pocId.trim() === '' ? 'new' : project.pocId.trim()) + '-' + stamp + '.yaml';
1015
+ document.body.appendChild(anchor);
1016
+ anchor.click();
1017
+ document.body.removeChild(anchor);
1018
+ setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
1019
+ }
1020
+ showToast('已下载 ' + DATA.projects.length + ' 个 YAML 文件');
1021
+ save(true);
1022
+ }
1023
+
1024
+ /** The three bare-minimum required fields, checked before a download. */
1025
+ function validateRequired() {
1026
+ var ok = true;
1027
+ var project = current();
1028
+ var required = [
1029
+ ['name', project.name],
1030
+ ['owner', project.owner],
1031
+ ['techOwner', project.techOwner],
1032
+ ['progress.date', project.progress.date],
1033
+ ['progress.actual', project.progress.actual],
1034
+ ['progress.next.goal', project.progress.next.goal]
1035
+ ];
1036
+ for (var i = 0; i < required.length; i += 1) {
1037
+ var key = required[i][0];
1038
+ var value = text(required[i][1]).trim();
1039
+ var node = document.querySelector('[data-field="' + key + '"]');
1040
+ if (node) node.className = value === '' ? 'field has-error' : 'field';
1041
+ if (value === '') ok = false;
1042
+ }
1043
+ return ok;
1044
+ }
1045
+
1046
+ function initState() {
1047
+ storageAvailable = probeStorage();
1048
+ if (!storageAvailable) {
1049
+ var notice = byId('draftNotice');
1050
+ if (notice) {
1051
+ notice.textContent = '这个浏览器禁用了本地存储,草稿不会自动保存,请填完立即下载。';
1052
+ notice.hidden = false;
1053
+ }
1054
+ }
1055
+ var draft = loadDraft();
1056
+ if (draft) {
1057
+ DATA.projects = draft;
1058
+ var restore = byId('restoreNotice');
1059
+ if (restore) restore.hidden = false;
1060
+ }
1061
+ }
1062
+
1063
+ initState();
1064
+ bind();
1065
+ render();
1066
+ if (byId('clearBtn')) byId('clearBtn').addEventListener('click', clearDraft);
1067
+ if (byId('previewBtn')) byId('previewBtn').addEventListener('click', previewYaml);
1068
+ if (byId('downloadBtn')) byId('downloadBtn').addEventListener('click', downloadYaml);
1069
+ setInterval(function () { save(true); }, 30000);
1070
+ window.addEventListener('beforeunload', function () { save(true); });
1071
+ `;
1072
+ /** The blank project, as the generated script builds it. */
1073
+ function blankProjectPayload() {
1074
+ return blankProject();
1075
+ }