Skip to content

Commit aab6e2f

Browse files
committed
feat: 支持缩略图响应页码变化
1 parent 5557e16 commit aab6e2f

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,26 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
150150

151151
const item = document.createElement("div");
152152
item.classList.add("bb-view-thumbnail-item");
153+
if (pdfViewer.currentPageNumber === i + 1) {
154+
item.classList.add("active");
155+
}
156+
item.setAttribute("data-bb-page", i + 1)
153157
item.appendChild(img);
154158
thumbnailsContainer.appendChild(item);
155159
});
160+
161+
EventHandler.on(thumbnailsContainer, "click", ".bb-view-thumbnail-item", e => {
162+
const active = thumbnailsContainer.querySelector('.active');
163+
if (active) {
164+
active.classList.remove('active');
165+
}
166+
167+
const item = e.delegateTarget;
168+
item.classList.add("active");
169+
170+
const index = parseInt(item.getAttribute("data-bb-page")) || 1;
171+
pdfViewer.currentPageNumber = index;
172+
})
156173
}
157174

158175
if (options.triggerPagesLoaded === true) {
@@ -167,6 +184,18 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
167184
pageNumberEl.value = page;
168185
}
169186

187+
if (options.enableThumbnails) {
188+
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
189+
if (thumbnailsContainer) {
190+
const active = thumbnailsContainer.querySelector('.active');
191+
active.classList.remove('active');
192+
193+
const item = thumbnailsContainer.querySelector(`[data-bb-page='${page}']`);
194+
item.classList.add("active");
195+
item.scrollIntoView({ behavior: 'smooth', block: "nearest", inline: "start" });
196+
}
197+
}
198+
170199
if (options.triggerPageChanged === true) {
171200
await invoke.invokeMethodAsync("pageChanged", page);
172201
}
@@ -259,8 +288,13 @@ export function dispose(id) {
259288
}
260289

261290
const thumbnailsToggle = el.querySelector(".bb-view-bar");
262-
if(thumbnailsToggle) {
291+
if (thumbnailsToggle) {
263292
EventHandler.off(thumbnailsToggle, "click");
264293
}
294+
295+
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
296+
if (thumbnailsContainer) {
297+
EventHandler.off(thumbnailsContainer, "click");
298+
}
265299
}
266300
}

0 commit comments

Comments
 (0)