Skip to content

Commit 3715d31

Browse files
authored
feat(PdfReader): support download (#773)
* refactor: 移除代码 * refactor: 内置下载 * feat: 移除 Download 回调方法 * feat(PdfReader): support download
1 parent 4cb96db commit 3715d31

4 files changed

Lines changed: 13 additions & 18 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.10</Version>
4+
<Version>10.0.11</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<div class="bb-view-group bb-view-controls invisible">
4646
@if (ShowDownload)
4747
{
48-
<div class="bb-view-icon bb-view-download" title="@Localizer["Download"]" @onclick="OnDownload"><i class="fa-solid fa-fw fa-arrow-right-to-bracket fa-rotate-90"></i></div>
48+
<div class="bb-view-icon bb-view-download" title="@Localizer["Download"]"><i class="fa-solid fa-fw fa-arrow-right-to-bracket fa-rotate-90"></i></div>
4949
}
5050
@if (ShowPrint)
5151
{

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ public partial class PdfReader
121121
[Parameter]
122122
public string? MoreButtonIcon { get; set; }
123123

124-
/// <summary>
125-
/// 点击下载按钮回调方法 默认 null
126-
/// </summary>
127-
[Parameter]
128-
public Func<Task>? OnDownloadAsync { get; set; }
129-
130124
/// <summary>
131125
/// 正在打印回调方法 默认 null
132126
/// </summary>
@@ -272,14 +266,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
272266
/// <returns></returns>
273267
public Task RotateRight() => InvokeVoidAsync("rotate", Id, 90);
274268

275-
private async Task OnDownload()
276-
{
277-
if (OnDownloadAsync != null)
278-
{
279-
await OnDownloadAsync();
280-
}
281-
}
282-
283269
/// <summary>
284270
/// 页面开始初始化时回调方法
285271
/// </summary>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ const loadPdf = async (el, invoke, options) => {
109109
}
110110

111111
const loadMetadata = (el, pdfViewer, metadata) => {
112-
console.log(metadata);
113-
114112
const filename = el.querySelector('.bb-view-pdf-dialog-filename');
115113
const docTitle = el.querySelector('.bb-view-subject');
116114
filename.textContent = docTitle.textContent;
@@ -439,6 +437,17 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
439437
pdfViewer.spreadMode = 0;
440438
}
441439
});
440+
EventHandler.on(toolbar, "click", ".bb-view-download", e => {
441+
if (options.url) {
442+
const docTitle = el.querySelector('.bb-view-subject');
443+
const anchorElement = document.createElement('a');
444+
anchorElement.href = options.url;
445+
anchorElement.download = docTitle.textContent;
446+
anchorElement.click();
447+
anchorElement.remove();
448+
}
449+
});
450+
442451
EventHandler.on(toolbar, "click", ".dropdown-item-presentation", async e => {
443452
e.delegateTarget.classList.toggle("active");
444453

0 commit comments

Comments
 (0)