Compare commits

...
2 Commits
Author SHA1 Message Date
xiaoqidun 44eb9e20b9 fix(修复问题): 修复注解重复等待与进度丢失
build.yaml / build (push) Successful in 46s
2026-10-27 18:25:56 +08:00
xiaoqidun bc71750c78 feat(体验提升): 优化注解加载与侧栏切换 2026-10-27 18:17:42 +08:00
+30 -14
View File
@@ -10711,6 +10711,7 @@ function focusSearch() {
} }
function showNavigation(selected) { function showNavigation(selected) {
if (selected !== el.annotationsTab) cancelAnnotationSummary(documentTab());
const scrollTop = el.navigationContent.scrollTop; const scrollTop = el.navigationContent.scrollTop;
for (const [tab, panel] of [[el.pagesTab, el.pageList], [el.outlinesTab, el.outlineList], [el.annotationsTab, el.annotationsPanel], [el.searchTab, el.searchPanel]]) { for (const [tab, panel] of [[el.pagesTab, el.pageList], [el.outlinesTab, el.outlineList], [el.annotationsTab, el.annotationsPanel], [el.searchTab, el.searchPanel]]) {
if (tab.getAttribute("data-selected") === "true") { if (tab.getAttribute("data-selected") === "true") {
@@ -10727,28 +10728,35 @@ function showNavigation(selected) {
if (selected === el.annotationsTab) loadAnnotationSummary(); if (selected === el.annotationsTab) loadAnnotationSummary();
} }
function cancelAnnotationSummary(tab) {
for (const [id, request] of wasmRequests) {
if (request.tab === tab && request.name === "ofdgoAnnotationInfos" && !request.canceled) {
tab.state.annotationSummary = null;
cancelOperation(id);
}
}
}
async function loadAnnotationSummary() { async function loadAnnotationSummary() {
const tab = documentTab(), state = tab.state;
if (!state.doc || !state.ready) return; if (!state.doc || !state.ready) return;
const seq = state.openSeq; const seq = state.openSeq;
if (state.annotationSummary?.seq === seq) { renderAnnotationSummary(); return; } if (state.annotationSummary?.seq === seq) { renderAnnotationSummary(true); return; }
cancelAnnotationSummary(tab);
const summary = {seq, items: [], loading: true}; const summary = {seq, items: [], loading: true};
state.annotationSummary = summary; state.annotationSummary = summary;
el.annotationsList.replaceChildren(); el.annotationsList.replaceChildren();
el.annotationsStatus.textContent = "正在读取注解"; el.annotationsStatus.textContent = "正在读取注解";
try { try {
const items = await callWASM("ofdgoAnnotationInfos"); const items = await callTabWASM(tab, "ofdgoAnnotationInfos");
if (seq !== state.openSeq || state.annotationSummary !== summary) return; if (tab.closed || seq !== state.openSeq || state.annotationSummary !== summary) return;
summary.items = items || []; summary.items = items || [];
const labels = {Path: "批注", Highlight: "高亮", Stamp: "印章", Watermark: "水印", Link: "链接"};
const kind = el.annotationsKind.value;
el.annotationsKind.replaceChildren(new Option("全部", ""), ...[...new Set(summary.items.map(annotationKind))].map(type => new Option(labels[type] || type, type)));
el.annotationsKind.value = [...el.annotationsKind.options].some(option => option.value === kind) ? kind : "";
summary.loading = false; summary.loading = false;
renderAnnotationSummary(); if (isForegroundDocument(tab)) renderAnnotationSummary(true);
} catch (error) { } catch (error) {
if (seq === state.openSeq && state.annotationSummary === summary) { if (seq === state.openSeq && state.annotationSummary === summary) {
state.annotationSummary = null; state.annotationSummary = null;
el.annotationsStatus.textContent = error.message; if (isForegroundDocument(tab)) el.annotationsStatus.textContent = error.name === "AbortError" ? "" : error.message;
} }
} }
} }
@@ -10757,12 +10765,17 @@ function annotationKind(annotation) {
return annotation.type === "Path" && annotation.subtype === "Link" ? "Link" : annotation.type; return annotation.type === "Path" && annotation.subtype === "Link" ? "Link" : annotation.type;
} }
function renderAnnotationSummary() { function renderAnnotationSummary(reset = false) {
const summary = state.annotationSummary; const summary = state.annotationSummary;
if (!summary || summary.loading || summary.seq !== state.openSeq) return; if (!summary || summary.loading || summary.seq !== state.openSeq) return;
const labels = {Path: "批注", Highlight: "高亮", Stamp: "印章", Watermark: "水印", Link: "链接"};
if (reset) {
const previousKind = el.annotationsKind.value;
el.annotationsKind.replaceChildren(new Option("全部", ""), ...[...new Set(summary.items.map(annotationKind))].map(type => new Option(labels[type] || type, type)));
el.annotationsKind.value = [...el.annotationsKind.options].some(option => option.value === previousKind) ? previousKind : "";
}
const query = el.annotationsFilter.value.trim().toLocaleLowerCase(); const query = el.annotationsFilter.value.trim().toLocaleLowerCase();
const kind = el.annotationsKind.value; const kind = el.annotationsKind.value;
const labels = {Path: "批注", Highlight: "高亮", Stamp: "印章", Watermark: "水印", Link: "链接"};
const items = summary.items.filter(item => (!kind || annotationKind(item) === kind) && `${item.remark || ""}\n${item.creator || ""}\n${item.id}`.toLocaleLowerCase().includes(query)); const items = summary.items.filter(item => (!kind || annotationKind(item) === kind) && `${item.remark || ""}\n${item.creator || ""}\n${item.id}`.toLocaleLowerCase().includes(query));
el.annotationsStatus.textContent = summary.items.length ? `${items.length} / ${summary.items.length}` : ""; el.annotationsStatus.textContent = summary.items.length ? `${items.length} / ${summary.items.length}` : "";
el.annotationsList.replaceChildren(...items.map(item => { el.annotationsList.replaceChildren(...items.map(item => {
@@ -12504,10 +12517,11 @@ function operationProgress(request, progress) {
const text = request.name.includes("Print") ? "正在准备打印" : request.name === "ofdgoEditDocument" ? "正在准备编辑" : request.name.includes("Save") ? "正在准备保存" : request.name.includes("Export") ? "正在准备导出" : "正在准备文档"; const text = request.name.includes("Print") ? "正在准备打印" : request.name === "ofdgoEditDocument" ? "正在准备编辑" : request.name.includes("Save") ? "正在准备保存" : request.name.includes("Export") ? "正在准备导出" : "正在准备文档";
const completed = progress?.phase === "convert" && progress.total > 0; const completed = progress?.phase === "convert" && progress.total > 0;
const label = completed ? `${text} · ${progress.completed} / ${progress.total} 页` : text; const label = completed ? `${text} · ${progress.completed} / ${progress.total} 页` : text;
request.progress = {text:label, percent:completed ? progress.completed / progress.total * 100 : null};
if (request.name.includes("Print")) { if (request.name.includes("Print")) {
if (request.tab.print?.context) request.tab.print.status(label, true); if (request.tab.print?.context) request.tab.print.status(label, true);
} else if (operationRequest(request.tab) === request) { } else if (operationRequest(request.tab) === request) {
request.tab.progress = {text:label, percent:completed ? progress.completed / progress.total * 100 : null}; request.tab.progress = request.progress;
if (isForegroundDocument(request.tab)) setProgress(label, request.tab.progress.percent); if (isForegroundDocument(request.tab)) setProgress(label, request.tab.progress.percent);
} }
} }
@@ -12629,7 +12643,9 @@ function showError(err, empty = !state.doc) {
} }
function setBusy(busy, text = "", percent = 0, status = "", tab = documentTab()) { function setBusy(busy, text = "", percent = 0, status = "", tab = documentTab()) {
busy ||= Boolean(tab.editTask || operationRequest(tab)); const operation = operationRequest(tab);
busy ||= Boolean(tab.editTask || operation);
if (operation?.preparing && operation.progress) ({text, percent} = operation.progress);
const resumeSearch = tab.busy && !busy && tab.state.searchPaused; const resumeSearch = tab.busy && !busy && tab.state.searchPaused;
tab.busy = busy; tab.busy = busy;
if (text) tab.progress = {text, percent}; if (text) tab.progress = {text, percent};
@@ -12666,7 +12682,7 @@ function setBusy(busy, text = "", percent = 0, status = "", tab = documentTab())
el.outlineForm.inert = busy; el.outlineForm.inert = busy;
el.structureForm.inert = busy; el.structureForm.inert = busy;
el.outlineList.inert = busy; el.outlineList.inert = busy;
el.navigationTabs.inert = busy; el.navigationTabs.inert = busy && !(tab.preparationBusy && operation?.preparing && operation.name === "ofdgoAnnotationInfos");
el.pageList.inert = busy; el.pageList.inert = busy;
el.editorTools.inert = busy || Boolean(sealPreview || resourceManager.pick); el.editorTools.inert = busy || Boolean(sealPreview || resourceManager.pick);
el.fontList.inert = busy; el.fontList.inert = busy;