feat(前端界面): 优化OFDGo WebUI适宽适高
build.yaml / build (push) Successful in 37s

This commit is contained in:
2026-07-07 14:07:30 +08:00
parent f1d1f5ed2d
commit 749c71502e
2 changed files with 13 additions and 11 deletions
+10 -5
View File
@@ -17,8 +17,6 @@ const COMMON_FONT_NAMES = [
"Times New Roman",
];
const LOCAL_FONT_LOAD_LIMIT = 16;
const FIT_WIDTH_MARGIN = 72;
const FIT_HEIGHT_MARGIN = 86;
const COMPACT_LAYOUT = window.matchMedia("(max-width: 900px)");
const STATUS = {
ready: "选择 OFD 文件",
@@ -1127,7 +1125,7 @@ function pageShell(index) {
function scrollToPage(index) {
const shell = pageShell(index);
if (shell) {
shell.scrollIntoView({ block: "start", inline: "nearest" });
shell.scrollIntoView({ block: state.fitMode === "height" ? "center" : "start", inline: "nearest" });
}
}
@@ -1542,7 +1540,7 @@ function fitWidth(updateStatus = true) {
return;
}
state.fitMode = "width";
const available = Math.max(280, el.pageFrame.clientWidth - FIT_WIDTH_MARGIN);
const available = Math.max(280, el.pageFrame.clientWidth - pageSpace() * 2);
const width = Math.max(1, page.width * MM_TO_PX);
setScale(available / width, updateStatus, "width");
}
@@ -1553,9 +1551,12 @@ function fitHeight(updateStatus = true) {
return;
}
state.fitMode = "height";
const available = Math.max(220, el.viewerPanel.clientHeight - FIT_HEIGHT_MARGIN);
const available = Math.max(220, el.viewerPanel.clientHeight - pageSpace() * 2);
const height = Math.max(1, page.height * MM_TO_PX);
setScale(available / height, updateStatus, "height");
if (updateStatus) {
scrollToPage(state.pageIndex);
}
}
function applyFit(updateStatus = true) {
@@ -1583,6 +1584,10 @@ function currentPageInfo() {
return state.doc?.pages?.[state.pageIndex] || null;
}
function pageSpace() {
return Number.parseFloat(getComputedStyle(el.pageFrame).paddingTop) || 0;
}
function updateControls() {
const hasDoc = Boolean(state.doc);
const pageCount = state.doc ? state.doc.pageCount : 0;