Skip to content

Commit 6864e63

Browse files
committed
refactor: 旋转方法移动到客户端
1 parent 92f05e8 commit 6864e63

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageHeight)">@Localizer["FitHeight"]</div>
3939
</div>
4040
</div>
41-
<div class="bb-view-icon bb-view-fit-rotate" title="@Localizer["RotateLeft"]" @onclick="RotateLeft"><i class="fa-solid fa-fw fa-rotate-left"></i></div>
42-
<div class="bb-view-icon bb-view-fit-rotate" title="@Localizer["RotateRight"]" @onclick="RotateRight"><i class="fa-solid fa-fw fa-rotate-right"></i></div>
41+
<div class="bb-view-icon bb-view-rotate-left" title="@Localizer["RotateLeft"]"><i class="fa-solid fa-fw fa-rotate-left"></i></div>
42+
<div class="bb-view-icon bb-view-rotate-right" title="@Localizer["RotateRight"]"><i class="fa-solid fa-fw fa-rotate-right"></i></div>
4343
</div>
4444
</div>
4545
<div class="bb-view-group bb-view-controls">

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

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ export function setScaleValue(id, value) {
3636
export function rotate(id, step) {
3737
const { pdfViewer } = Data.get(id);
3838
if (pdfViewer) {
39-
let rotate = pdfViewer.pagesRotation || 360;
40-
rotate += step;
41-
pdfViewer.pagesRotation = rotate % 360;
39+
rotateView(pdfViewer, step);
4240
}
4341
}
4442

43+
const rotateView = (pdfViewer, step) => {
44+
let rotate = pdfViewer.pagesRotation || 360;
45+
rotate += step;
46+
pdfViewer.pagesRotation = rotate % 360;
47+
}
48+
4549
export function navigateToPage(id, pageNumber) {
4650
const { pdfViewer } = Data.get(id);
4751
if (pdfViewer) {
@@ -252,6 +256,19 @@ const addEventBus = (el, pdfViewer, eventBus, invoke, options) => {
252256

253257
const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
254258
const toolbar = el.querySelector(".bb-view-toolbar");
259+
260+
EventHandler.on(toolbar, "click", '.bb-view-bar', e => {
261+
const thumbnailsEl = el.querySelector(".bb-view-thumbnails");
262+
thumbnailsEl.classList.toggle("show");
263+
});
264+
EventHandler.on(toolbar, "click", '.bb-page-minus', e => updateScale(pdfViewer, e.delegateTarget, -1));
265+
EventHandler.on(toolbar, "click", '.bb-page-plus', e => updateScale(pdfViewer, e.delegateTarget, 1));
266+
EventHandler.on(toolbar, 'click', '.bb-view-rotate-left', e => {
267+
rotateView(pdfViewer, -90);
268+
});
269+
EventHandler.on(toolbar, 'click', '.bb-view-rotate-right', e => {
270+
rotateView(pdfViewer, 90);
271+
});
255272
EventHandler.on(toolbar, "click", ".bb-view-print", async e => {
256273
printPdf(options.url);
257274
await invoke.invokeMethodAsync("Printing");
@@ -276,13 +293,6 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
276293
// el.requestFullscreen();
277294
//}
278295
});
279-
280-
EventHandler.on(toolbar, "click", '.bb-page-minus', e => updateScale(pdfViewer, e.delegateTarget, -1));
281-
EventHandler.on(toolbar, "click", '.bb-page-plus', e => updateScale(pdfViewer, e.delegateTarget, 1));
282-
EventHandler.on(toolbar, "click", '.bb-view-bar', e => {
283-
const thumbnailsEl = el.querySelector(".bb-view-thumbnails");
284-
thumbnailsEl.classList.toggle("show");
285-
});
286296
}
287297

288298
const resetThumbnailsView = (el, pdfViewer) => {
@@ -378,10 +388,6 @@ const printPdf = url => {
378388
iframe.src = url;
379389

380390
iframe.onload = () => {
381-
iframe.contentWindow.addEventListener('afterprint', function () {
382-
document.body.removeChild(iframe);
383-
});
384-
385391
iframe.contentWindow.focus();
386392
iframe.contentWindow.print();
387393
};
@@ -399,33 +405,21 @@ export function dispose(id) {
399405
}
400406

401407
if (el) {
402-
const minus = el.querySelector(".bb-page-minus");
403-
const plus = el.querySelector(".bb-page-plus");
404-
if (minus) {
405-
EventHandler.off(minus, "click");
406-
}
407-
if (plus) {
408-
EventHandler.off(plus, "click");
409-
}
410-
411408
const towPagesOneView = el.querySelector(".dropdown-item-pages");
412409
if (towPagesOneView) {
413410
EventHandler.off(towPagesOneView, "click");
414411
}
415412

416-
const titleEl = el.querySelector(".bb-view-title");
417-
if (titleEl) {
418-
EventHandler.off(titleEl, "click");
413+
const toolbar = el.querySelector(".bb-view-toolbar");
414+
if (toolbar) {
415+
EventHandler.off(toolbar, "click");
419416
}
420417

421418
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
422419
if (thumbnailsContainer) {
423420
EventHandler.off(thumbnailsContainer, "click");
424421
}
425422

426-
const controls = el.querySelector(".bb-view-controls");
427-
EventHandler.off(controls, "click");
428-
429423
const iframe = document.querySelector('.bb-view-print-iframe');
430424
if (iframe) {
431425
iframe.remove();

0 commit comments

Comments
 (0)