Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.Gantt" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.Holiday" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.Html2Image" Version="9.0.0-beta02" />
<PackageReference Include="BootstrapBlazor.Html2Image" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.Html2Pdf" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.IconPark" Version="9.0.2" />
<PackageReference Include="BootstrapBlazor.ImageCropper" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.IP2Region" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.JuHeIpLocatorProvider" Version="9.0.0-beta01" />
<PackageReference Include="BootstrapBlazor.JuHeIpLocatorProvider" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.Live2DDisplay" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.Markdown" Version="9.0.1" />
<PackageReference Include="BootstrapBlazor.MaterialDesign" Version="9.0.1" />
Expand All @@ -64,6 +64,7 @@
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.3" />
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.1" />
<PackageReference Include="BootstrapBlazor.Topology" Version="9.0.0" />
<PackageReference Include="BootstrapBlazor.UniverSheet" Version="9.0.0-beta01" />
<PackageReference Include="BootstrapBlazor.VideoPlayer" Version="9.0.3" />
<PackageReference Include="BootstrapBlazor.WinBox" Version="9.0.7" />
</ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/UniverSheets.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@page "/univer-sheet"
@inherits WebSiteModuleComponentBase
@attribute [JSModuleAutoLoader("Samples/UniverSheets.razor.js")]

<h3>@Localizer["UniverSheetTitle"]</h3>

<h4>@Localizer["UniverSheetIntro"]</h4>

<PackageTips Name="BootstrapBlazor.UniverSheet" />

<DemoBlock Title="@Localizer["NormalTitle"]"
Introduction="@Localizer["NormalIntro"]"
Name="Normal">
<section ignore>
<p>@((MarkupString)Localizer["NormalDesc1"].Value)</p>
<Button OnClickWithoutRender="OnPushExcelData" Text="@Localizer["PushButtonText"]"></Button>
</section>
<div class="bb-sheet-demo">
<UniverSheet @ref="_sheetExcel" OnReadyAsync="OnReadyAsync"></UniverSheet>
</div>
</DemoBlock>

<DemoBlock Title="@Localizer["PluginTitle"]"
Introduction="@Localizer["PluginIntro"]"
Name="Plugin">
<section ignore>
<p>@((MarkupString)Localizer["NormalDesc2"].Value)</p>
<Button OnClickWithoutRender="OnPushPluginData" Text="@Localizer["PushButtonText"]"></Button>
</section>
<div class="bb-sheet-demo">
<UniverSheet @ref="_sheetPlugin" Plugins="Plugins" OnPostDataAsync="OnPostDataAsync"></UniverSheet>
</div>
</DemoBlock>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Server.Components.Samples;

