Skip to content

Commit 3e03904

Browse files
committed
wip: 临时提交
# Conflicts: # BootstrapBlazor.Extensions.sln
1 parent c0b16b4 commit 3e03904

7 files changed

Lines changed: 191 additions & 0 deletions

File tree

BootstrapBlazor.Extensions.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.PdfViewer",
192192
EndProject
193193
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.Vditor", "src\components\BootstrapBlazor.Vditor\BootstrapBlazor.Vditor.csproj", "{D417E1B9-D146-4983-81D0-79F3193B322B}"
194194
EndProject
195+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.TouchSocket", "src\extensions\BootstrapBlazor.TouchSocket\BootstrapBlazor.TouchSocket.csproj", "{FD23CEA1-78EB-85D7-8EDF-047657355B52}"
196+
EndProject
197+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.OfficeDocumentViewer", "src\components\BootstrapBlazor.OfficeDocumentViewer\BootstrapBlazor.OfficeDocumentViewer.csproj", "{B2B4B85C-06AE-411C-8E29-C9A4AF473548}"
198+
EndProject
195199
Global
196200
GlobalSection(SolutionConfigurationPlatforms) = preSolution
197201
Debug|Any CPU = Debug|Any CPU
@@ -522,6 +526,14 @@ Global
522526
{D417E1B9-D146-4983-81D0-79F3193B322B}.Debug|Any CPU.Build.0 = Debug|Any CPU
523527
{D417E1B9-D146-4983-81D0-79F3193B322B}.Release|Any CPU.ActiveCfg = Release|Any CPU
524528
{D417E1B9-D146-4983-81D0-79F3193B322B}.Release|Any CPU.Build.0 = Release|Any CPU
529+
{FD23CEA1-78EB-85D7-8EDF-047657355B52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
530+
{FD23CEA1-78EB-85D7-8EDF-047657355B52}.Debug|Any CPU.Build.0 = Debug|Any CPU
531+
{FD23CEA1-78EB-85D7-8EDF-047657355B52}.Release|Any CPU.ActiveCfg = Release|Any CPU
532+
{FD23CEA1-78EB-85D7-8EDF-047657355B52}.Release|Any CPU.Build.0 = Release|Any CPU
533+
{B2B4B85C-06AE-411C-8E29-C9A4AF473548}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
534+
{B2B4B85C-06AE-411C-8E29-C9A4AF473548}.Debug|Any CPU.Build.0 = Debug|Any CPU
535+
{B2B4B85C-06AE-411C-8E29-C9A4AF473548}.Release|Any CPU.ActiveCfg = Release|Any CPU
536+
{B2B4B85C-06AE-411C-8E29-C9A4AF473548}.Release|Any CPU.Build.0 = Release|Any CPU
525537
EndGlobalSection
526538
GlobalSection(SolutionProperties) = preSolution
527539
HideSolutionNode = FALSE
@@ -612,6 +624,8 @@ Global
612624
{08458CA3-BF81-48E8-870D-9389DC037808} = {FF1089BE-C704-4374-B629-C57C08E1798F}
613625
{4757B038-70E4-40B0-9B73-700EE5632B07} = {FF1089BE-C704-4374-B629-C57C08E1798F}
614626
{D417E1B9-D146-4983-81D0-79F3193B322B} = {FF1089BE-C704-4374-B629-C57C08E1798F}
627+
{FD23CEA1-78EB-85D7-8EDF-047657355B52} = {7B29E81D-92DE-46C8-8EDC-1B48C8F12BC2}
628+
{B2B4B85C-06AE-411C-8E29-C9A4AF473548} = {FF1089BE-C704-4374-B629-C57C08E1798F}
615629
EndGlobalSection
616630
GlobalSection(ExtensibilityGlobals) = postSolution
617631
SolutionGuid = {D5EB1960-6F30-4CE1-B375-EAE1F787D6FF}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<Version>9.0.0</Version>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Office Viewer</PackageTags>
9+
<Description>Bootstrap UI components extensions of Microsoft Office Documentation Viewer</Description>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="BootstrapBlazor" Version="$(BBVersion)" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Using Include="BootstrapBlazor.Components" />
18+
<Using Include="Microsoft.JSInterop" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@namespace BootstrapBlazor.Components
2+
@inherits BootstrapModuleComponentBase
3+
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.OfficeDocumentViewer/OfficeDocumentViewer.razor.js", JSObjectReference = true, AutoInvokeDispose = false)]
4+
5+
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString" style="@StyleString"></div>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using Microsoft.AspNetCore.Components;
6+
7+
namespace BootstrapBlazor.Components;
8+
9+
public partial class OfficeDocumentViewer
10+
{
11+
/// <summary>
12+
/// Gets or sets the url for the PDF file to be displayed.
13+
/// </summary>
14+
[Parameter]
15+
public string? Url { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the viewer height. Default is null.
19+
/// </summary>
20+
[Parameter]
21+
public string? Height { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the document loaded event callback.
25+
/// </summary>
26+
[Parameter]
27+
public Func<Task>? OnLoaded { get; set; }
28+
29+
[Inject, NotNull]
30+
private NavigationManager? NavigationManager { get; set; }
31+
32+
private string? ClassString => CssBuilder.Default("bb-office-viewer-container")
33+
.AddClassFromAttributes(AdditionalAttributes)
34+
.Build();
35+
36+
private string? StyleString => CssBuilder.Default()
37+
.AddClass($"--bb-office-viewer-height: {Height};", !string.IsNullOrEmpty(Height))
38+
.Build();
39+
40+
private string? _url;
41+
42+
/// <summary>
43+
/// <inheritdoc/>
44+
/// </summary>
45+
/// <param name="firstRender"></param>
46+
/// <returns></returns>
47+
protected override async Task OnAfterRenderAsync(bool firstRender)
48+
{
49+
await base.OnAfterRenderAsync(firstRender);
50+
51+
if (firstRender)
52+
{
53+
_url = Url;
54+
return;
55+
}
56+
57+
var rerender = false;
58+
if (_url != Url)
59+
{
60+
_url = Url;
61+
rerender = true;
62+
}
63+
64+
if (rerender)
65+
{
66+
await InvokeVoidAsync("load", Id, GetAbsoluteUri(_url));
67+
}
68+
}
69+
70+
/// <summary>
71+
/// <inheritdoc/>
72+
/// </summary>
73+
/// <returns></returns>
74+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new
75+
{
76+
LoadedCallaback = nameof(TriggerOnLoaded),
77+
Url = GetAbsoluteUri(Url)
78+
});
79+
80+
private string GetAbsoluteUri(string? url)
81+
{
82+
url ??= string.Empty;
83+
if (string.IsNullOrEmpty(url))
84+
{
85+
return url;
86+
}
87+
var uri = NavigationManager.ToAbsoluteUri(url);
88+
return uri.AbsoluteUri;
89+
}
90+
91+
/// <summary>
92+
/// Trigger OnLoaded callback when the PDF document is loaded.
93+
/// </summary>
94+
/// <returns></returns>
95+
[JSInvokable]
96+
public async Task TriggerOnLoaded()
97+
{
98+
if (OnLoaded != null)
99+
{
100+
await OnLoaded();
101+
}
102+
}
103+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { addLink } from "../BootstrapBlazor/modules/utility.js"
2+
import Data from "../BootstrapBlazor/modules/data.js"
3+
4+
export async function init(id, invoke, options) {
5+
await addLink("./_content/BootstrapBlazor.OfficeDocumentViewer/office-viewer.css");
6+
7+
const el = document.getElementById(id);
8+
const officeViewer = { el, invoke, options };
9+
Data.set(id, officeViewer);
10+
11+
await load(id, options.url);
12+
}
13+
14+
export async function load(id, url) {
15+
const officeViewer = Data.get(id);
16+
const { el, invoke, options } = officeViewer;
17+
18+
el.innerHTML = '';
19+
20+
if (url) {
21+
const { frame } = officeViewer;
22+
const viewer = frame || createFrame(el);
23+
if (options.loadedCallaback) {
24+
viewer.onload = () => {
25+
invoke.invokeMethodAsync(options.loadedCallaback);
26+
};
27+
}
28+
viewer.src = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(url)}`;
29+
}
30+
}
31+
32+
const createFrame = el => {
33+
const frame = document.createElement('iframe');
34+
frame.classList.add('bb-office-viewer');
35+
el.appendChild(frame);
36+
return frame;
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@using BootstrapBlazor.Components;
2+
@using Microsoft.AspNetCore.Components.Web
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.bb-office-viewer-container {
2+
width: 100%;
3+
height: var(--bb-office-viewer-height, 500px);
4+
}
5+
6+
.bb-office-viewer {
7+
width: 100%;
8+
height: 100%;
9+
}

0 commit comments

Comments
 (0)