Skip to content

Commit 2010373

Browse files
authored
feat(PdfReader): add ResetToolbarView function (#749)
* refactor: 移除 sidebar 样式 * refactor: 移除 dialog 样式 * refactor: 移除不使用的枚举 * refactor: 更改方法名称为 initEventBus * refactor: 工具栏按钮事件统一到 toolbar 元素 * refactor: 旋转方法移动到客户端 * feat: 移动工具栏按钮逻辑到客户端 * feat: 工具栏缩放功能下沉到客户端 * refactor: 增加重置工具栏逻辑 * chore: bump version 10.0.5 * refactor: 增加双页视图状态保持逻辑 * feat: 增加页码获得焦点逻辑 * chore: bump version 10.0.5
1 parent 3d5f991 commit 2010373

8 files changed

Lines changed: 267 additions & 1441 deletions

File tree

src/components/BootstrapBlazor.PdfReader/BootstrapBlazor.PdfReader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.0.4</Version>
4+
<Version>10.0.6</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.PdfReader/EnumPageMode.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/BootstrapBlazor.PdfReader/EnumZoomMode.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@
33
@inherits BootstrapModuleComponentBase
44

55
<div @attributes="@AdditionalAttributes" id="@Id" class="@ClassString" style="@StyleString">
6-
@if (ShowToolbar)
7-
{
8-
<div class="bb-view-toolbar">
6+
<div class="bb-view-toolbar">
7+
@if (ShowToolbar)
8+
{
99
<div class="bb-view-group bb-view-title">
1010
@if (EnableThumbnails)
1111
{
1212
<div class="bb-view-icon bb-view-bar" title="@Localizer["ToggleSidebar"]"><i class="fa-solid fa-bars"></i></div>
1313
}
1414
<span class="bb-view-subject">@_docTitle</span>
1515
</div>
16-
<div class="@ViewBodyString">
16+
<div class="bb-view-group bb-view-toolbar-main">
1717
<div class="bb-view-group bb-view-group-page">
18-
<input type="text" class="bb-view-num" @bind="CurrentPageString" /><span class="bb-view-slash">/</span>
18+
<input type="text" class="bb-view-num" value="1" /><span class="bb-view-slash">/</span>
1919
<div class="bb-view-pagesCount"></div>
2020
</div>
2121
<div class="bb-view-group bb-view-group-scale">
2222
<div class="bb-view-divider"></div>
2323
<div class="bb-view-icon bb-page-minus" title="@Localizer["ZoomOut"]"><i class="fa-solid fa-fw fa-minus"></i></div>
24-
<input type="text" class="bb-view-scale-input" @bind="CurrentScaleString" />
24+
<input type="text" class="bb-view-scale-input" value="100%" />
2525
<div class="bb-view-icon bb-page-plus" title="@Localizer["ZoomIn"]"><i class="fa-solid fa-fw fa-plus"></i></div>
2626
</div>
2727
<div class="bb-view-group bb-view-group-rotate">
2828
<div class="bb-view-divider"></div>
2929
<div class="bb-view-icon btn-group">
30-
<button type="button" class="btn bb-view-fit-height" title="@Localizer["FitHeight"]" @onclick="() => SetFitMode(PdfReaderFitMode.PageHeight)"><i class="fa-solid fa-fw fa-arrows-left-right-to-line fa-rotate-90"></i></button>
31-
<button type="button" class="btn bb-view-fit-width" title="@Localizer["FitWidth"]" @onclick="() => SetFitMode(PdfReaderFitMode.PageWidth)"><i class="fa-solid fa-fw fa-arrows-left-right-to-line"></i></button>
30+
<button type="button" class="btn bb-view-fit-height" title="@Localizer["FitHeight"]"><i class="fa-solid fa-fw fa-arrows-left-right-to-line fa-rotate-90"></i></button>
31+
<button type="button" class="btn bb-view-fit-width" title="@Localizer["FitWidth"]"><i class="fa-solid fa-fw fa-arrows-left-right-to-line"></i></button>
3232
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
3333
<span class="visually-hidden">Toggle Dropdown</span>
3434
</button>
3535
<div class="dropdown-menu dropdown-menu-end shadow">
36-
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageActual)">@Localizer["PageActual"]</div>
37-
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageWidth)">@Localizer["FitWidth"]</div>
38-
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageHeight)">@Localizer["FitHeight"]</div>
36+
<div class="dropdown-item bb-view-page-actual">@Localizer["PageActual"]</div>
37+
<div class="dropdown-item bb-view-fit-width">@Localizer["FitWidth"]</div>
38+
<div class="dropdown-item bb-view-fit-height">@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">
@@ -83,8 +83,8 @@
8383
</div>
8484
</div>
8585
</div>
86-
</div>
87-
}
86+
}
87+
</div>
8888
<div class="bb-view-main">
8989
@if (EnableThumbnails)
9090
{

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

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using Microsoft.AspNetCore.Components;
66
using Microsoft.Extensions.Localization;
7-
using System.Globalization;
87

98
namespace BootstrapBlazor.Components;
109

@@ -135,57 +134,13 @@ public partial class PdfReader
135134
.AddClassFromAttributes(AdditionalAttributes)
136135
.Build();
137136

138-
private string? ViewBodyString => CssBuilder.Default("bb-view-group bb-view-toolbar-main")
139-
.AddClass("fit-width", FitMode == PdfReaderFitMode.PageHeight)
140-
.Build();
141-
142137
private string? _docTitle;
143-
private PdfReaderFitMode _fitMode;
144138
private uint _currentPage;
145139
private string? _url;
146-
private string? _currentScale;
147140
private string? _dropdownItemCheckIcon;
148141
private string? _dropdownItemDefaultIcon;
149142
private bool _enableThumbnails = true;
150-
151-
private string CurrentPageString
152-
{
153-
get => CurrentPage.ToString(CultureInfo.InvariantCulture);
154-
set => SetCurrentPage(value);
155-
}
156-
157-
private void SetCurrentPage(string value)
158-
{
159-
if (uint.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var num))
160-
{
161-
CurrentPage = num;
162-
}
163-
}
164-
165-
private string CurrentScaleString
166-
{
167-
get => $"{CurrentScale ?? "100"}%";
168-
set => SetCurrentScale(value);
169-
}
170-
171-
private void SetCurrentScale(string value)
172-
{
173-
if (string.IsNullOrEmpty(value))
174-
{
175-
CurrentScale = "100";
176-
}
177-
else if (float.TryParse(value.TrimEnd("%"), out var v))
178-
{
179-
v = v switch
180-
{
181-
> 500 => 500,
182-
< 25 => 25,
183-
_ => v
184-
};
185-
186-
CurrentScale = v.ToString(CultureInfo.InvariantCulture);
187-
}
188-
}
143+
private bool _showToolbar = true;
189144