/// <summary>
/// UniverSheet 组件示例代码
/// </summary>
public partial class UniverSheets
{
[Inject, NotNull]
private ToastService? ToastService { get; set; }

[Inject, NotNull]
private IStringLocalizer<UniverSheets>? Localizer { get; set; }

private readonly Dictionary<string, string> Plugins = new()
{
{ "ReportPlugin", "univer-sheet/plugin.js" }
};

private UniverSheet _sheetExcel = default!;

private UniverSheet _sheetPlugin = default!;

private async Task OnReadyAsync() => await ToastService.Information(Localizer["ToastOnReadyTitle"], Localizer["ToastOnReadyContent"]);

private static Task<UniverSheetData?> OnPostDataAsync(UniverSheetData data)
{
// 这里可以根据 data 的内容进行处理然后返回处理后的数据
// 本例返回与时间相关的数据
var result = new UniverSheetData()
{
MessageName = data.MessageName,
CommandName = data.CommandName,
Data = new
{
key = "datetime",
Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
}
};
return Task.FromResult<UniverSheetData?>(result);
}

private async Task OnPushExcelData()
{
await _sheetExcel.PushDataAsync(new UniverSheetData()
{
MessageName = "MessageName",
CommandName = "CommandName",
Data = new object[]
{
new object[] { "1", "2", "3", "4", "5" },
new object[] { "1", "2", "3", "4", "5" },
}
});
}

private async Task OnPushPluginData()
{
await _sheetPlugin.PushDataAsync(new UniverSheetData()
{
MessageName = "MessageName",
CommandName = "CommandName",
Data = new
{
Id = "1",
Name = "Test",
Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.bb-sheet-demo {
height: 290px;
width: 100%;
border: 1px solid var(--bs-border-color);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function init(id) {

}

export function dispose(id) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@ void AddData(DemoMenuItem item)
Url = "typed"
},
new()
{
IsNew = true,
Text = Localizer["UniverSheet"],
Url = "univer-sheet"
},
new()
{
Text = Localizer["VideoPlayer"],
Url = "video-player"
Expand Down
16 changes: 15 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4855,7 +4855,8 @@
"Affix": "Affix",
"Watermark": "Watermark",
"OctIcon": "Oct Icons",
"Typed": "Typed"
"Typed": "Typed",
"UniverSheet": "UniverSheet"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
"TablesHeaderTitle": "Header grouping function",
Expand Down Expand Up @@ -7002,5 +7003,18 @@
"Html2ImageElementIntro": "Get the <b>base64-encoded</b> image by calling the <code>GetDataAsync</code> method",
"Html2ImageButtonText": "Image",
"Html2ImageDesc": "Since the underlying library is <a href=\"https://github.com/bubkoo/html-to-image?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">html-to-image</a>, if you encounter any problems during actual use, please refer to the project <a href=\"https://github.com/bubkoo/html-to-image/issues?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Issue</a>"
},
"BootstrapBlazor.Server.Components.Samples.UniverSheets": {
"UniverSheetTitle": "UniverSheet",
"UniverSheetIntro": "Encapsulates the core spreadsheet component of the open source office suite ​Univer​, providing a high-performance, scalable online spreadsheet solution",
"NormalTitle": "Basic usage",
"NormalIntro": "Set your own plugins by setting the <code>Plugins</code> parameter",
"NormalDesc1": "Push data to the spreadsheet by calling the instance method <code>PushDataAsync</code>",
"NormalDesc2": "Click the <b>Push Data</b> button to push data to the table, and click the first icon on the <b>Toolbar</b> to get data from the server.",
"PushButtonText": "Push",
"ToastOnReadyTitle": "Notification",
"ToastOnReadyContent": "The sheet is ready for push data.",
"PluginTitle": "Plugins",
"PluginIntro": "Set custom plugins by setting the <code>Plugins</code> parameter"
}
}
18 changes: 16 additions & 2 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4855,7 +4855,8 @@
"Affix": "固钉组件 Affix",
"Watermark": "水印组件 Watermark",
"OctIcon": "Oct Icons",
"Typed": "打字机效果 Typed"
"Typed": "打字机效果 Typed",
"UniverSheet": "表格组件 UniverSheet"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
"TablesHeaderTitle": "表头分组功能",
Expand Down Expand Up @@ -6990,7 +6991,7 @@
"BootstrapBlazor.Server.Components.Samples.Typeds": {
"TypedTitle": "Typed 打字机效果",
"TypedIntro": "输入任意字符串,它会按照你设置的速度输入,输入的内容会退格,然后根据你设置的字符串数量开始一个新句子。",
"NormalTitle": "Text",
"NormalTitle": "基础用法",
"NormalIntro": "通过设置 <code>Text</code> 参数设置要显示的文本",
"TypedOptionsTitle": "TypedOptions",
"TypedOptionsIntro": "通过设置 <code>TypedOptions</code> 参数的属性自定义打字速度、延时等设定"
Expand All @@ -7002,5 +7003,18 @@
"Html2ImageElementIntro": "通过调用 <code>GetDataAsync</code> 方法获得 <b>base64-encoded</b> 图片",
"Html2ImageButtonText": "Image",
"Html2ImageDesc": "由于底层使用的是 <a href=\"https://github.com/bubkoo/html-to-image?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">html-to-image</a> 实际使用过程中遇到问题请参考项目 <a href=\"https://github.com/bubkoo/html-to-image/issues?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Issue</a>"
},
"BootstrapBlazor.Server.Components.Samples.UniverSheets": {
"UniverSheetTitle": "UniverSheet 电子表格组件",
"UniverSheetIntro": "封装开源办公套件 ​Univer​ 的核心电子表格组件,提供高性能、可扩展的在线表格解决方案",
"NormalTitle": "基础用法",
"NormalIntro": "通过调用实例方法 <code>PushDataAsync</code> 推送数据到电子表格",
"NormalDesc1": "点击 <b>推送数据</b> 按钮主动将数据推送给表格",
"NormalDesc2": "点击 <b>推送数据</b> 按钮主动将数据推送给表格,点击 <b>工具栏</b> 第一个小按钮主动从服务器端获取数据",
"PushButtonText": "推送数据",
"ToastOnReadyTitle": "组件通知",
"ToastOnReadyContent": "表格组件已就绪,可进行后续数据推送等操作",
"PluginTitle": "自定义插件",
"PluginIntro": "通过设置 <code>Plugins</code> 参数设置自己的插件"
}
}
3 changes: 2 additions & 1 deletion src/BootstrapBlazor.Server/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@
"smiles-drawer": "SmilesDrawers",
"affix": "Affixs",
"watermark": "Watermarks",
"typed": "Typeds"
"typed": "Typeds",
"univer-sheet": "UniverSheets"
},
"video": {
"table": "BV1ap4y1x7Qn?p=1",
Expand Down
117 changes: 117 additions & 0 deletions src/BootstrapBlazor.Server/wwwroot/univer-sheet/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import DataService from '../_content/BootstrapBlazor.UniverSheet/data-service.js'

const { Disposable, setDependencies, Injector, ICommandService, CommandType, UniverInstanceType } = UniverCore;
const { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup, ComponentManager, IMenuManagerService, MenuItemType, getMenuHiddenObservable } = UniverUi;

const GetDataOperation = {
id: 'report.operation.add-table',
type: CommandType.OPERATION,
handler: async (accessor) => {
const dataService = accessor.get(DataService.name);
const data = await dataService.getDataAsync({
messageName: "getDataMessage",
commandName: "getDataCommand"
});
if (data) {
const univerAPI = dataService.getUniverSheet().univerAPI;
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange(0, 0, 2, 1)
const defaultData = [
[{ v: data.data.key }],
[{ v: data.data.value }]
]
range.setValues(defaultData);
}
}
};

function GetDataIcon() {
return React.createElement(
'svg',
{ xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24" },
React.createElement(
'path',
{ fill: "currentColor", d: "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12S6.477 2 12 2m.16 14a6.981 6.981 0 0 0-5.147 2.256A7.966 7.966 0 0 0 12 20a7.97 7.97 0 0 0 5.167-1.892A6.979 6.979 0 0 0 12.16 16M12 4a8 8 0 0 0-6.384 12.821A8.975 8.975 0 0 1 12.16 14a8.972 8.972 0 0 1 6.362 2.634A8 8 0 0 0 12 4m0 1a4 4 0 1 1 0 8a4 4 0 0 1 0-8m0 2a2 2 0 1 0 0 4a2 2 0 0 0 0-4" }
)
);
}

function ReportGetDataFactory(accessor) {
return {
id: GetDataOperation.id,
type: MenuItemType.BUTTON,
icon: 'GetDataIcon',
tooltip: '获取数据',
title: '获取数据',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
};
}

export class ReportController extends Disposable {
constructor(_injector, _commandService, _menuManagerService, _componentManager) {
super();

this._injector = _injector;
this._commandService = _commandService;
this._menuManagerService = _menuManagerService;
this._componentManager = _componentManager;

this._initCommands();
this._registerComponents();
this._initMenus();
this._registerReceiveDataCallback();
}

_registerReceiveDataCallback() {
const dataService = this._injector.get(DataService.name);
dataService.registerReceiveDataCallback(data => {
this.receiveData(data, dataService.getUniverSheet());
});
}

_initCommands() {
[GetDataOperation].forEach((c) => {
this.disposeWithMe(this._commandService.registerCommand(c));
});
}

_registerComponents() {
const componentMap = {
GetDataIcon,
}
Object.entries(componentMap).forEach((item) => {
this.disposeWithMe(this._componentManager.register(...item));
});

}

_initMenus() {
this._menuManagerService.mergeMenu({
[RibbonStartGroup.HISTORY]: {
[GetDataOperation.id]: {
order: -1,
menuItemFactory: ReportGetDataFactory
},
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.DATA]: {
[GetDataOperation.id]: {
order: 0,
menuItemFactory: ReportGetDataFactory
}
}
}
});
}

receiveData(data, sheet) {
const { univerAPI } = sheet;
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange(0, 0, 2, 3)
const defaultData = [
[{ v: 'Id' }, { v: 'Name' }, { v: 'Value' }],
[{ v: data.data.id }, { v: data.data.name }, { v: data.data.value }]
]
range.setValues(defaultData);
}
}

setDependencies(ReportController, [Injector, ICommandService, IMenuManagerService, ComponentManager]);
31 changes: 31 additions & 0 deletions src/BootstrapBlazor.Server/wwwroot/univer-sheet/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import DataService from '../_content/BootstrapBlazor.UniverSheet/data-service.js'
import { ReportController } from './controller.js'

const { Plugin, Injector, setDependencies } = UniverCore;

// 定义插件类
export class ReportPlugin extends Plugin {
static pluginName = 'ReportPlugin';

constructor(_injector) {
super();

this._injector = _injector;
}

onStarting() {
this._injector.add([ReportController]);
this._injector.add([DataService.name, { useClass: DataService }])
}

onReady() {
this._injector.get(ReportController)
}

onRendered() {

}
}

// 设置依赖
setDependencies(ReportPlugin, [Injector]);