dsh-total-quality 2.0.55 → 2.0.57

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.
Files changed (197) hide show
  1. package/CONTRIBUTING.md +51 -47
  2. package/LICENSE.md +37 -37
  3. package/README.en.md +32 -30
  4. package/README.md +90 -88
  5. package/agent-host.cjs +277 -277
  6. package/client.js +199 -92
  7. package/cordis.patch.yml +5 -5
  8. package/docs/enterprise-onboarding.md +10 -10
  9. package/docs/technical-reference.md +223 -223
  10. package/host.cjs +91 -124
  11. package/llm-bridge.cjs +234 -234
  12. package/locale/en.json +5 -5
  13. package/locale/zh.json +5 -5
  14. package/package.json +3 -2
  15. package/public/app.css +3 -0
  16. package/public/app.js +6 -2
  17. package/public/index.html +8 -9
  18. package/public/js/api.js +152 -152
  19. package/public/js/assistant-history.js +62 -62
  20. package/public/js/material-library.js +100 -100
  21. package/public/js/mobile-preview.js +119 -0
  22. package/public/js/pages-company-knowledge.js +9 -32
  23. package/public/js/pages-core.js +232 -232
  24. package/public/js/pages-growth.js +148 -148
  25. package/public/js/pages-qms.js +1 -1
  26. package/public/js/pages-qtools.js +410 -410
  27. package/public/js/pages-thanks.js +71 -71
  28. package/public/js/plugin-updates.js +53 -0
  29. package/public/js/quality-workflow.js +205 -205
  30. package/public/js/survey-dates.js +41 -41
  31. package/public/js/survey-knowledge.js +301 -301
  32. package/public/js/tool-wizards.js +621 -621
  33. package/public/js/ui.js +467 -467
  34. package/public/js/voice-capture-worklet.js +30 -30
  35. package/public/js/xiaozhi-voice.js +264 -264
  36. package/public/js/xiaozhi.js +468 -468
  37. package/public/platform-help.html +426 -426
  38. package/public/platform-site/assets/0468a68574112812.css +10703 -10703
  39. package/public/platform-site/assets/159e086d35adfa1c.css +2094 -2094
  40. package/public/platform-site/assets/169e3159cade0d9f.css +98 -98
  41. package/public/platform-site/assets/22b917c4a3d4ae3d.svg +14 -14
  42. package/public/platform-site/assets/476f9254ccf723e7.css +8265 -8265
  43. package/public/platform-site/assets/85a0a4fb4416ded9.css +120 -120
  44. package/public/platform-site/assets/a3b272383226f6d9.svg +135 -135
  45. package/public/platform-site/assets/fd16dc5f3cc9d97e.svg +104 -104
  46. package/public/platform-site/assets/qip-favicon.svg +5 -5
  47. package/public/platform-site/index.html +279 -279
  48. package/public/platform-site/offline.js +261 -261
  49. package/public/platform-site/qip-brand.css +566 -566
  50. package/public/platform-site/qip-module-guides.js +237 -237
  51. package/public/responsive.css +103 -101
  52. package/public/vendor/markdown-it-15.0.3.LICENSE +22 -22
  53. package/public/vendor/markdown-it-15.0.3.umd.min.js +13 -13
  54. package/public/workbench.css +7 -7
  55. package/public/xiaozhi.css +292 -292
  56. package/resources/qms-templates/019ffb58f24ed48d.docx +0 -0
  57. package/resources/qms-templates/04a69165fc15143a.docx +0 -0
  58. package/resources/qms-templates/09af69358c989a63.docx +0 -0
  59. package/resources/qms-templates/0e7ac77844e45311.docx +0 -0
  60. package/resources/qms-templates/12446a1b5e173c71.docx +0 -0
  61. package/resources/qms-templates/15ae40f67f9a3efc.docx +0 -0
  62. package/resources/qms-templates/18a69bbebf2ece7f.docx +0 -0
  63. package/resources/qms-templates/1978faa989134f02.docx +0 -0
  64. package/resources/qms-templates/1a30e121de752f7b.docx +0 -0
  65. package/resources/qms-templates/1b88907969ea7d4c.docx +0 -0
  66. package/resources/qms-templates/1e92b808722bf90a.docx +0 -0
  67. package/resources/qms-templates/2091cad340dc0e7f.docx +0 -0
  68. package/resources/qms-templates/271ae1002c896ed7.docx +0 -0
  69. package/resources/qms-templates/280ce53e5d3b5fcf.docx +0 -0
  70. package/resources/qms-templates/28ca8e4ede0adf6d.docx +0 -0
  71. package/resources/qms-templates/2ac6675f3cb1f993.docx +0 -0
  72. package/resources/qms-templates/2c3b799389909d8b.docx +0 -0
  73. package/resources/qms-templates/2c51038ba2cc3264.docx +0 -0
  74. package/resources/qms-templates/30c888851d16d764.docx +0 -0
  75. package/resources/qms-templates/3459fc4daaa2743d.docx +0 -0
  76. package/resources/qms-templates/3751dafc335e0e80.docx +0 -0
  77. package/resources/qms-templates/38798cd4298cd2db.docx +0 -0
  78. package/resources/qms-templates/38f551f9d738ab0a.docx +0 -0
  79. package/resources/qms-templates/3c85a23ea17018b4.docx +0 -0
  80. package/resources/qms-templates/3cdb7d14caf1b852.docx +0 -0
  81. package/resources/qms-templates/3f23239bb6b3e1db.docx +0 -0
  82. package/resources/qms-templates/42a5b9efeeaa8007.docx +0 -0
  83. package/resources/qms-templates/47352aafe9b8dac1.docx +0 -0
  84. package/resources/qms-templates/495359b1e3cbb8fe.docx +0 -0
  85. package/resources/qms-templates/4ca6920464785166.docx +0 -0
  86. package/resources/qms-templates/4ce862582a7791be.docx +0 -0
  87. package/resources/qms-templates/54c9a02a10991b9e.docx +0 -0
  88. package/resources/qms-templates/5aeb8fddf5f3693f.docx +0 -0
  89. package/resources/qms-templates/5d7e5576b0e73be7.docx +0 -0
  90. package/resources/qms-templates/5db3a40edac37791.docx +0 -0
  91. package/resources/qms-templates/5ffa21eb78eb6f77.docx +0 -0
  92. package/resources/qms-templates/60d0fbcb709b7161.docx +0 -0
  93. package/resources/qms-templates/63e1d3a166756095.docx +0 -0
  94. package/resources/qms-templates/65c724c080d32f10.docx +0 -0
  95. package/resources/qms-templates/674bd7826c6cbac2.docx +0 -0
  96. package/resources/qms-templates/677e851acca1b879.docx +0 -0
  97. package/resources/qms-templates/6bf15feb1a0d2a8d.docx +0 -0
  98. package/resources/qms-templates/6c3889c7d0918db9.docx +0 -0
  99. package/resources/qms-templates/6c4c349eeb0a96a8.docx +0 -0
  100. package/resources/qms-templates/6c5befbd33f759c1.docx +0 -0
  101. package/resources/qms-templates/6df8367901347508.docx +0 -0
  102. package/resources/qms-templates/71db51997037692b.docx +0 -0
  103. package/resources/qms-templates/78a8ef8c76510c99.docx +0 -0
  104. package/resources/qms-templates/8397bfd1c0a1b013.docx +0 -0
  105. package/resources/qms-templates/84d750cf858b60a1.docx +0 -0
  106. package/resources/qms-templates/880de58a4b334533.docx +0 -0
  107. package/resources/qms-templates/88c37d1b87d9b78c.docx +0 -0
  108. package/resources/qms-templates/88e9cd42f1849462.docx +0 -0
  109. package/resources/qms-templates/8956597403be35b6.docx +0 -0
  110. package/resources/qms-templates/94675c810a233e1f.docx +0 -0
  111. package/resources/qms-templates/94dff59dd7ebec6e.docx +0 -0
  112. package/resources/qms-templates/9670b9cd02141594.docx +0 -0
  113. package/resources/qms-templates/98c373ebd7b5163d.docx +0 -0
  114. package/resources/qms-templates/a4078cf2378a9388.docx +0 -0
  115. package/resources/qms-templates/a5b110c7ef917139.docx +0 -0
  116. package/resources/qms-templates/aec75820e45774be.docx +0 -0
  117. package/resources/qms-templates/b31c085e281d230c.docx +0 -0
  118. package/resources/qms-templates/b7c1c3c72f8ffeef.docx +0 -0
  119. package/resources/qms-templates/b81b82eaa5c8f422.docx +0 -0
  120. package/resources/qms-templates/b92a2fa31f75f137.docx +0 -0
  121. package/resources/qms-templates/b96c54ae9cfffc54.docx +0 -0
  122. package/resources/qms-templates/bc47cfd626c010e7.docx +0 -0
  123. package/resources/qms-templates/be60792734afca69.docx +0 -0
  124. package/resources/qms-templates/c0018d8ae9ad19e1.docx +0 -0
  125. package/resources/qms-templates/c171027c964c8be3.docx +0 -0
  126. package/resources/qms-templates/c4b93d71f5d98b4b.docx +0 -0
  127. package/resources/qms-templates/c531da29fcb3090f.docx +0 -0
  128. package/resources/qms-templates/c88eddd43358d015.docx +0 -0
  129. package/resources/qms-templates/cb978da542f0d892.docx +0 -0
  130. package/resources/qms-templates/ccde4a94532a8d36.docx +0 -0
  131. package/resources/qms-templates/cf3fb1e20ae6f24d.docx +0 -0
  132. package/resources/qms-templates/d231b4982fc8113e.docx +0 -0
  133. package/resources/qms-templates/d3c55aa5ed14055c.docx +0 -0
  134. package/resources/qms-templates/db45c44a00a13349.docx +0 -0
  135. package/resources/qms-templates/db849a41210f54e0.docx +0 -0
  136. package/resources/qms-templates/dba9ce363d83ddc8.docx +0 -0
  137. package/resources/qms-templates/dca3ea4c95eb2225.docx +0 -0
  138. package/resources/qms-templates/dfa4220d2b6b8131.docx +0 -0
  139. package/resources/qms-templates/dfa51222c777734f.docx +0 -0
  140. package/resources/qms-templates/e07ea511507e14f5.docx +0 -0
  141. package/resources/qms-templates/e0a2e00c03458dfa.docx +0 -0
  142. package/resources/qms-templates/e0e802f46b6764d1.docx +0 -0
  143. package/resources/qms-templates/e53fc85717f2852b.docx +0 -0
  144. package/resources/qms-templates/e9dd82d5e54520e5.docx +0 -0
  145. package/resources/qms-templates/ea7bfc22c06d82a9.docx +0 -0
  146. package/resources/qms-templates/ecf0db9f37294536.docx +0 -0
  147. package/resources/qms-templates/f05fcfc87e82ff39.docx +0 -0
  148. package/resources/qms-templates/fb9e56a17c4a4f97.docx +0 -0
  149. package/resources/qms-templates/manifest.json +932 -0
  150. package/src/data/seed-sme.js +317 -317
  151. package/src/data/seed.js +879 -879
  152. package/src/lib/backup-identity.js +57 -57
  153. package/src/lib/chat-answer.js +225 -225
  154. package/src/lib/chat-context.js +99 -99
  155. package/src/lib/company-library.js +28 -19
  156. package/src/lib/data-import.js +217 -217
  157. package/src/lib/data-sources.js +118 -118
  158. package/src/lib/demo-data.js +27 -1
  159. package/src/lib/employee-intake.js +84 -84
  160. package/src/lib/growth.js +53 -53
  161. package/src/lib/intake-packets.js +119 -119
  162. package/src/lib/issue-intake.js +88 -88
  163. package/src/lib/kb-revision.js +214 -214
  164. package/src/lib/llm.js +279 -279
  165. package/src/lib/model-error.js +14 -14
  166. package/src/lib/privacy.js +26 -26
  167. package/src/lib/qms-drafting.js +194 -194
  168. package/src/lib/qms-jobs.js +11 -7
  169. package/src/lib/qms-manual-review.js +185 -185
  170. package/src/lib/qms-procedure-review.js +109 -109
  171. package/src/lib/qms-templates.js +358 -326
  172. package/src/lib/qms.js +369 -369
  173. package/src/lib/quality-priority.js +100 -100
  174. package/src/lib/quality-state.js +92 -92
  175. package/src/lib/quality-workflow.js +65 -65
  176. package/src/lib/retrieval.js +159 -159
  177. package/src/lib/spc.js +127 -127
  178. package/src/lib/voice-hotwords.txt +22 -22
  179. package/src/lib/voice-text.js +13 -13
  180. package/src/lib/voice-worker.js +72 -72
  181. package/src/lib/voice.js +330 -330
  182. package/src/lib/workbench-notices.js +49 -49
  183. package/src/lib/workbench.js +103 -106
  184. package/src/package.json +3 -3
  185. package/src/tools/analysis.js +306 -306
  186. package/src/tools/data.js +596 -596
  187. package/src/tools/docs.js +430 -430
  188. package/src/tools/registry.js +57 -57
  189. package/tools-dsh.cjs +153 -153
  190. package//345/256/211/350/243/205/350/257/264/346/230/216.md +33 -25
  191. package//346/234/254/346/234/272/347/213/254/347/253/213/345/256/211/350/243/205/350/257/264/346/230/216.md +17 -17
  192. package//350/207/252/346/243/200.cjs +88 -88
  193. package/public/js/remote-knowledge.js +0 -165
  194. package/public/js/workbench-notices.js +0 -67
  195. package/public/remote-knowledge-help.html +0 -35
  196. package/public/remote-knowledge.css +0 -40
  197. package/src/lib/remote-knowledge.js +0 -284
