Skip to content

Commit 7a2fa79

Browse files
committed
doc: 增加在线协作示例
1 parent e7156e9 commit 7a2fa79

File tree

9 files changed

+173
-0
lines changed

9 files changed

+173
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@page "/OnlineSheet"
2+
<h3>OnlineSheet</h3>
3+
4+
@code {
5+
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
4+
5+
public partial class OnlineSheet : ComponentBase
6+
{
7+
}
8+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@namespace BootstrapBlazor.Server.Components.Samples.Tutorials
2+
3+
<div class="bb-contributor">
4+
<img src="@Contributor.Avatar" />
5+
<div class="bb-contributor-main">
6+
<div class="bb-contributor-item">
7+
<label>姓名:</label>
8+
<span>@Contributor.Name</span>
9+
</div>
10+
<div class="bb-contributor-item">
11+
<label>姓名:</label>
12+
<span>@Contributor.Description</span>
13+
</div>
14+
</div>
15+
</div>
16+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
7+
8+
/// <summary>
9+
/// Online sheet sample code
10+
/// </summary>
11+
public partial class OnlineContributor
12+
{
13+
/// <summary>
14+
/// Gets or sets Contributor
15+
/// </summary>
16+
[Parameter]
17+
[NotNull]
18+
public Contributor? Contributor { get; set; }
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.bb-contributor {
2+
display: flex;
3+
flex-direction: row;
4+
}
5+
6+
.bb-contributor img {
7+
border-radius: 50%;
8+
width: 56px;
9+
margin-right: .5rem;
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@namespace BootstrapBlazor.Server.Components.Samples.Tutorials
2+
@page "/tutorials/online-sheet"
3+
4+
<div class="bb-online-sheet-demo">
5+
<UniverSheet @ref="_sheetExcel" Data="@_data" OnReadyAsync="OnReadyAsync"></UniverSheet>
6+
</div>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
7+
8+
/// <summary>
9+
/// Online sheet sample code
10+
/// </summary>
11+
public partial class OnlineSheet : ComponentBase, IDisposable
12+
{
13+
[Inject, NotNull]
14+
private IWebHostEnvironment? WebHost { get; set; }
15+
16+
[Inject, NotNull]
17+
private ToastService? ToastService { get; set; }
18+
19+
[Inject, NotNull]
20+
private IStringLocalizer<OnlineSheet>? Localizer { get; set; }
21+
22+
[Inject]
23+
[NotNull]
24+
private IDispatchService<Contributor>? DispatchService { get; set; }
25+
26+
[NotNull]
27+
private UniverSheet? _sheetExcel = null;
28+
29+
private UniverSheetData? _data = null;
30+
31+
private bool _inited = false;
32+
33+
/// <summary>
34+
/// <inheritdoc/>
35+
/// </summary>
36+
protected override void OnInitialized()
37+
{
38+
base.OnInitialized();
39+
40+
var reportFile = Path.Combine(WebHost.WebRootPath, "univer-sheet", "report.json");
41+
if (File.Exists(reportFile))
42+
{
43+
var sheetData = File.ReadAllText(reportFile);
44+
45+
_data = new UniverSheetData()
46+
{
47+
Data = sheetData
48+
};
49+
}
50+
}
51+
52+
private async Task OnReadyAsync()
53+
{
54+
_inited = true;
55+
await ToastService.Information(Localizer["ToastOnReadyTitle"], Localizer["ToastOnReadyContent"]);
56+
DispatchService.Subscribe(Dispatch);
57+
}
58+
59+
private async Task Dispatch(DispatchEntry<Contributor> entry)
60+
{
61+
if (!_inited)
62+
{
63+
return;
64+
}
65+
66+
if (entry.Entry != null)
67+
{
68+
await ToastService.Show(new ToastOption()
69+
{
70+
Title = "Dispatch 服务测试",
71+
ChildContent = BootstrapDynamicComponent.CreateComponent<OnlineContributor>(new Dictionary<string, object?>()
72+
{
73+
{ "Contributor", entry.Entry }
74+
}).Render(),
75+
Category = ToastCategory.Information,
76+
Delay = 3000,
77+
ForceDelay = true
78+
});
79+
80+
DispatchService.UnSubscribe(Dispatch);
81+
82+
await _sheetExcel.PushDataAsync(entry.Entry.Data);
83+
}
84+
}
85+
86+
private void Dispose(bool disposing)
87+
{
88+
if (disposing)
89+
{
90+
DispatchService.UnSubscribe(Dispatch);
91+
}
92+
}
93+
94+
/// <summary>
95+
/// <inheritdoc/>
96+
/// </summary>
97+
public void Dispose()
98+
{
99+
Dispose(true);
100+
GC.SuppressFinalize(this);
101+
}
102+
}
103+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.bb-online-sheet-demo {
2+
margin: -1rem;
3+
height: calc(100vh - var(--bs-header-height));
4+
}

0 commit comments

Comments
 (0)