Skip to content

Commit 213e625

Browse files
committed
feat(PdfReader): add OnRotationChanged parameter
1 parent 56d3cbd commit 213e625

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public partial class PdfReader
5656
public uint CurrentPage { get; set; }
5757

5858
/// <summary>
59-
/// 获得/设置 当前缩放倍率 默认 null 使用 100%
59+
/// 获得/设置 当前旋转角度 默认 0 数值范围 0 90 180 270
6060
/// </summary>
6161
[Parameter]
62-
public string? CurrentScale { get; set; }
62+
public int CurrentRotation { get; set; }
6363

6464
/// <summary>
6565
/// 获得/设置 是否适配当前页面宽度 默认 false
@@ -109,6 +109,12 @@ public partial class PdfReader
109109
[Parameter]
110110
public Func<float, Task>? OnScaleChangedAsync { get; set; }
111111

112+
/// <summary>
113+
/// 页面旋转回调方法
114+
/// </summary>
115+
[Parameter]
116+
public Func<int, Task>? OnRotationChanged { get; set; }
117+
112118
/// <summary>
113119
/// 获得/设置 更多按钮图标 默认为 null 使用内置图标
114120
/// </summary>
@@ -142,6 +148,7 @@ public partial class PdfReader
142148

143149
private string? _docTitle;
144150
private uint _currentPage;
151+
private float _currentRotation;
145152
private string? _url;
146153
private string? _dropdownItemCheckIcon;
147154
private string? _dropdownItemDefaultIcon;
@@ -195,6 +202,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
195202
_currentPage = CurrentPage;
196203
await NavigateToPageAsync(_currentPage);
197204
}
205+
if (_currentRotation != CurrentRotation)
206+
{
207+
_currentRotation = CurrentRotation;
208+
await InvokeVoidAsync("rotate", Id, _currentRotation);
209+
}
198210
if (_showToolbar != ShowToolbar)
199211
{
200212
_showToolbar = ShowToolbar;
@@ -232,7 +244,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
232244
TriggerPagesLoaded = OnPagesLoadedAsync != null,
233245
TriggerPageChanged = OnPageChangedAsync != null,
234246
TriggerTowPagesOnViewChanged = OnTwoPagesOneViewAsync != null,
235-
TriggerScaleChanged = OnScaleChangedAsync != null
247+
TriggerScaleChanged = OnScaleChangedAsync != null,
248+
TriggerRotationChanged = OnRotationChanged != null,
236249
});
237250

238251
/// <summary>
@@ -334,4 +347,18 @@ public async Task Printing()
334347
await OnPrintingAsync();
335348
}
336349
}
350+
351+
/// <summary>
352+
/// 页面旋转回调方法
353+
/// </summary>
354+
/// <param name="angle"></param>
355+
/// <returns></returns>
356+
[JSInvokable]
357+
public async Task RotationChanged(int angle)
358+
{
359+
if (OnRotationChanged != null)
360+
{
361+
await OnRotationChanged(angle);
362+
}
363+
}
337364
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,15 @@ const addEventBus = (el, pdfViewer, eventBus, invoke, options) => {
357357
}
358358
})
359359

360-
eventBus.on("rotationchanging", evt => {
360+
eventBus.on("rotationchanging", async evt => {
361361
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
362362
if (thumbnailsContainer) {
363363
thumbnailsContainer.style.setProperty('--thumb-rotate', `${evt.pagesRotation}deg`);
364364
}
365+
366+
if (options.triggerRotationChanged) {
367+
await invoke.invokeMethodAsync("RotationChanged", evt.pagesRotation);
368+
}
365369
})
366370
}
367371

0 commit comments

Comments
 (0)