@@ -1,205 +1,205 @@
1
- (function (global) {
2
- 'use strict';
3
- const { UI, API, Pages } = global;
4
- const { act, card, empty, esc, dt, table, modal, closeModal, toast, tag, infoGrid } = UI;
5
- const api='/qip-real-workbench/api';
6
- const wb=api+'/workbench';
7
- const labels={issues:'问题清单',measurements:'测量数据',defects:'质检缺陷'};
8
- const packetStates={queued:'等待识别',waiting_model:'等待模型连接',review:'待人工复核',failed:'识别失败',done:'已核对'};
9
- const statusLabels={pending:'待主管验收',returned:'已退回整改',accepted:'验收通过'};
10
- const sourceStates={complete:'已同步',failed:'连接或同步失败',blocked:'有待校验记录'};
11
- const date=value=>value ? (/^\d{4}-\d{2}-\d{2}$/.test(value)?value:dt(value)) : '—';
12
- const filesFor=(files,manager=false)=>files.map(({id,name})=>'<a class="btn btn-sm" href="'+
13
- (manager?api+'/enterprise-kb/files/':wb+'/files/')+encodeURIComponent(id)+'" download>'+esc(name)+'</a>').join(' ');
14
- const workshops=()=>global.State.bootstrap?.naming?.workshops || [];
15
- let reviewRows=[], sources=[], sourceFields={};
16
- const priority=(row)=>row.priority==='overdue'?tag('已超期','red'):row.priority==='soon'?tag('三天内到期','orange'):'';
17
- function packetLinks(row) {
18
- if (row.state==='done' && !row.results.length) return '<span class="wb-profile-context">未发现可登记异常</span>';
19
- if (row.state==='failed' && row.failure) return esc(row.failure);
20
- return row.results.map(r=>r.issueId ? act(esc(r.title || r.issueId),'issueDetail',{id:r.issueId},'btn btn-sm') :
21
- tag(({linked:'已补入证据',duplicate:'重复记录已跳过',dismissed:'复核完毕',created:'已登记'})[r.state]||r.state,'gray')).join(' ');
22
- }
23
- function packetTable(rows,manager=false) {
24
- return table(['提交时间','原件','进度','处理结果',''],rows.map(row=>[
25
- esc(dt(row.createdAt)),filesFor(row.files,manager),tag(packetStates[row.state] || row.state,row.state==='review'?'orange':'blue'),
26
- packetLinks(row),manager ? act('处理','packetReview',{id:row.id},'btn btn-sm') :
27
- row.state==='failed' ? act('重试识别','packetRetry',{id:row.id},'btn btn-sm') : '',
28
- ]),{empty:manager?'暂无待复核资料':'暂无批量提交资料'});
29
- }
30
-
31
- Pages.intakeReview={
32
- title:'历史资料复核',sub:'处理待复核的历史资料',
33
- async render(){
34
- const packets=await API.get(wb+'/intake-review');
35
- reviewRows=packets.rows;
36
- return card('资料复核',packets.modelAvailable?'':'模型未连接,可手动处理',packetTable(packets.rows,true));
37
- },
38
- };
39
- function caseReviewMarkup(row,manager=false) {
40
- const r=row.review;
41
- const deadline=row.dueAt ? '<p>整改期限 '+esc(date(row.dueAt))+' '+priority(row)+'</p>' : '';
42
- if (!r) return deadline;
43
- const person=r.decidedBy || r.submittedBy;
44
- return deadline+'<section class="wb-flow-summary"><h4><span>'+esc(statusLabels[r.state])+'</span></h4>'+
45
- '<p>'+esc(person?.name || '本机使用者')+' · '+esc(dt(r.decidedAt || r.requestedAt))+'</p>'+
46
- '<p class="wb-history-note">'+esc(r.opinion || r.note)+'</p>'+
47
- (r.evidence?.length ? '<p>验收时提交的附件 '+filesFor(r.evidence,manager)+'</p>' : '')+'</section>'+
48
- (row.reviewHistory?.length ? '<details><summary>往轮验收记录('+row.reviewHistory.length+')</summary>'+
49
- row.reviewHistory.map(previous=>'<div class="wb-flow-summary"><b>'+esc(statusLabels[previous.state])+'</b><p>'+
50
- esc(previous.submittedBy?.name)+' → '+esc(previous.decidedBy?.name || '—')+' · '+esc(dt(previous.decidedAt || previous.requestedAt))+
51
- '</p><p>'+esc(previous.opinion || previous.note)+'</p>'+filesFor(previous.evidence || [],manager)+'</div>').join('')+'</details>' : '');
52
- }
53
-
54
- async function requestReview({id}) {
55
- modal({title:'提交验收',sub:id,body:'<label class="qip-business-field">整改完成情况及验收依据'+
56
- UI.input('note','',{type:'textarea',rows:4,placeholder:'记录复测批次、结果和现场证据'})+'</label>',
57
- footer:act('提交申请','caseReviewSubmit',{id,requestId:crypto.randomUUID()},'btn btn-primary')});
58
- }
59
- async function submitReview({id,requestId}) {
60
- const {note}=UI.readForm(document.querySelector('.dm-panel'));
61
- await API.post(wb+'/cases/'+encodeURIComponent(id)+'/request-review',{requestId,note});
62
- closeModal(); toast('已提交验收','ok'); await global.AppRefresh();
63
- }
64
- async function reviewCase({id}) {
65
- const {row}=await API.get(api+'/issues/'+encodeURIComponent(id));
66
- const r=row.review;
67
- if (r?.state!=='pending') return toast('事项已处理,请刷新','warn');
68
- modal({title:'验收 · '+row.title,sub:id,
69
- body:infoGrid([['提交人',esc(r.submittedBy?.name)],['提交时间',esc(dt(r.requestedAt))],
70
- ['整改说明',esc(r.note),true],['临时措施',esc(r.containment || '—'),true],['复测结果',esc(r.verifyResult || '—'),true]])+
71
- '<div class="qip-business-actions">'+filesFor(r.evidence || [],true)+'</div>'+
72
- '<label class="qip-business-field">验收结论 / 退回原因'+UI.input('opinion','',{type:'textarea',rows:4})+'</label>',
73
- footer:act('退回整改','caseReviewSave',{id,reviewId:r.id,decision:'returned'},'btn')+
74
- act('通过并结案','caseReviewSave',{id,reviewId:r.id,decision:'accepted'},'btn btn-primary')});
75
- }
76
- async function saveReview({id,reviewId,decision},button) {
77
- const {opinion}=UI.readForm(document.querySelector('.dm-panel'));
78
- button.disabled=true;
79
- try {
80
- await API.post(wb+'/cases/'+encodeURIComponent(id)+'/decision',{reviewId,decision,opinion});
81
- closeModal(); toast(decision==='accepted'?'已验收结案':'已退回整改','ok'); await global.AppRefresh();
82
- } finally {button.disabled=false;}
83
- }
84
-
85
- function packetReview({id}) {
86
- const row=reviewRows.find(packet=>packet.id===id);
87
- if (!row) return;
88
- const details=(row.items||[]).filter(item=>!item.resolved).map(item=>
89
- '<div class="wb-flow-summary"><b>'+esc(item.title || '待核对资料')+'</b><p>'+esc(item.reason)+'</p>'+
90
- (item.evidence?'<p class="wb-history-note">'+esc(item.evidence)+'</p>':'')+
91
- act('核对这条','packetReviewItem',{packetId:id,itemId:item.id},'btn btn-sm')+'</div>').join('');
92
- modal({title:'核对员工提交资料',sub:id,body:'<p>'+esc([row.person,row.workshop].filter(Boolean).join(' · '))+
93
- '</p>'+filesFor(row.files,true)+(row.note?'<p>'+esc(row.note)+'</p>':'')+details,
94
- footer:row.state==='failed'||row.state==='queued' ? act('转人工复核','packetResolve',{packetId:id,action:'manual'},'btn btn-primary')+
95
- (row.state==='failed'?act('重试 AI','packetRetry',{id},'btn'):'') : ''});
96
- }
97
- function packetItem({packetId,itemId}) {
98
- const packet=reviewRows.find(row=>row.id===packetId), row=packet?.items.find(item=>item.id===itemId);
99
- if (!row) return;
100
- modal({title:'复核提交条目',sub:row.reason,
101
- body:'<div class="qip-business-form"><label class="qip-business-field full">新事项标题'+UI.input('title',row.title||'')+'</label>'+
102
- '<label class="qip-business-field">车间'+UI.input('workshop',packet.workshop || row.workshop || workshops()[0],{type:'select',options:workshops()})+'</label>'+
103
- '<label class="qip-business-field">关联现有事项编号'+UI.input('issueId',row.issueId||'')+'</label>'+
104
- '<label class="qip-business-field full">复核意见'+UI.input('opinion','',{type:'textarea',rows:3})+'</label></div>',
105
- footer:act('结束复核','packetResolve',{packetId,itemId,action:'dismiss'},'btn')+
106
- act('关联已有事项','packetResolve',{packetId,itemId,action:'link'},'btn')+
107
- act('登记新事项','packetResolve',{packetId,itemId,action:'create'},'btn btn-primary')});
108
- }
109
- async function resolvePacket({packetId,itemId,action}) {
110
- const body=UI.readForm(document.querySelector('.dm-panel'));
111
- await API.post(wb+'/submissions/'+encodeURIComponent(packetId)+'/resolve',{...body,itemId,action});
112
- closeModal(); toast('复核已保存','ok'); await global.AppRefresh();
113
- }
114
- async function retryPacket({id}) {
115
- await API.post(wb+'/submissions/'+encodeURIComponent(id)+'/retry');
116
- closeModal(); toast('已加入识别队列','ok'); await global.AppRefresh();
117
- }
118
- function sourceTable(rows,manager=false) {
119
- return table(['数据源','类型 / 车间','最近运行','状态',...(manager?['操作']:[])],rows.map(r=>[
120
- esc(r.name),esc([labels[r.target],r.workshop].filter(Boolean).join(' · ')),esc(date(r.last?.at)),
121
- tag(!r.enabled && manager?'暂停':sourceStates[r.last?.state] || '待首次同步',r.last?.state==='complete'?'green':'gray'),
122
- ...(manager?[act('设置','sourceEdit',{id:r.id},'btn btn-sm')+act('试同步','sourceRun',{id:r.id,mode:'preview'},'btn btn-sm')+
123
- act('立即同步','sourceRun',{id:r.id,mode:'sync'},'btn btn-sm btn-primary')+act('记录','sourceLogs',{id:r.id},'btn btn-sm')]:[]),
124
- ]),{empty:manager?'暂无数据源,可以先新建并试同步':'本车间暂无已启用的数据源'});
125
- }
126
- Pages.dataSources={
127
- title:'业务数据源',sub:'设置字段映射、试同步和增量同步',
128
- async render(){
129
- const result=await API.get(wb+'/sources');
130
- sources=result.rows;
131
- sourceFields=result.fields;
132
- return card('业务数据源','支持 HTTP JSON 接口和 SQLite 只读数据源',sourceTable(sources,true),
133
- act('+ 新建数据源','sourceEdit',{},'btn btn-primary'));
134
- },
135
- };
136
- function dataFields(target) {
137
- return sourceFields[target] || [];
138
- }
139
- function editSource({id}) {
140
- const source=sources.find(row=>row.id===id)||{};
141
- modal({title:id?'设置数据源':'新建数据源',width:'wide',
142
- body:'<div class="qip-business-form"><label class="qip-business-field">数据源名称'+UI.input('name',source.name||'')+'</label>'+
143
- '<label class="qip-business-field">车间'+UI.input('workshop',source.workshop||workshops()[0],{type:'select',options:workshops()})+'</label>'+
144
- '<label class="qip-business-field">来源类型'+UI.input('kind',source.kind||'http',{type:'select',options:[
145
- {value:'http',label:'HTTP JSON(MES / ERP / 数据库网关)'},{value:'sqlite',label:'SQLite 文件(只读)'}]})+'</label>'+
146
- '<label class="qip-business-field">导入的数据'+UI.input('target',source.target||'issues',{type:'select',options:Object.entries(labels).map(([value,label])=>({value,label}))})+'</label>'+
147
- '<label class="qip-business-field">递增的整数 ID 列'+UI.input('cursorField',source.cursorField||'id')+'</label>'+
148
- '<label class="qip-business-field">同步间隔(分钟)'+UI.input('minutes',source.minutes||30,{type:'number'})+'</label>'+
149
- '<div class="full" data-source-connection></div><div class="full" data-source-mapping></div>'+
150
- '<div class="full">'+UI.input('enabled',source.enabled===true,{type:'checkbox',label:'启用定时同步'})+'</div></div>',
151
- footer:act('保存配置','sourceSave',{id},'btn btn-primary')});
152
- const panel=document.querySelector('.dm-panel');
153
- const selected=name=>panel.querySelector('[data-field='+name+']').value;
154
- const drawConnection=()=>{
155
- panel.querySelector('[data-source-connection]').innerHTML=selected('kind')==='http' ?
156
- '<label class="qip-business-field">JSON 接口地址'+UI.input('endpoint',source.endpoint||'',{placeholder:'https://mes.example/api/quality'})+'</label>'+
157
- '<label class="qip-business-field">访问令牌'+UI.input('apiKey','',{type:'password',placeholder:source.hasKey?'已配置,留空继续使用':'需要时填写 Bearer 令牌'})+'</label>'+
158
- (source.hasKey?UI.input('clearKey',false,{type:'checkbox',label:'清除现有令牌'}):'')+
159
- '<p>接口收到 after 和 limit,返回按递增 ID 排序的 JSON 数组或含 rows 的对象。</p>' :
160
- '<label class="qip-business-field">SQLite 文件绝对路径'+UI.input('filename',source.filename||'')+'</label>'+
161
- '<label class="qip-business-field">业务表名'+UI.input('table',source.table||'')+'</label>';
162
- };
163
- const drawMapping=()=>{
164
- panel.querySelector('[data-source-mapping]').innerHTML='<h4>字段映射</h4><p>为平台字段填写源系统列名,带星号的字段必填。</p>'+
165
- '<div class="qip-business-form">'+dataFields(selected('target')).map(({key,label,required})=>
166
- '<label class="qip-business-field">'+esc(label)+(required?' *':'')+UI.input('map-'+key,source.mapping?.[key]||'',{placeholder:required?key:'选填'})+'</label>').join('')+'</div>';
167
- };
168
- panel.querySelector('[data-field=kind]').onchange=drawConnection;
169
- panel.querySelector('[data-field=target]').onchange=drawMapping;
170
- drawConnection();
171
- drawMapping();
172
- }
173
- async function saveSource({id}) {
174
- const values=UI.readForm(document.querySelector('.dm-panel')), mapping={};
175
- for (const [key,value] of Object.entries(values)) if (key.startsWith('map-')) {
176
- mapping[key.slice(4)]=value; delete values[key];
177
- }
178
- await API.post(wb+'/sources',{...values,id,mapping});
179
- closeModal(); toast('已保存,可先试同步','ok'); await global.AppRefresh();
180
- }
181
- async function runSource({id,mode},button) {
182
- button.disabled=true;
183
- try {
184
- const {result:r}=await API.post(wb+'/sources/'+encodeURIComponent(id)+'/'+mode,{});
185
- await global.AppRefresh();
186
- modal({title:mode==='preview'?'试同步结果':'本次同步结果',
187
- body:infoGrid([['状态',esc(r.message||sourceStates[r.state]||r.state)],['读到',r.read],['可写入',r.accepted??0],
188
- ['已写入',r.imported],['重复',r.duplicates],['拒绝或待核对',(r.pending||0)+(r.rejected||0)+(r.review||0)]])+
189
- (r.errors?.length?'<ul>'+r.errors.map(error=>'<li>'+esc(error)+'</li>').join('')+'</ul>':'')+
190
- (r.sample?.length?'<details><summary>查看本次样例</summary><pre class="wb-flow-pre">'+esc(JSON.stringify(r.sample,null,2))+'</pre></details>':'')});
191
- } finally {button.disabled=false;}
192
- }
193
- function sourceLogs({id}) {
194
- const source=sources.find(row=>row.id===id);
195
- modal({title:'同步运行记录',sub:source?.name,
196
- body:table(['时间','状态','读取 / 写入','详情'],(source?.history||[]).map(row=>[
197
- esc(dt(row.at)),esc(sourceStates[row.state]||row.state),(row.read||0)+' / '+(row.imported||0),esc(row.message || ''),
198
- ]),{empty:'还没有运行记录'})});
199
- }
200
-
201
- global.QualityWorkflow={caseReviewMarkup,
202
- actions:{caseReviewRequest:requestReview,caseReviewSubmit:submitReview,caseReviewDecision:reviewCase,caseReviewSave:saveReview,
203
- packetReview,packetReviewItem:packetItem,packetResolve:resolvePacket,packetRetry:retryPacket,
204
- sourceEdit:editSource,sourceSave:saveSource,sourceRun:runSource,sourceLogs}};
205
- })(window);
1
+ (function (global) {
2
+ 'use strict';
3
+ const { UI, API, Pages } = global;
4
+ const { act, card, empty, esc, dt, table, modal, closeModal, toast, tag, infoGrid } = UI;
5
+ const api='/qip-real-workbench/api';
6
+ const wb=api+'/workbench';
7
+ const labels={issues:'问题清单',measurements:'测量数据',defects:'质检缺陷'};
8
+ const packetStates={queued:'等待识别',waiting_model:'等待模型连接',review:'待人工复核',failed:'识别失败',done:'已核对'};
9
+ const statusLabels={pending:'待主管验收',returned:'已退回整改',accepted:'验收通过'};
10
+ const sourceStates={complete:'已同步',failed:'连接或同步失败',blocked:'有待校验记录'};
11
+ const date=value=>value ? (/^\d{4}-\d{2}-\d{2}$/.test(value)?value:dt(value)) : '—';
12
+ const filesFor=(files,manager=false)=>files.map(({id,name})=>'<a class="btn btn-sm" href="'+
13
+ (manager?api+'/enterprise-kb/files/':wb+'/files/')+encodeURIComponent(id)+'" download>'+esc(name)+'</a>').join(' ');
14
+ const workshops=()=>global.State.bootstrap?.naming?.workshops || [];
15
+ let reviewRows=[], sources=[], sourceFields={};
16
+ const priority=(row)=>row.priority==='overdue'?tag('已超期','red'):row.priority==='soon'?tag('三天内到期','orange'):'';
17
+ function packetLinks(row) {
18
+ if (row.state==='done' && !row.results.length) return '<span class="wb-profile-context">未发现可登记异常</span>';
19
+ if (row.state==='failed' && row.failure) return esc(row.failure);
20
+ return row.results.map(r=>r.issueId ? act(esc(r.title || r.issueId),'issueDetail',{id:r.issueId},'btn btn-sm') :
21
+ tag(({linked:'已补入证据',duplicate:'重复记录已跳过',dismissed:'复核完毕',created:'已登记'})[r.state]||r.state,'gray')).join(' ');
22
+ }
23
+ function packetTable(rows,manager=false) {
24
+ return table(['提交时间','原件','进度','处理结果',''],rows.map(row=>[
25
+ esc(dt(row.createdAt)),filesFor(row.files,manager),tag(packetStates[row.state] || row.state,row.state==='review'?'orange':'blue'),
26
+ packetLinks(row),manager ? act('处理','packetReview',{id:row.id},'btn btn-sm') :
27
+ row.state==='failed' ? act('重试识别','packetRetry',{id:row.id},'btn btn-sm') : '',
28
+ ]),{empty:manager?'暂无待复核资料':'暂无批量提交资料'});
29
+ }
30
+
31
+ Pages.intakeReview={
32
+ title:'历史资料复核',sub:'处理待复核的历史资料',
33
+ async render(){
34
+ const packets=await API.get(wb+'/intake-review');
35
+ reviewRows=packets.rows;
36
+ return card('资料复核',packets.modelAvailable?'':'模型未连接,可手动处理',packetTable(packets.rows,true));
37
+ },
38
+ };
39
+ function caseReviewMarkup(row,manager=false) {
40
+ const r=row.review;
41
+ const deadline=row.dueAt ? '<p>整改期限 '+esc(date(row.dueAt))+' '+priority(row)+'</p>' : '';
42
+ if (!r) return deadline;
43
+ const person=r.decidedBy || r.submittedBy;
44
+ return deadline+'<section class="wb-flow-summary"><h4><span>'+esc(statusLabels[r.state])+'</span></h4>'+
45
+ '<p>'+esc(person?.name || '本机使用者')+' · '+esc(dt(r.decidedAt || r.requestedAt))+'</p>'+
46
+ '<p class="wb-history-note">'+esc(r.opinion || r.note)+'</p>'+
47
+ (r.evidence?.length ? '<p>验收时提交的附件 '+filesFor(r.evidence,manager)+'</p>' : '')+'</section>'+
48
+ (row.reviewHistory?.length ? '<details><summary>往轮验收记录('+row.reviewHistory.length+')</summary>'+
49
+ row.reviewHistory.map(previous=>'<div class="wb-flow-summary"><b>'+esc(statusLabels[previous.state])+'</b><p>'+
50
+ esc(previous.submittedBy?.name)+' → '+esc(previous.decidedBy?.name || '—')+' · '+esc(dt(previous.decidedAt || previous.requestedAt))+
51
+ '</p><p>'+esc(previous.opinion || previous.note)+'</p>'+filesFor(previous.evidence || [],manager)+'</div>').join('')+'</details>' : '');
52
+ }
53
+
54
+ async function requestReview({id}) {
55
+ modal({title:'提交验收',sub:id,body:'<label class="qip-business-field">整改完成情况及验收依据'+
56
+ UI.input('note','',{type:'textarea',rows:4,placeholder:'记录复测批次、结果和现场证据'})+'</label>',
57
+ footer:act('提交申请','caseReviewSubmit',{id,requestId:crypto.randomUUID()},'btn btn-primary')});
58
+ }
59
+ async function submitReview({id,requestId}) {
60
+ const {note}=UI.readForm(document.querySelector('.dm-panel'));
61
+ await API.post(wb+'/cases/'+encodeURIComponent(id)+'/request-review',{requestId,note});
62
+ closeModal(); toast('已提交验收','ok'); await global.AppRefresh();
63
+ }
64
+ async function reviewCase({id}) {
65
+ const {row}=await API.get(api+'/issues/'+encodeURIComponent(id));
66
+ const r=row.review;
67
+ if (r?.state!=='pending') return toast('事项已处理,请刷新','warn');
68
+ modal({title:'验收 · '+row.title,sub:id,
69
+ body:infoGrid([['提交人',esc(r.submittedBy?.name)],['提交时间',esc(dt(r.requestedAt))],
70
+ ['整改说明',esc(r.note),true],['临时措施',esc(r.containment || '—'),true],['复测结果',esc(r.verifyResult || '—'),true]])+
71
+ '<div class="qip-business-actions">'+filesFor(r.evidence || [],true)+'</div>'+
72
+ '<label class="qip-business-field">验收结论 / 退回原因'+UI.input('opinion','',{type:'textarea',rows:4})+'</label>',
73
+ footer:act('退回整改','caseReviewSave',{id,reviewId:r.id,decision:'returned'},'btn')+
74
+ act('通过并结案','caseReviewSave',{id,reviewId:r.id,decision:'accepted'},'btn btn-primary')});
75
+ }
76
+ async function saveReview({id,reviewId,decision},button) {
77
+ const {opinion}=UI.readForm(document.querySelector('.dm-panel'));
78
+ button.disabled=true;
79
+ try {
80
+ await API.post(wb+'/cases/'+encodeURIComponent(id)+'/decision',{reviewId,decision,opinion});
81
+ closeModal(); toast(decision==='accepted'?'已验收结案':'已退回整改','ok'); await global.AppRefresh();
82
+ } finally {button.disabled=false;}
83
+ }
84
+
85
+ function packetReview({id}) {
86
+ const row=reviewRows.find(packet=>packet.id===id);
87
+ if (!row) return;
88
+ const details=(row.items||[]).filter(item=>!item.resolved).map(item=>
89
+ '<div class="wb-flow-summary"><b>'+esc(item.title || '待核对资料')+'</b><p>'+esc(item.reason)+'</p>'+
90
+ (item.evidence?'<p class="wb-history-note">'+esc(item.evidence)+'</p>':'')+
91
+ act('核对这条','packetReviewItem',{packetId:id,itemId:item.id},'btn btn-sm')+'</div>').join('');
92
+ modal({title:'核对员工提交资料',sub:id,body:'<p>'+esc([row.person,row.workshop].filter(Boolean).join(' · '))+
93
+ '</p>'+filesFor(row.files,true)+(row.note?'<p>'+esc(row.note)+'</p>':'')+details,
94
+ footer:row.state==='failed'||row.state==='queued' ? act('转人工复核','packetResolve',{packetId:id,action:'manual'},'btn btn-primary')+
95
+ (row.state==='failed'?act('重试 AI','packetRetry',{id},'btn'):'') : ''});
96
+ }
97
+ function packetItem({packetId,itemId}) {
98
+ const packet=reviewRows.find(row=>row.id===packetId), row=packet?.items.find(item=>item.id===itemId);
99
+ if (!row) return;
100
+ modal({title:'复核提交条目',sub:row.reason,
101
+ body:'<div class="qip-business-form"><label class="qip-business-field full">新事项标题'+UI.input('title',row.title||'')+'</label>'+
102
+ '<label class="qip-business-field">车间'+UI.input('workshop',packet.workshop || row.workshop || workshops()[0],{type:'select',options:workshops()})+'</label>'+
103
+ '<label class="qip-business-field">关联现有事项编号'+UI.input('issueId',row.issueId||'')+'</label>'+
104
+ '<label class="qip-business-field full">复核意见'+UI.input('opinion','',{type:'textarea',rows:3})+'</label></div>',
105
+ footer:act('结束复核','packetResolve',{packetId,itemId,action:'dismiss'},'btn')+
106
+ act('关联已有事项','packetResolve',{packetId,itemId,action:'link'},'btn')+
107
+ act('登记新事项','packetResolve',{packetId,itemId,action:'create'},'btn btn-primary')});
108
+ }
109
+ async function resolvePacket({packetId,itemId,action}) {
110
+ const body=UI.readForm(document.querySelector('.dm-panel'));
111
+ await API.post(wb+'/submissions/'+encodeURIComponent(packetId)+'/resolve',{...body,itemId,action});
112
+ closeModal(); toast('复核已保存','ok'); await global.AppRefresh();
113
+ }
114
+ async function retryPacket({id}) {
115
+ await API.post(wb+'/submissions/'+encodeURIComponent(id)+'/retry');
116
+ closeModal(); toast('已加入识别队列','ok'); await global.AppRefresh();
117
+ }
118
+ function sourceTable(rows,manager=false) {
119
+ return table(['数据源','类型 / 车间','最近运行','状态',...(manager?['操作']:[])],rows.map(r=>[
120
+ esc(r.name),esc([labels[r.target],r.workshop].filter(Boolean).join(' · ')),esc(date(r.last?.at)),
121
+ tag(!r.enabled && manager?'暂停':sourceStates[r.last?.state] || '待首次同步',r.last?.state==='complete'?'green':'gray'),
122
+ ...(manager?[act('设置','sourceEdit',{id:r.id},'btn btn-sm')+act('试同步','sourceRun',{id:r.id,mode:'preview'},'btn btn-sm')+
123
+ act('立即同步','sourceRun',{id:r.id,mode:'sync'},'btn btn-sm btn-primary')+act('记录','sourceLogs',{id:r.id},'btn btn-sm')]:[]),
124
+ ]),{empty:manager?'暂无数据源,可以先新建并试同步':'本车间暂无已启用的数据源'});
125
+ }
126
+ Pages.dataSources={
127
+ title:'业务数据源',sub:'设置字段映射、试同步和增量同步',
128
+ async render(){
129
+ const result=await API.get(wb+'/sources');
130
+ sources=result.rows;
131
+ sourceFields=result.fields;
132
+ return card('业务数据源','支持 HTTP JSON 接口和 SQLite 只读数据源',sourceTable(sources,true),
133
+ act('+ 新建数据源','sourceEdit',{},'btn btn-primary'));
134
+ },
135
+ };
136
+ function dataFields(target) {
137
+ return sourceFields[target] || [];
138
+ }
139
+ function editSource({id}) {
140
+ const source=sources.find(row=>row.id===id)||{};
141
+ modal({title:id?'设置数据源':'新建数据源',width:'wide',
142
+ body:'<div class="qip-business-form"><label class="qip-business-field">数据源名称'+UI.input('name',source.name||'')+'</label>'+
143
+ '<label class="qip-business-field">车间'+UI.input('workshop',source.workshop||workshops()[0],{type:'select',options:workshops()})+'</label>'+
144
+ '<label class="qip-business-field">来源类型'+UI.input('kind',source.kind||'http',{type:'select',options:[
145
+ {value:'http',label:'HTTP JSON(MES / ERP / 数据库网关)'},{value:'sqlite',label:'SQLite 文件(只读)'}]})+'</label>'+
146
+ '<label class="qip-business-field">导入的数据'+UI.input('target',source.target||'issues',{type:'select',options:Object.entries(labels).map(([value,label])=>({value,label}))})+'</label>'+
147
+ '<label class="qip-business-field">递增的整数 ID 列'+UI.input('cursorField',source.cursorField||'id')+'</label>'+
148
+ '<label class="qip-business-field">同步间隔(分钟)'+UI.input('minutes',source.minutes||30,{type:'number'})+'</label>'+
149
+ '<div class="full" data-source-connection></div><div class="full" data-source-mapping></div>'+
150
+ '<div class="full">'+UI.input('enabled',source.enabled===true,{type:'checkbox',label:'启用定时同步'})+'</div></div>',
151
+ footer:act('保存配置','sourceSave',{id},'btn btn-primary')});
152
+ const panel=document.querySelector('.dm-panel');
153
+ const selected=name=>panel.querySelector('[data-field='+name+']').value;
154
+ const drawConnection=()=>{
155
+ panel.querySelector('[data-source-connection]').innerHTML=selected('kind')==='http' ?
156
+ '<label class="qip-business-field">JSON 接口地址'+UI.input('endpoint',source.endpoint||'',{placeholder:'https://mes.example/api/quality'})+'</label>'+
157
+ '<label class="qip-business-field">访问令牌'+UI.input('apiKey','',{type:'password',placeholder:source.hasKey?'已配置,留空继续使用':'需要时填写 Bearer 令牌'})+'</label>'+
158
+ (source.hasKey?UI.input('clearKey',false,{type:'checkbox',label:'清除现有令牌'}):'')+
159
+ '<p>接口收到 after 和 limit,返回按递增 ID 排序的 JSON 数组或含 rows 的对象。</p>' :
160
+ '<label class="qip-business-field">SQLite 文件绝对路径'+UI.input('filename',source.filename||'')+'</label>'+
161
+ '<label class="qip-business-field">业务表名'+UI.input('table',source.table||'')+'</label>';
162
+ };
163
+ const drawMapping=()=>{
164
+ panel.querySelector('[data-source-mapping]').innerHTML='<h4>字段映射</h4><p>为平台字段填写源系统列名,带星号的字段必填。</p>'+
165
+ '<div class="qip-business-form">'+dataFields(selected('target')).map(({key,label,required})=>
166
+ '<label class="qip-business-field">'+esc(label)+(required?' *':'')+UI.input('map-'+key,source.mapping?.[key]||'',{placeholder:required?key:'选填'})+'</label>').join('')+'</div>';
167
+ };
168
+ panel.querySelector('[data-field=kind]').onchange=drawConnection;
169
+ panel.querySelector('[data-field=target]').onchange=drawMapping;
170
+ drawConnection();
171
+ drawMapping();
172
+ }
173
+ async function saveSource({id}) {
174
+ const values=UI.readForm(document.querySelector('.dm-panel')), mapping={};
175
+ for (const [key,value] of Object.entries(values)) if (key.startsWith('map-')) {
176
+ mapping[key.slice(4)]=value; delete values[key];
177
+ }
178
+ await API.post(wb+'/sources',{...values,id,mapping});
179
+ closeModal(); toast('已保存,可先试同步','ok'); await global.AppRefresh();
180
+ }
181
+ async function runSource({id,mode},button) {
182
+ button.disabled=true;
183
+ try {
184
+ const {result:r}=await API.post(wb+'/sources/'+encodeURIComponent(id)+'/'+mode,{});
185
+ await global.AppRefresh();
186
+ modal({title:mode==='preview'?'试同步结果':'本次同步结果',
187
+ body:infoGrid([['状态',esc(r.message||sourceStates[r.state]||r.state)],['读到',r.read],['可写入',r.accepted??0],
188
+ ['已写入',r.imported],['重复',r.duplicates],['拒绝或待核对',(r.pending||0)+(r.rejected||0)+(r.review||0)]])+
189
+ (r.errors?.length?'<ul>'+r.errors.map(error=>'<li>'+esc(error)+'</li>').join('')+'</ul>':'')+
190
+ (r.sample?.length?'<details><summary>查看本次样例</summary><pre class="wb-flow-pre">'+esc(JSON.stringify(r.sample,null,2))+'</pre></details>':'')});
191
+ } finally {button.disabled=false;}
192
+ }
193
+ function sourceLogs({id}) {
194
+ const source=sources.find(row=>row.id===id);
195
+ modal({title:'同步运行记录',sub:source?.name,
196
+ body:table(['时间','状态','读取 / 写入','详情'],(source?.history||[]).map(row=>[
197
+ esc(dt(row.at)),esc(sourceStates[row.state]||row.state),(row.read||0)+' / '+(row.imported||0),esc(row.message || ''),
198
+ ]),{empty:'还没有运行记录'})});
199
+ }
200
+
201
+ global.QualityWorkflow={caseReviewMarkup,
202
+ actions:{caseReviewRequest:requestReview,caseReviewSubmit:submitReview,caseReviewDecision:reviewCase,caseReviewSave:saveReview,
203
+ packetReview,packetReviewItem:packetItem,packetResolve:resolvePacket,packetRetry:retryPacket,
204
+ sourceEdit:editSource,sourceSave:saveSource,sourceRun:runSource,sourceLogs}};
205
+ })(window);
@@ -1,41 +1,41 @@
1
- export const planningDateKeys = ['certDate', 'phase1Date', 'auditDate'];
2
-
3
- export function isCalendarDay(value) {
4
- if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(value) || Number(value.slice(0, 4)) < 1900) return false;
5
- return new Date(value + 'T00:00:00Z').toISOString().slice(0, 10) === value;
6
- }
7
-
8
- export function localToday(now = new Date()) {
9
- return [now.getFullYear(), now.getMonth() + 1, now.getDate()].map(value => String(value).padStart(2, '0')).join('-');
10
- }
11
-
12
- export function planningDateLimits(survey, today = localToday()) {
13
- const cert = isCalendarDay(survey.certDate) ? survey.certDate : '';
14
- const phase1 = isCalendarDay(survey.phase1Date) ? survey.phase1Date : '';
15
- const audit = isCalendarDay(survey.auditDate) ? survey.auditDate : '';
16
- const firstBound = [audit, cert].filter(Boolean).sort()[0] || '';
17
- return {
18
- certDate: { min: [today, phase1, audit].sort().at(-1), max: '' },
19
- phase1Date: { min: '1900-01-01', max: firstBound },
20
- auditDate: { min: phase1 || '1900-01-01', max: cert },
21
- };
22
- }
23
-
24
- export function planningDateIssue(survey, previous = {}, today = localToday()) {
25
- const changed = key => (survey[key] || '') !== (previous[key] || '');
26
- const cert = survey.certDate;
27
- if (changed('certDate') && isCalendarDay(cert) && cert < today) {
28
- return { key: 'certDate', message: '计划取证日期不能早于今天。' };
29
- }
30
- const pairs = [
31
- ['phase1Date', 'auditDate', '正式审核日期不能早于一阶段审核日期。'],
32
- ['auditDate', 'certDate', '正式审核日期不能晚于计划取证日期。'],
33
- ['phase1Date', 'certDate', '一阶段审核日期不能晚于计划取证日期。'],
34
- ];
35
- for (const [earlier, later, message] of pairs) {
36
- if ((changed(earlier) || changed(later)) && isCalendarDay(survey[earlier]) && isCalendarDay(survey[later]) && survey[earlier] > survey[later]) {
37
- return { key: changed(earlier) ? earlier : later, message };
38
- }
39
- }
40
- return null;
41
- }
1
+ export const planningDateKeys = ['certDate', 'phase1Date', 'auditDate'];
2
+
3
+ export function isCalendarDay(value) {
4
+ if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(value) || Number(value.slice(0, 4)) < 1900) return false;
5
+ return new Date(value + 'T00:00:00Z').toISOString().slice(0, 10) === value;
6
+ }
7
+
8
+ export function localToday(now = new Date()) {
9
+ return [now.getFullYear(), now.getMonth() + 1, now.getDate()].map(value => String(value).padStart(2, '0')).join('-');
10
+ }
11
+
12
+ export function planningDateLimits(survey, today = localToday()) {
13
+ const cert = isCalendarDay(survey.certDate) ? survey.certDate : '';
14
+ const phase1 = isCalendarDay(survey.phase1Date) ? survey.phase1Date : '';
15
+ const audit = isCalendarDay(survey.auditDate) ? survey.auditDate : '';
16
+ const firstBound = [audit, cert].filter(Boolean).sort()[0] || '';
17
+ return {
18
+ certDate: { min: [today, phase1, audit].sort().at(-1), max: '' },
19
+ phase1Date: { min: '1900-01-01', max: firstBound },
20
+ auditDate: { min: phase1 || '1900-01-01', max: cert },
21
+ };
22
+ }
23
+
24
+ export function planningDateIssue(survey, previous = {}, today = localToday()) {
25
+ const changed = key => (survey[key] || '') !== (previous[key] || '');
26
+ const cert = survey.certDate;
27
+ if (changed('certDate') && isCalendarDay(cert) && cert < today) {
28
+ return { key: 'certDate', message: '计划取证日期不能早于今天。' };
29
+ }
30
+ const pairs = [
31
+ ['phase1Date', 'auditDate', '正式审核日期不能早于一阶段审核日期。'],
32
+ ['auditDate', 'certDate', '正式审核日期不能晚于计划取证日期。'],
33
+ ['phase1Date', 'certDate', '一阶段审核日期不能晚于计划取证日期。'],
34
+ ];
35
+ for (const [earlier, later, message] of pairs) {
36
+ if ((changed(earlier) || changed(later)) && isCalendarDay(survey[earlier]) && isCalendarDay(survey[later]) && survey[earlier] > survey[later]) {
37
+ return { key: changed(earlier) ? earlier : later, message };
38
+ }
39
+ }
40
+ return null;
41
+ }