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.
- package/CONTRIBUTING.md +51 -47
- package/LICENSE.md +37 -37
- package/README.en.md +32 -30
- package/README.md +90 -88
- package/agent-host.cjs +277 -277
- package/client.js +199 -92
- package/cordis.patch.yml +5 -5
- package/docs/enterprise-onboarding.md +10 -10
- package/docs/technical-reference.md +223 -223
- package/host.cjs +91 -124
- package/llm-bridge.cjs +234 -234
- package/locale/en.json +5 -5
- package/locale/zh.json +5 -5
- package/package.json +3 -2
- package/public/app.css +3 -0
- package/public/app.js +6 -2
- package/public/index.html +8 -9
- package/public/js/api.js +152 -152
- package/public/js/assistant-history.js +62 -62
- package/public/js/material-library.js +100 -100
- package/public/js/mobile-preview.js +119 -0
- package/public/js/pages-company-knowledge.js +9 -32
- package/public/js/pages-core.js +232 -232
- package/public/js/pages-growth.js +148 -148
- package/public/js/pages-qms.js +1 -1
- package/public/js/pages-qtools.js +410 -410
- package/public/js/pages-thanks.js +71 -71
- package/public/js/plugin-updates.js +53 -0
- package/public/js/quality-workflow.js +205 -205
- package/public/js/survey-dates.js +41 -41
- package/public/js/survey-knowledge.js +301 -301
- package/public/js/tool-wizards.js +621 -621
- package/public/js/ui.js +467 -467
- package/public/js/voice-capture-worklet.js +30 -30
- package/public/js/xiaozhi-voice.js +264 -264
- package/public/js/xiaozhi.js +468 -468
- package/public/platform-help.html +426 -426
- package/public/platform-site/assets/0468a68574112812.css +10703 -10703
- package/public/platform-site/assets/159e086d35adfa1c.css +2094 -2094
- package/public/platform-site/assets/169e3159cade0d9f.css +98 -98
- package/public/platform-site/assets/22b917c4a3d4ae3d.svg +14 -14
- package/public/platform-site/assets/476f9254ccf723e7.css +8265 -8265
- package/public/platform-site/assets/85a0a4fb4416ded9.css +120 -120
- package/public/platform-site/assets/a3b272383226f6d9.svg +135 -135
- package/public/platform-site/assets/fd16dc5f3cc9d97e.svg +104 -104
- package/public/platform-site/assets/qip-favicon.svg +5 -5
- package/public/platform-site/index.html +279 -279
- package/public/platform-site/offline.js +261 -261
- package/public/platform-site/qip-brand.css +566 -566
- package/public/platform-site/qip-module-guides.js +237 -237
- package/public/responsive.css +103 -101
- package/public/vendor/markdown-it-15.0.3.LICENSE +22 -22
- package/public/vendor/markdown-it-15.0.3.umd.min.js +13 -13
- package/public/workbench.css +7 -7
- package/public/xiaozhi.css +292 -292
- package/resources/qms-templates/019ffb58f24ed48d.docx +0 -0
- package/resources/qms-templates/04a69165fc15143a.docx +0 -0
- package/resources/qms-templates/09af69358c989a63.docx +0 -0
- package/resources/qms-templates/0e7ac77844e45311.docx +0 -0
- package/resources/qms-templates/12446a1b5e173c71.docx +0 -0
- package/resources/qms-templates/15ae40f67f9a3efc.docx +0 -0
- package/resources/qms-templates/18a69bbebf2ece7f.docx +0 -0
- package/resources/qms-templates/1978faa989134f02.docx +0 -0
- package/resources/qms-templates/1a30e121de752f7b.docx +0 -0
- package/resources/qms-templates/1b88907969ea7d4c.docx +0 -0
- package/resources/qms-templates/1e92b808722bf90a.docx +0 -0
- package/resources/qms-templates/2091cad340dc0e7f.docx +0 -0
- package/resources/qms-templates/271ae1002c896ed7.docx +0 -0
- package/resources/qms-templates/280ce53e5d3b5fcf.docx +0 -0
- package/resources/qms-templates/28ca8e4ede0adf6d.docx +0 -0
- package/resources/qms-templates/2ac6675f3cb1f993.docx +0 -0
- package/resources/qms-templates/2c3b799389909d8b.docx +0 -0
- package/resources/qms-templates/2c51038ba2cc3264.docx +0 -0
- package/resources/qms-templates/30c888851d16d764.docx +0 -0
- package/resources/qms-templates/3459fc4daaa2743d.docx +0 -0
- package/resources/qms-templates/3751dafc335e0e80.docx +0 -0
- package/resources/qms-templates/38798cd4298cd2db.docx +0 -0
- package/resources/qms-templates/38f551f9d738ab0a.docx +0 -0
- package/resources/qms-templates/3c85a23ea17018b4.docx +0 -0
- package/resources/qms-templates/3cdb7d14caf1b852.docx +0 -0
- package/resources/qms-templates/3f23239bb6b3e1db.docx +0 -0
- package/resources/qms-templates/42a5b9efeeaa8007.docx +0 -0
- package/resources/qms-templates/47352aafe9b8dac1.docx +0 -0
- package/resources/qms-templates/495359b1e3cbb8fe.docx +0 -0
- package/resources/qms-templates/4ca6920464785166.docx +0 -0
- package/resources/qms-templates/4ce862582a7791be.docx +0 -0
- package/resources/qms-templates/54c9a02a10991b9e.docx +0 -0
- package/resources/qms-templates/5aeb8fddf5f3693f.docx +0 -0
- package/resources/qms-templates/5d7e5576b0e73be7.docx +0 -0
- package/resources/qms-templates/5db3a40edac37791.docx +0 -0
- package/resources/qms-templates/5ffa21eb78eb6f77.docx +0 -0
- package/resources/qms-templates/60d0fbcb709b7161.docx +0 -0
- package/resources/qms-templates/63e1d3a166756095.docx +0 -0
- package/resources/qms-templates/65c724c080d32f10.docx +0 -0
- package/resources/qms-templates/674bd7826c6cbac2.docx +0 -0
- package/resources/qms-templates/677e851acca1b879.docx +0 -0
- package/resources/qms-templates/6bf15feb1a0d2a8d.docx +0 -0
- package/resources/qms-templates/6c3889c7d0918db9.docx +0 -0
- package/resources/qms-templates/6c4c349eeb0a96a8.docx +0 -0
- package/resources/qms-templates/6c5befbd33f759c1.docx +0 -0
- package/resources/qms-templates/6df8367901347508.docx +0 -0
- package/resources/qms-templates/71db51997037692b.docx +0 -0
- package/resources/qms-templates/78a8ef8c76510c99.docx +0 -0
- package/resources/qms-templates/8397bfd1c0a1b013.docx +0 -0
- package/resources/qms-templates/84d750cf858b60a1.docx +0 -0
- package/resources/qms-templates/880de58a4b334533.docx +0 -0
- package/resources/qms-templates/88c37d1b87d9b78c.docx +0 -0
- package/resources/qms-templates/88e9cd42f1849462.docx +0 -0
- package/resources/qms-templates/8956597403be35b6.docx +0 -0
- package/resources/qms-templates/94675c810a233e1f.docx +0 -0
- package/resources/qms-templates/94dff59dd7ebec6e.docx +0 -0
- package/resources/qms-templates/9670b9cd02141594.docx +0 -0
- package/resources/qms-templates/98c373ebd7b5163d.docx +0 -0
- package/resources/qms-templates/a4078cf2378a9388.docx +0 -0
- package/resources/qms-templates/a5b110c7ef917139.docx +0 -0
- package/resources/qms-templates/aec75820e45774be.docx +0 -0
- package/resources/qms-templates/b31c085e281d230c.docx +0 -0
- package/resources/qms-templates/b7c1c3c72f8ffeef.docx +0 -0
- package/resources/qms-templates/b81b82eaa5c8f422.docx +0 -0
- package/resources/qms-templates/b92a2fa31f75f137.docx +0 -0
- package/resources/qms-templates/b96c54ae9cfffc54.docx +0 -0
- package/resources/qms-templates/bc47cfd626c010e7.docx +0 -0
- package/resources/qms-templates/be60792734afca69.docx +0 -0
- package/resources/qms-templates/c0018d8ae9ad19e1.docx +0 -0
- package/resources/qms-templates/c171027c964c8be3.docx +0 -0
- package/resources/qms-templates/c4b93d71f5d98b4b.docx +0 -0
- package/resources/qms-templates/c531da29fcb3090f.docx +0 -0
- package/resources/qms-templates/c88eddd43358d015.docx +0 -0
- package/resources/qms-templates/cb978da542f0d892.docx +0 -0
- package/resources/qms-templates/ccde4a94532a8d36.docx +0 -0
- package/resources/qms-templates/cf3fb1e20ae6f24d.docx +0 -0
- package/resources/qms-templates/d231b4982fc8113e.docx +0 -0
- package/resources/qms-templates/d3c55aa5ed14055c.docx +0 -0
- package/resources/qms-templates/db45c44a00a13349.docx +0 -0
- package/resources/qms-templates/db849a41210f54e0.docx +0 -0
- package/resources/qms-templates/dba9ce363d83ddc8.docx +0 -0
- package/resources/qms-templates/dca3ea4c95eb2225.docx +0 -0
- package/resources/qms-templates/dfa4220d2b6b8131.docx +0 -0
- package/resources/qms-templates/dfa51222c777734f.docx +0 -0
- package/resources/qms-templates/e07ea511507e14f5.docx +0 -0
- package/resources/qms-templates/e0a2e00c03458dfa.docx +0 -0
- package/resources/qms-templates/e0e802f46b6764d1.docx +0 -0
- package/resources/qms-templates/e53fc85717f2852b.docx +0 -0
- package/resources/qms-templates/e9dd82d5e54520e5.docx +0 -0
- package/resources/qms-templates/ea7bfc22c06d82a9.docx +0 -0
- package/resources/qms-templates/ecf0db9f37294536.docx +0 -0
- package/resources/qms-templates/f05fcfc87e82ff39.docx +0 -0
- package/resources/qms-templates/fb9e56a17c4a4f97.docx +0 -0
- package/resources/qms-templates/manifest.json +932 -0
- package/src/data/seed-sme.js +317 -317
- package/src/data/seed.js +879 -879
- package/src/lib/backup-identity.js +57 -57
- package/src/lib/chat-answer.js +225 -225
- package/src/lib/chat-context.js +99 -99
- package/src/lib/company-library.js +28 -19
- package/src/lib/data-import.js +217 -217
- package/src/lib/data-sources.js +118 -118
- package/src/lib/demo-data.js +27 -1
- package/src/lib/employee-intake.js +84 -84
- package/src/lib/growth.js +53 -53
- package/src/lib/intake-packets.js +119 -119
- package/src/lib/issue-intake.js +88 -88
- package/src/lib/kb-revision.js +214 -214
- package/src/lib/llm.js +279 -279
- package/src/lib/model-error.js +14 -14
- package/src/lib/privacy.js +26 -26
- package/src/lib/qms-drafting.js +194 -194
- package/src/lib/qms-jobs.js +11 -7
- package/src/lib/qms-manual-review.js +185 -185
- package/src/lib/qms-procedure-review.js +109 -109
- package/src/lib/qms-templates.js +358 -326
- package/src/lib/qms.js +369 -369
- package/src/lib/quality-priority.js +100 -100
- package/src/lib/quality-state.js +92 -92
- package/src/lib/quality-workflow.js +65 -65
- package/src/lib/retrieval.js +159 -159
- package/src/lib/spc.js +127 -127
- package/src/lib/voice-hotwords.txt +22 -22
- package/src/lib/voice-text.js +13 -13
- package/src/lib/voice-worker.js +72 -72
- package/src/lib/voice.js +330 -330
- package/src/lib/workbench-notices.js +49 -49
- package/src/lib/workbench.js +103 -106
- package/src/package.json +3 -3
- package/src/tools/analysis.js +306 -306
- package/src/tools/data.js +596 -596
- package/src/tools/docs.js +430 -430
- package/src/tools/registry.js +57 -57
- package/tools-dsh.cjs +153 -153
- package//345/256/211/350/243/205/350/257/264/346/230/216.md +33 -25
- 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
- package//350/207/252/346/243/200.cjs +88 -88
- package/public/js/remote-knowledge.js +0 -165
- package/public/js/workbench-notices.js +0 -67
- package/public/remote-knowledge-help.html +0 -35
- package/public/remote-knowledge.css +0 -40
- package/src/lib/remote-knowledge.js +0 -284
|
@@ -1,301 +1,301 @@
|
|
|
1
|
-
(function (global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
const { esc, modal, closeModal, toast } = UI;
|
|
4
|
-
const route = '/qip-real-workbench/api/qms/survey/';
|
|
5
|
-
|
|
6
|
-
function buildTree({ folders, sources }) {
|
|
7
|
-
const byId = new Map(folders.map((folder) => [folder.id, { ...folder, children: [], files: [] }]));
|
|
8
|
-
const roots = [];
|
|
9
|
-
for (const folder of byId.values()) {
|
|
10
|
-
const parent = byId.get(folder.parentId);
|
|
11
|
-
(parent ? parent.children : roots).push(folder);
|
|
12
|
-
}
|
|
13
|
-
for (const file of sources) byId.get(file.folderId)?.files.push(file);
|
|
14
|
-
function compact(folder) {
|
|
15
|
-
folder.children = folder.children.filter(compact);
|
|
16
|
-
folder.ready = [...folder.files.filter((file) => file.chunkCount > 0).map((file) => file.id),
|
|
17
|
-
...folder.children.flatMap((child) => child.ready)];
|
|
18
|
-
return folder.files.length > 0 || folder.children.length > 0;
|
|
19
|
-
}
|
|
20
|
-
return roots.filter(compact);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const kinds = { template: '8009 模板', draft: '已生成文件', upload: '企业上传' };
|
|
24
|
-
function sourceTreeHtml(folder) {
|
|
25
|
-
return `<li class="survey-tree-folder" data-scope-folder="${esc(folder.id)}">
|
|
26
|
-
<div class="survey-folder-row">
|
|
27
|
-
<button type="button" class="survey-folder-arrow" data-scope-toggle aria-expanded="false" aria-label="${esc(folder.name)}的子目录和文件">▸</button>
|
|
28
|
-
<label><input type="checkbox" data-scope-check${folder.ready.length ? '' : ' disabled'}>
|
|
29
|
-
<span>${esc(folder.name)}</span><small>${folder.ready.length} 份</small></label>
|
|
30
|
-
</div>
|
|
31
|
-
<ul class="survey-tree-branch" hidden>
|
|
32
|
-
${folder.children.map(sourceTreeHtml).join('')}
|
|
33
|
-
${folder.files.map((file) => {
|
|
34
|
-
const state = file.chunkCount > 0 ? kinds[file.kind] : file.indexStatus === 'indexing' ? '索引中' : '无可读正文';
|
|
35
|
-
return `<li class="survey-tree-file" data-scope-file="${esc(file.id)}">
|
|
36
|
-
<label><input type="checkbox"${file.chunkCount > 0 ? '' : ' disabled'}><span>${esc(file.name)}</span><small>${state}</small></label></li>`;
|
|
37
|
-
}).join('')}
|
|
38
|
-
</ul></li>`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function mountPicker(panel, roots, sources) {
|
|
42
|
-
const tree = panel.querySelector('.survey-source-tree');
|
|
43
|
-
const filter = panel.querySelector('[name="sourceSearch"]');
|
|
44
|
-
const count = panel.querySelector('[data-scope-count]');
|
|
45
|
-
const button = panel.querySelector('[data-scope-submit]');
|
|
46
|
-
const empty = panel.querySelector('[data-scope-empty]');
|
|
47
|
-
const clear = panel.querySelector('[data-scope-clear]');
|
|
48
|
-
const selected = new Set();
|
|
49
|
-
const explicitFolders = new Set();
|
|
50
|
-
const expanded = new Set(roots.length === 1 ? [roots[0].id] : []);
|
|
51
|
-
const directories = new Map();
|
|
52
|
-
const rows = new Map([...tree.querySelectorAll('[data-scope-folder]')].map((node) => [node.dataset.scopeFolder, node]));
|
|
53
|
-
const files = new Map([...tree.querySelectorAll('[data-scope-file]')].map((node) => [node.dataset.scopeFile, node]));
|
|
54
|
-
const names = new Map(sources.map((file) => [file.id, file.name.toLocaleLowerCase()]));
|
|
55
|
-
const results = panel.querySelector('[data-import-results]');
|
|
56
|
-
function register(folder) {
|
|
57
|
-
directories.set(folder.id, folder);
|
|
58
|
-
folder.children.forEach(register);
|
|
59
|
-
}
|
|
60
|
-
roots.forEach(register);
|
|
61
|
-
|
|
62
|
-
function refresh() {
|
|
63
|
-
for (const [id, row] of rows) {
|
|
64
|
-
const ready = directories.get(id).ready;
|
|
65
|
-
const amount = ready.filter((fileId) => selected.has(fileId)).length;
|
|
66
|
-
const check = row.querySelector('[data-scope-check]');
|
|
67
|
-
check.checked = amount > 0 && amount === ready.length;
|
|
68
|
-
check.indeterminate = amount > 0 && amount < ready.length;
|
|
69
|
-
}
|
|
70
|
-
for (const [id, row] of files) row.querySelector('input').checked = selected.has(id);
|
|
71
|
-
count.textContent = '已选 ' + selected.size + ' 份文件';
|
|
72
|
-
clear.disabled = button.disabled = !selected.size;
|
|
73
|
-
}
|
|
74
|
-
function refreshSearch() {
|
|
75
|
-
const key = filter.value.trim().toLocaleLowerCase();
|
|
76
|
-
function visit(folder, ancestorMatch = false) {
|
|
77
|
-
const matched = ancestorMatch || !key || folder.name.toLocaleLowerCase().includes(key);
|
|
78
|
-
const visibleChildren = folder.children.map((child) => visit(child, matched));
|
|
79
|
-
const visibleFiles = folder.files.map((file) => {
|
|
80
|
-
const visible = matched || names.get(file.id).includes(key);
|
|
81
|
-
files.get(file.id).hidden = !visible;
|
|
82
|
-
return visible;
|
|
83
|
-
});
|
|
84
|
-
const row = rows.get(folder.id);
|
|
85
|
-
row.hidden = !matched && !visibleChildren.includes(true) && !visibleFiles.includes(true);
|
|
86
|
-
const open = !row.hidden && (key ? true : expanded.has(folder.id));
|
|
87
|
-
row.lastElementChild.hidden = !open;
|
|
88
|
-
row.querySelector('[data-scope-toggle]').setAttribute('aria-expanded', String(open));
|
|
89
|
-
return !row.hidden;
|
|
90
|
-
}
|
|
91
|
-
const visibleRoots = roots.map((folder) => visit(folder));
|
|
92
|
-
empty.hidden = visibleRoots.includes(true);
|
|
93
|
-
}
|
|
94
|
-
tree.addEventListener('click', (event) => {
|
|
95
|
-
const toggle = event.target.closest('[data-scope-toggle]');
|
|
96
|
-
if (!toggle) return;
|
|
97
|
-
const row = toggle.closest('[data-scope-folder]');
|
|
98
|
-
const id = row.dataset.scopeFolder;
|
|
99
|
-
const open = toggle.getAttribute('aria-expanded') !== 'true';
|
|
100
|
-
if (open) expanded.add(id); else expanded.delete(id);
|
|
101
|
-
toggle.setAttribute('aria-expanded', String(open));
|
|
102
|
-
row.lastElementChild.hidden = !open;
|
|
103
|
-
});
|
|
104
|
-
tree.addEventListener('change', (event) => {
|
|
105
|
-
const checkbox = event.target;
|
|
106
|
-
if (checkbox.type !== 'checkbox') return;
|
|
107
|
-
const fileRow = checkbox.closest('[data-scope-file]');
|
|
108
|
-
if (fileRow) {
|
|
109
|
-
if (checkbox.checked) selected.add(fileRow.dataset.scopeFile); else selected.delete(fileRow.dataset.scopeFile);
|
|
110
|
-
} else {
|
|
111
|
-
const id = checkbox.closest('[data-scope-folder]').dataset.scopeFolder;
|
|
112
|
-
if (checkbox.checked) explicitFolders.add(id); else explicitFolders.delete(id);
|
|
113
|
-
for (const fileId of directories.get(id).ready) {
|
|
114
|
-
if (checkbox.checked) selected.add(fileId); else selected.delete(fileId);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
results.replaceChildren();
|
|
118
|
-
refresh();
|
|
119
|
-
});
|
|
120
|
-
clear.addEventListener('click', () => {
|
|
121
|
-
selected.clear();
|
|
122
|
-
explicitFolders.clear();
|
|
123
|
-
results.replaceChildren();
|
|
124
|
-
refresh();
|
|
125
|
-
});
|
|
126
|
-
filter.addEventListener('input', refreshSearch);
|
|
127
|
-
refreshSearch();
|
|
128
|
-
refresh();
|
|
129
|
-
return {
|
|
130
|
-
refresh,
|
|
131
|
-
selection() {
|
|
132
|
-
const folderIds = [];
|
|
133
|
-
const fileIds = new Set(selected);
|
|
134
|
-
for (const { id, ready } of directories.values()) {
|
|
135
|
-
if (explicitFolders.has(id) && ready.every((fileId) => fileIds.has(fileId))) {
|
|
136
|
-
folderIds.push(id);
|
|
137
|
-
ready.forEach((fileId) => fileIds.delete(fileId));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return { fileIds: [...fileIds], folderIds };
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function candidateGroups(records) {
|
|
146
|
-
const groups = new Map();
|
|
147
|
-
for (const { key, label, value, source, part, evidence } of records) {
|
|
148
|
-
if (!groups.has(key)) groups.set(key, { key, label, options: new Map() });
|
|
149
|
-
const { options } = groups.get(key);
|
|
150
|
-
const normalized = JSON.stringify(Array.isArray(value) ? value.map((entry) => JSON.stringify(entry)).sort() : value);
|
|
151
|
-
if (!options.has(normalized)) options.set(normalized, { value, references: [] });
|
|
152
|
-
options.get(normalized).references.push({ source, part, evidence });
|
|
153
|
-
}
|
|
154
|
-
return [...groups.values()].map(({ options, ...group }) => ({ ...group, options: [...options.values()] }));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function valueText(value) {
|
|
158
|
-
return Array.isArray(value) ? value.map((entry) => typeof entry === 'string' ? entry
|
|
159
|
-
: [entry.dept, entry.owner, entry.duty].filter(Boolean).join(' · ')).join('、') : value;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function renderCandidates(results, records, unavailable, apply, selectionLimits, stopped) {
|
|
163
|
-
const groups = candidateGroups(records);
|
|
164
|
-
const combine = new Set(['certs', 'workshops', ...('products' in selectionLimits ? ['products'] : [])]);
|
|
165
|
-
const unavailableHtml = unavailable.length ? `<details class="survey-import-errors"><summary>${unavailable.length} 项资料未完成提取</summary>
|
|
166
|
-
<ul>${unavailable.map(({ name, reason }) => '<li>' + esc(name) + ' · ' + esc(reason) + '</li>').join('')}</ul></details>` : '';
|
|
167
|
-
if (!groups.length) {
|
|
168
|
-
results.innerHTML = '<p>' + (stopped ? '已停止提取。' : unavailable.length ? '本次没有得到可带入的候选值。'
|
|
169
|
-
: '已读取所选资料,未找到适合当前表单的明确字段。') + '</p>' + unavailableHtml;
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
results.innerHTML = '<p class="survey-candidate-intro">' + (stopped ? '已停止提取。可使用已完成的候选值。'
|
|
173
|
-
: '核对候选值与来源,再带入当前表单。') + '</p>' + unavailableHtml + groups.map((group, i) => {
|
|
174
|
-
const multiple = group.options.length > 1;
|
|
175
|
-
const merge = combine.has(group.key);
|
|
176
|
-
const radio = multiple && !merge;
|
|
177
|
-
return `<fieldset class="survey-candidate-group">
|
|
178
|
-
<legend>${esc(group.label)}</legend>
|
|
179
|
-
${radio ? `<p class="survey-conflict-note">多个来源给出了不同值,请选择一项。</p>
|
|
180
|
-
<label class="survey-keep-current"><input name="candidate-${i}" type="radio" checked> 保留当前填写</label>` : ''}
|
|
181
|
-
${group.options.map(({ value, references }, n) => {
|
|
182
|
-
const preselect = !multiple && references.some(({ source }) => source.kind === 'upload');
|
|
183
|
-
const citations = references.map(({ source, part, evidence }) =>
|
|
184
|
-
`<small><strong>${esc(source.name)}</strong> · ${kinds[source.kind]} · 片段 ${part}<br>${esc(evidence)}</small>`).join('');
|
|
185
|
-
return `<div class="survey-candidate-option">
|
|
186
|
-
<label class="survey-candidate"><input type="${radio ? 'radio' : 'checkbox'}" name="candidate-${i}" data-candidate-group="${i}" value="${n}"${preselect ? ' checked' : ''}>
|
|
187
|
-
<span>${esc(valueText(value))}</span></label>
|
|
188
|
-
${references.length > 1 ? '<details class="survey-candidate-evidence"><summary>查看 ' + references.length + ' 处来源</summary>' + citations + '</details>'
|
|
189
|
-
: '<div class="survey-candidate-evidence">' + citations + '</div>'}</div>`;
|
|
190
|
-
}).join('')}</fieldset>`;
|
|
191
|
-
}).join('') + '<button type="button" class="btn btn-primary" data-apply-candidates>带入勾选项</button>';
|
|
192
|
-
const button = results.querySelector('[data-apply-candidates]');
|
|
193
|
-
const active = () => [...results.querySelectorAll('[data-candidate-group]:checked')];
|
|
194
|
-
const update = () => { button.disabled = !active().length; };
|
|
195
|
-
results.onchange = update;
|
|
196
|
-
button.addEventListener('click', () => {
|
|
197
|
-
const values = new Map();
|
|
198
|
-
for (const input of active()) {
|
|
199
|
-
const group = groups[Number(input.dataset.candidateGroup)];
|
|
200
|
-
const { value } = group.options[Number(input.value)];
|
|
201
|
-
values.set(group.key, combine.has(group.key) ? [...new Set([...(values.get(group.key) || []), ...value])] : value);
|
|
202
|
-
}
|
|
203
|
-
for (const { key, label } of groups) {
|
|
204
|
-
if (selectionLimits[key] && values.get(key)?.length > selectionLimits[key]) {
|
|
205
|
-
toast(label + '最多带入 ' + selectionLimits[key] + ' 项,请调整勾选。', 'warn');
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (values.size) apply([...values].map(([key, value]) => ({ key, value })));
|
|
210
|
-
});
|
|
211
|
-
update();
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async function open({ type, active, apply, limits = {} }) {
|
|
215
|
-
const data = await API.get(route + 'sources');
|
|
216
|
-
if (!active()) return;
|
|
217
|
-
const roots = buildTree(data);
|
|
218
|
-
if (!data.sources.some((file) => file.chunkCount > 0)) {
|
|
219
|
-
const message = data.sources.some((file) => file.indexStatus === 'indexing')
|
|
220
|
-
? '企业资料正在建立正文索引,请稍后重新打开。' : '请在企业知识库上传带正文的公司手册、流程或质量方针。';
|
|
221
|
-
modal({ title: '从知识库带入', body: '<p>' + message + '</p>',
|
|
222
|
-
footer: '<button type="button" class="btn" data-open-library>打开企业知识库</button>',
|
|
223
|
-
onMount(panel) {
|
|
224
|
-
panel.querySelector('[data-open-library]').addEventListener('click', () => {
|
|
225
|
-
closeModal();
|
|
226
|
-
global.AppGo('companyLibrary');
|
|
227
|
-
});
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
modal({
|
|
233
|
-
title: '从知识库带入',
|
|
234
|
-
width: 'wide',
|
|
235
|
-
body: `<form class="survey-scope-form">
|
|
236
|
-
<fieldset class="survey-source-picker">
|
|
237
|
-
<div class="survey-scope-search"><label for="surveySourceSearch">搜索资料</label>
|
|
238
|
-
<input id="surveySourceSearch" name="sourceSearch" type="search" placeholder="输入目录或文件名"></div>
|
|
239
|
-
<p class="survey-source-note">勾选目录会包含子目录下的已索引文件。也可展开目录,逐份勾选。</p>
|
|
240
|
-
<ul class="survey-source-tree">${roots.map(sourceTreeHtml).join('')}</ul>
|
|
241
|
-
<p data-scope-empty hidden>没有找到匹配的目录或文件。</p>
|
|
242
|
-
</fieldset>
|
|
243
|
-
<div class="survey-scope-actions"><span data-scope-count aria-live="polite"></span>
|
|
244
|
-
<button type="button" class="btn" data-scope-clear>清除选择</button>
|
|
245
|
-
<button type="button" class="btn" data-scope-stop hidden>停止</button>
|
|
246
|
-
<button type="submit" class="btn btn-primary" data-scope-submit>提取候选值</button></div>
|
|
247
|
-
</form><div class="survey-import-results" data-import-results aria-live="polite"></div>`,
|
|
248
|
-
onMount(panel) {
|
|
249
|
-
const form = panel.querySelector('form');
|
|
250
|
-
const fieldset = panel.querySelector('.survey-source-picker');
|
|
251
|
-
const submit = panel.querySelector('[data-scope-submit]');
|
|
252
|
-
const clear = panel.querySelector('[data-scope-clear]');
|
|
253
|
-
const stop = panel.querySelector('[data-scope-stop]');
|
|
254
|
-
const results = panel.querySelector('[data-import-results]');
|
|
255
|
-
const picker = mountPicker(panel, roots, data.sources);
|
|
256
|
-
let request = null;
|
|
257
|
-
stop.addEventListener('click', () => request?.abort());
|
|
258
|
-
form.addEventListener('submit', async (event) => {
|
|
259
|
-
event.preventDefault();
|
|
260
|
-
if (request || submit.disabled) return;
|
|
261
|
-
const controller = request = new AbortController();
|
|
262
|
-
const observer = new MutationObserver(() => { if (!panel.isConnected) controller.abort(); });
|
|
263
|
-
observer.observe(document.body, { childList: true });
|
|
264
|
-
fieldset.disabled = submit.disabled = clear.disabled = true;
|
|
265
|
-
stop.hidden = false;
|
|
266
|
-
results.textContent = '正在读取所选资料…';
|
|
267
|
-
const candidates = [];
|
|
268
|
-
const unavailable = [];
|
|
269
|
-
let completed = false;
|
|
270
|
-
let failure = '';
|
|
271
|
-
try {
|
|
272
|
-
await API.stream(route + 'suggest-batch', { ...picker.selection(), type }, (update) => {
|
|
273
|
-
if (update.type === 'batch') {
|
|
274
|
-
candidates.push(...update.candidates);
|
|
275
|
-
unavailable.push(...update.unavailable);
|
|
276
|
-
} else if (update.type === 'progress') {
|
|
277
|
-
results.textContent = '已处理 ' + update.processed + ' / ' + update.total + ' 份文件…';
|
|
278
|
-
} else if (update.type === 'done') completed = true;
|
|
279
|
-
else if (update.type === 'error') failure = update.message;
|
|
280
|
-
}, controller.signal);
|
|
281
|
-
} catch (error) {
|
|
282
|
-
if (!controller.signal.aborted) failure = error.message;
|
|
283
|
-
} finally {
|
|
284
|
-
observer.disconnect();
|
|
285
|
-
request = null;
|
|
286
|
-
stop.hidden = true;
|
|
287
|
-
fieldset.disabled = false;
|
|
288
|
-
picker.refresh();
|
|
289
|
-
}
|
|
290
|
-
if (!panel.isConnected || !active()) return;
|
|
291
|
-
if (failure || (!completed && !controller.signal.aborted)) {
|
|
292
|
-
if (!candidates.length) { results.textContent = failure || '提取中断,请重试。'; return; }
|
|
293
|
-
unavailable.push({ name: '后续资料', reason: failure || '提取中断,可重新选择和提取' });
|
|
294
|
-
}
|
|
295
|
-
renderCandidates(results, candidates, unavailable, apply, limits, controller.signal.aborted);
|
|
296
|
-
});
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
global.SurveyKnowledge = { open };
|
|
301
|
-
})(window);
|
|
1
|
+
(function (global) {
|
|
2
|
+
'use strict';
|
|
3
|
+
const { esc, modal, closeModal, toast } = UI;
|
|
4
|
+
const route = '/qip-real-workbench/api/qms/survey/';
|
|
5
|
+
|
|
6
|
+
function buildTree({ folders, sources }) {
|
|
7
|
+
const byId = new Map(folders.map((folder) => [folder.id, { ...folder, children: [], files: [] }]));
|
|
8
|
+
const roots = [];
|
|
9
|
+
for (const folder of byId.values()) {
|
|
10
|
+
const parent = byId.get(folder.parentId);
|
|
11
|
+
(parent ? parent.children : roots).push(folder);
|
|
12
|
+
}
|
|
13
|
+
for (const file of sources) byId.get(file.folderId)?.files.push(file);
|
|
14
|
+
function compact(folder) {
|
|
15
|
+
folder.children = folder.children.filter(compact);
|
|
16
|
+
folder.ready = [...folder.files.filter((file) => file.chunkCount > 0).map((file) => file.id),
|
|
17
|
+
...folder.children.flatMap((child) => child.ready)];
|
|
18
|
+
return folder.files.length > 0 || folder.children.length > 0;
|
|
19
|
+
}
|
|
20
|
+
return roots.filter(compact);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const kinds = { template: '8009 模板', draft: '已生成文件', upload: '企业上传' };
|
|
24
|
+
function sourceTreeHtml(folder) {
|
|
25
|
+
return `<li class="survey-tree-folder" data-scope-folder="${esc(folder.id)}">
|
|
26
|
+
<div class="survey-folder-row">
|
|
27
|
+
<button type="button" class="survey-folder-arrow" data-scope-toggle aria-expanded="false" aria-label="${esc(folder.name)}的子目录和文件">▸</button>
|
|
28
|
+
<label><input type="checkbox" data-scope-check${folder.ready.length ? '' : ' disabled'}>
|
|
29
|
+
<span>${esc(folder.name)}</span><small>${folder.ready.length} 份</small></label>
|
|
30
|
+
</div>
|
|
31
|
+
<ul class="survey-tree-branch" hidden>
|
|
32
|
+
${folder.children.map(sourceTreeHtml).join('')}
|
|
33
|
+
${folder.files.map((file) => {
|
|
34
|
+
const state = file.chunkCount > 0 ? kinds[file.kind] : file.indexStatus === 'indexing' ? '索引中' : '无可读正文';
|
|
35
|
+
return `<li class="survey-tree-file" data-scope-file="${esc(file.id)}">
|
|
36
|
+
<label><input type="checkbox"${file.chunkCount > 0 ? '' : ' disabled'}><span>${esc(file.name)}</span><small>${state}</small></label></li>`;
|
|
37
|
+
}).join('')}
|
|
38
|
+
</ul></li>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function mountPicker(panel, roots, sources) {
|
|
42
|
+
const tree = panel.querySelector('.survey-source-tree');
|
|
43
|
+
const filter = panel.querySelector('[name="sourceSearch"]');
|
|
44
|
+
const count = panel.querySelector('[data-scope-count]');
|
|
45
|
+
const button = panel.querySelector('[data-scope-submit]');
|
|
46
|
+
const empty = panel.querySelector('[data-scope-empty]');
|
|
47
|
+
const clear = panel.querySelector('[data-scope-clear]');
|
|
48
|
+
const selected = new Set();
|
|
49
|
+
const explicitFolders = new Set();
|
|
50
|
+
const expanded = new Set(roots.length === 1 ? [roots[0].id] : []);
|
|
51
|
+
const directories = new Map();
|
|
52
|
+
const rows = new Map([...tree.querySelectorAll('[data-scope-folder]')].map((node) => [node.dataset.scopeFolder, node]));
|
|
53
|
+
const files = new Map([...tree.querySelectorAll('[data-scope-file]')].map((node) => [node.dataset.scopeFile, node]));
|
|
54
|
+
const names = new Map(sources.map((file) => [file.id, file.name.toLocaleLowerCase()]));
|
|
55
|
+
const results = panel.querySelector('[data-import-results]');
|
|
56
|
+
function register(folder) {
|
|
57
|
+
directories.set(folder.id, folder);
|
|
58
|
+
folder.children.forEach(register);
|
|
59
|
+
}
|
|
60
|
+
roots.forEach(register);
|
|
61
|
+
|
|
62
|
+
function refresh() {
|
|
63
|
+
for (const [id, row] of rows) {
|
|
64
|
+
const ready = directories.get(id).ready;
|
|
65
|
+
const amount = ready.filter((fileId) => selected.has(fileId)).length;
|
|
66
|
+
const check = row.querySelector('[data-scope-check]');
|
|
67
|
+
check.checked = amount > 0 && amount === ready.length;
|
|
68
|
+
check.indeterminate = amount > 0 && amount < ready.length;
|
|
69
|
+
}
|
|
70
|
+
for (const [id, row] of files) row.querySelector('input').checked = selected.has(id);
|
|
71
|
+
count.textContent = '已选 ' + selected.size + ' 份文件';
|
|
72
|
+
clear.disabled = button.disabled = !selected.size;
|
|
73
|
+
}
|
|
74
|
+
function refreshSearch() {
|
|
75
|
+
const key = filter.value.trim().toLocaleLowerCase();
|
|
76
|
+
function visit(folder, ancestorMatch = false) {
|
|
77
|
+
const matched = ancestorMatch || !key || folder.name.toLocaleLowerCase().includes(key);
|
|
78
|
+
const visibleChildren = folder.children.map((child) => visit(child, matched));
|
|
79
|
+
const visibleFiles = folder.files.map((file) => {
|
|
80
|
+
const visible = matched || names.get(file.id).includes(key);
|
|
81
|
+
files.get(file.id).hidden = !visible;
|
|
82
|
+
return visible;
|
|
83
|
+
});
|
|
84
|
+
const row = rows.get(folder.id);
|
|
85
|
+
row.hidden = !matched && !visibleChildren.includes(true) && !visibleFiles.includes(true);
|
|
86
|
+
const open = !row.hidden && (key ? true : expanded.has(folder.id));
|
|
87
|
+
row.lastElementChild.hidden = !open;
|
|
88
|
+
row.querySelector('[data-scope-toggle]').setAttribute('aria-expanded', String(open));
|
|
89
|
+
return !row.hidden;
|
|
90
|
+
}
|
|
91
|
+
const visibleRoots = roots.map((folder) => visit(folder));
|
|
92
|
+
empty.hidden = visibleRoots.includes(true);
|
|
93
|
+
}
|
|
94
|
+
tree.addEventListener('click', (event) => {
|
|
95
|
+
const toggle = event.target.closest('[data-scope-toggle]');
|
|
96
|
+
if (!toggle) return;
|
|
97
|
+
const row = toggle.closest('[data-scope-folder]');
|
|
98
|
+
const id = row.dataset.scopeFolder;
|
|
99
|
+
const open = toggle.getAttribute('aria-expanded') !== 'true';
|
|
100
|
+
if (open) expanded.add(id); else expanded.delete(id);
|
|
101
|
+
toggle.setAttribute('aria-expanded', String(open));
|
|
102
|
+
row.lastElementChild.hidden = !open;
|
|
103
|
+
});
|
|
104
|
+
tree.addEventListener('change', (event) => {
|
|
105
|
+
const checkbox = event.target;
|
|
106
|
+
if (checkbox.type !== 'checkbox') return;
|
|
107
|
+
const fileRow = checkbox.closest('[data-scope-file]');
|
|
108
|
+
if (fileRow) {
|
|
109
|
+
if (checkbox.checked) selected.add(fileRow.dataset.scopeFile); else selected.delete(fileRow.dataset.scopeFile);
|
|
110
|
+
} else {
|
|
111
|
+
const id = checkbox.closest('[data-scope-folder]').dataset.scopeFolder;
|
|
112
|
+
if (checkbox.checked) explicitFolders.add(id); else explicitFolders.delete(id);
|
|
113
|
+
for (const fileId of directories.get(id).ready) {
|
|
114
|
+
if (checkbox.checked) selected.add(fileId); else selected.delete(fileId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
results.replaceChildren();
|
|
118
|
+
refresh();
|
|
119
|
+
});
|
|
120
|
+
clear.addEventListener('click', () => {
|
|
121
|
+
selected.clear();
|
|
122
|
+
explicitFolders.clear();
|
|
123
|
+
results.replaceChildren();
|
|
124
|
+
refresh();
|
|
125
|
+
});
|
|
126
|
+
filter.addEventListener('input', refreshSearch);
|
|
127
|
+
refreshSearch();
|
|
128
|
+
refresh();
|
|
129
|
+
return {
|
|
130
|
+
refresh,
|
|
131
|
+
selection() {
|
|
132
|
+
const folderIds = [];
|
|
133
|
+
const fileIds = new Set(selected);
|
|
134
|
+
for (const { id, ready } of directories.values()) {
|
|
135
|
+
if (explicitFolders.has(id) && ready.every((fileId) => fileIds.has(fileId))) {
|
|
136
|
+
folderIds.push(id);
|
|
137
|
+
ready.forEach((fileId) => fileIds.delete(fileId));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { fileIds: [...fileIds], folderIds };
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function candidateGroups(records) {
|
|
146
|
+
const groups = new Map();
|
|
147
|
+
for (const { key, label, value, source, part, evidence } of records) {
|
|
148
|
+
if (!groups.has(key)) groups.set(key, { key, label, options: new Map() });
|
|
149
|
+
const { options } = groups.get(key);
|
|
150
|
+
const normalized = JSON.stringify(Array.isArray(value) ? value.map((entry) => JSON.stringify(entry)).sort() : value);
|
|
151
|
+
if (!options.has(normalized)) options.set(normalized, { value, references: [] });
|
|
152
|
+
options.get(normalized).references.push({ source, part, evidence });
|
|
153
|
+
}
|
|
154
|
+
return [...groups.values()].map(({ options, ...group }) => ({ ...group, options: [...options.values()] }));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function valueText(value) {
|
|
158
|
+
return Array.isArray(value) ? value.map((entry) => typeof entry === 'string' ? entry
|
|
159
|
+
: [entry.dept, entry.owner, entry.duty].filter(Boolean).join(' · ')).join('、') : value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function renderCandidates(results, records, unavailable, apply, selectionLimits, stopped) {
|
|
163
|
+
const groups = candidateGroups(records);
|
|
164
|
+
const combine = new Set(['certs', 'workshops', ...('products' in selectionLimits ? ['products'] : [])]);
|
|
165
|
+
const unavailableHtml = unavailable.length ? `<details class="survey-import-errors"><summary>${unavailable.length} 项资料未完成提取</summary>
|
|
166
|
+
<ul>${unavailable.map(({ name, reason }) => '<li>' + esc(name) + ' · ' + esc(reason) + '</li>').join('')}</ul></details>` : '';
|
|
167
|
+
if (!groups.length) {
|
|
168
|
+
results.innerHTML = '<p>' + (stopped ? '已停止提取。' : unavailable.length ? '本次没有得到可带入的候选值。'
|
|
169
|
+
: '已读取所选资料,未找到适合当前表单的明确字段。') + '</p>' + unavailableHtml;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
results.innerHTML = '<p class="survey-candidate-intro">' + (stopped ? '已停止提取。可使用已完成的候选值。'
|
|
173
|
+
: '核对候选值与来源,再带入当前表单。') + '</p>' + unavailableHtml + groups.map((group, i) => {
|
|
174
|
+
const multiple = group.options.length > 1;
|
|
175
|
+
const merge = combine.has(group.key);
|
|
176
|
+
const radio = multiple && !merge;
|
|
177
|
+
return `<fieldset class="survey-candidate-group">
|
|
178
|
+
<legend>${esc(group.label)}</legend>
|
|
179
|
+
${radio ? `<p class="survey-conflict-note">多个来源给出了不同值,请选择一项。</p>
|
|
180
|
+
<label class="survey-keep-current"><input name="candidate-${i}" type="radio" checked> 保留当前填写</label>` : ''}
|
|
181
|
+
${group.options.map(({ value, references }, n) => {
|
|
182
|
+
const preselect = !multiple && references.some(({ source }) => source.kind === 'upload');
|
|
183
|
+
const citations = references.map(({ source, part, evidence }) =>
|
|
184
|
+
`<small><strong>${esc(source.name)}</strong> · ${kinds[source.kind]} · 片段 ${part}<br>${esc(evidence)}</small>`).join('');
|
|
185
|
+
return `<div class="survey-candidate-option">
|
|
186
|
+
<label class="survey-candidate"><input type="${radio ? 'radio' : 'checkbox'}" name="candidate-${i}" data-candidate-group="${i}" value="${n}"${preselect ? ' checked' : ''}>
|
|
187
|
+
<span>${esc(valueText(value))}</span></label>
|
|
188
|
+
${references.length > 1 ? '<details class="survey-candidate-evidence"><summary>查看 ' + references.length + ' 处来源</summary>' + citations + '</details>'
|
|
189
|
+
: '<div class="survey-candidate-evidence">' + citations + '</div>'}</div>`;
|
|
190
|
+
}).join('')}</fieldset>`;
|
|
191
|
+
}).join('') + '<button type="button" class="btn btn-primary" data-apply-candidates>带入勾选项</button>';
|
|
192
|
+
const button = results.querySelector('[data-apply-candidates]');
|
|
193
|
+
const active = () => [...results.querySelectorAll('[data-candidate-group]:checked')];
|
|
194
|
+
const update = () => { button.disabled = !active().length; };
|
|
195
|
+
results.onchange = update;
|
|
196
|
+
button.addEventListener('click', () => {
|
|
197
|
+
const values = new Map();
|
|
198
|
+
for (const input of active()) {
|
|
199
|
+
const group = groups[Number(input.dataset.candidateGroup)];
|
|
200
|
+
const { value } = group.options[Number(input.value)];
|
|
201
|
+
values.set(group.key, combine.has(group.key) ? [...new Set([...(values.get(group.key) || []), ...value])] : value);
|
|
202
|
+
}
|
|
203
|
+
for (const { key, label } of groups) {
|
|
204
|
+
if (selectionLimits[key] && values.get(key)?.length > selectionLimits[key]) {
|
|
205
|
+
toast(label + '最多带入 ' + selectionLimits[key] + ' 项,请调整勾选。', 'warn');
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (values.size) apply([...values].map(([key, value]) => ({ key, value })));
|
|
210
|
+
});
|
|
211
|
+
update();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function open({ type, active, apply, limits = {} }) {
|
|
215
|
+
const data = await API.get(route + 'sources');
|
|
216
|
+
if (!active()) return;
|
|
217
|
+
const roots = buildTree(data);
|
|
218
|
+
if (!data.sources.some((file) => file.chunkCount > 0)) {
|
|
219
|
+
const message = data.sources.some((file) => file.indexStatus === 'indexing')
|
|
220
|
+
? '企业资料正在建立正文索引,请稍后重新打开。' : '请在企业知识库上传带正文的公司手册、流程或质量方针。';
|
|
221
|
+
modal({ title: '从知识库带入', body: '<p>' + message + '</p>',
|
|
222
|
+
footer: '<button type="button" class="btn" data-open-library>打开企业知识库</button>',
|
|
223
|
+
onMount(panel) {
|
|
224
|
+
panel.querySelector('[data-open-library]').addEventListener('click', () => {
|
|
225
|
+
closeModal();
|
|
226
|
+
global.AppGo('companyLibrary');
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
modal({
|
|
233
|
+
title: '从知识库带入',
|
|
234
|
+
width: 'wide',
|
|
235
|
+
body: `<form class="survey-scope-form">
|
|
236
|
+
<fieldset class="survey-source-picker">
|
|
237
|
+
<div class="survey-scope-search"><label for="surveySourceSearch">搜索资料</label>
|
|
238
|
+
<input id="surveySourceSearch" name="sourceSearch" type="search" placeholder="输入目录或文件名"></div>
|
|
239
|
+
<p class="survey-source-note">勾选目录会包含子目录下的已索引文件。也可展开目录,逐份勾选。</p>
|
|
240
|
+
<ul class="survey-source-tree">${roots.map(sourceTreeHtml).join('')}</ul>
|
|
241
|
+
<p data-scope-empty hidden>没有找到匹配的目录或文件。</p>
|
|
242
|
+
</fieldset>
|
|
243
|
+
<div class="survey-scope-actions"><span data-scope-count aria-live="polite"></span>
|
|
244
|
+
<button type="button" class="btn" data-scope-clear>清除选择</button>
|
|
245
|
+
<button type="button" class="btn" data-scope-stop hidden>停止</button>
|
|
246
|
+
<button type="submit" class="btn btn-primary" data-scope-submit>提取候选值</button></div>
|
|
247
|
+
</form><div class="survey-import-results" data-import-results aria-live="polite"></div>`,
|
|
248
|
+
onMount(panel) {
|
|
249
|
+
const form = panel.querySelector('form');
|
|
250
|
+
const fieldset = panel.querySelector('.survey-source-picker');
|
|
251
|
+
const submit = panel.querySelector('[data-scope-submit]');
|
|
252
|
+
const clear = panel.querySelector('[data-scope-clear]');
|
|
253
|
+
const stop = panel.querySelector('[data-scope-stop]');
|
|
254
|
+
const results = panel.querySelector('[data-import-results]');
|
|
255
|
+
const picker = mountPicker(panel, roots, data.sources);
|
|
256
|
+
let request = null;
|
|
257
|
+
stop.addEventListener('click', () => request?.abort());
|
|
258
|
+
form.addEventListener('submit', async (event) => {
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
if (request || submit.disabled) return;
|
|
261
|
+
const controller = request = new AbortController();
|
|
262
|
+
const observer = new MutationObserver(() => { if (!panel.isConnected) controller.abort(); });
|
|
263
|
+
observer.observe(document.body, { childList: true });
|
|
264
|
+
fieldset.disabled = submit.disabled = clear.disabled = true;
|
|
265
|
+
stop.hidden = false;
|
|
266
|
+
results.textContent = '正在读取所选资料…';
|
|
267
|
+
const candidates = [];
|
|
268
|
+
const unavailable = [];
|
|
269
|
+
let completed = false;
|
|
270
|
+
let failure = '';
|
|
271
|
+
try {
|
|
272
|
+
await API.stream(route + 'suggest-batch', { ...picker.selection(), type }, (update) => {
|
|
273
|
+
if (update.type === 'batch') {
|
|
274
|
+
candidates.push(...update.candidates);
|
|
275
|
+
unavailable.push(...update.unavailable);
|
|
276
|
+
} else if (update.type === 'progress') {
|
|
277
|
+
results.textContent = '已处理 ' + update.processed + ' / ' + update.total + ' 份文件…';
|
|
278
|
+
} else if (update.type === 'done') completed = true;
|
|
279
|
+
else if (update.type === 'error') failure = update.message;
|
|
280
|
+
}, controller.signal);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (!controller.signal.aborted) failure = error.message;
|
|
283
|
+
} finally {
|
|
284
|
+
observer.disconnect();
|
|
285
|
+
request = null;
|
|
286
|
+
stop.hidden = true;
|
|
287
|
+
fieldset.disabled = false;
|
|
288
|
+
picker.refresh();
|
|
289
|
+
}
|
|
290
|
+
if (!panel.isConnected || !active()) return;
|
|
291
|
+
if (failure || (!completed && !controller.signal.aborted)) {
|
|
292
|
+
if (!candidates.length) { results.textContent = failure || '提取中断,请重试。'; return; }
|
|
293
|
+
unavailable.push({ name: '后续资料', reason: failure || '提取中断,可重新选择和提取' });
|
|
294
|
+
}
|
|
295
|
+
renderCandidates(results, candidates, unavailable, apply, limits, controller.signal.aborted);
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
global.SurveyKnowledge = { open };
|
|
301
|
+
})(window);
|