190145
/// <summary>
191146
/// <inheritdoc/>
@@ -216,33 +171,29 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
216171

217172
if (firstRender)
218173
{
219-
_fitMode = FitMode;
220-
_currentPage = CurrentPage;
221174
_url = Url;
222-
_currentScale = CurrentScale;
175+
_currentPage = CurrentPage;
223176
_enableThumbnails = EnableThumbnails;
177+
_showToolbar = ShowToolbar;
224178
}
225179

226180
if (_url != Url)
227181
{
228182
_url = Url;
229183
await InvokeInitAsync();
230184
}
231-
232-
if (_fitMode != FitMode)
233-
{
234-
_fitMode = FitMode;
235-
await InvokeVoidAsync("setScaleValue", Id, _fitMode.ToDescriptionString());
236-
}
237185
if (_currentPage != CurrentPage)
238186
{
239187
_currentPage = CurrentPage;
240188
await NavigateToPageAsync(_currentPage);
241189
}
242-
if (_currentScale != CurrentScale)
190+
if (_showToolbar != ShowToolbar)
243191
{
244-
_currentScale = CurrentScale;
245-
await InvokeVoidAsync("scale", Id, _currentScale);
192+
_showToolbar = ShowToolbar;
193+
if (_showToolbar)
194+
{
195+
await InvokeVoidAsync("resetToolbar", Id);
196+
}
246197
}
247198
if (_enableThumbnails != EnableThumbnails)
248199
{
@@ -263,6 +214,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
263214
Url,
264215
FitMode,
265216
EnableThumbnails,
217+
CurrentPage,
266218
TriggerPagesInit = OnPagesInitAsync != null,
267219
TriggerPagesLoaded = OnPagesLoadedAsync != null,
268220
TriggerPageChanged = OnPageChangedAsync != null,
@@ -277,27 +229,21 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
277229
public Task NavigateToPageAsync(uint pageNumber) => InvokeVoidAsync("navigateToPage", Id, pageNumber);
278230

279231
/// <summary>
280-
/// 适应页面宽度
232+
/// 设置页面适配模式方法
281233
/// </summary>
282-
public void SetFitMode(PdfReaderFitMode mode) => FitMode = mode;
234+
public Task SetFitMode(PdfReaderFitMode mode) => InvokeVoidAsync("setScaleValue", Id, mode.ToDescriptionString());
283235

284236
/// <summary>
285237
/// 旋转页面方法
286238
/// </summary>
287239
/// <returns></returns>
288-
public async Task RotateLeft()
289-
{
290-
await InvokeVoidAsync("rotate", Id, -90);
291-
}
240+
public Task RotateLeft() => InvokeVoidAsync("rotate", Id, -90);
292241

293242
/// <summary>
294243
/// 旋转页面方法
295244
/// </summary>
296245
/// <returns></returns>
297-
public async Task RotateRight()
298-
{
299-
await InvokeVoidAsync("rotate", Id, 90);
300-
}
246+
public Task RotateRight() => InvokeVoidAsync("rotate", Id, 90);
301247

302248
private async Task OnDownload()
303249
{

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@
7979
width: 1%;
8080
}
8181

82-
.bb-view-toolbar-main.fit-width .bb-view-fit-height {
82+
.bb-view-toolbar-main .fit-height .bb-view-fit-height {
8383
display: none;
8484
}
8585

86-
.bb-view-toolbar-main.fit-width .bb-view-fit-width {
86+
.bb-view-toolbar-main .fit-height .bb-view-fit-width {
8787
display: block;
8888
}
8989

0 commit comments

Comments
 (0)