Skip to content

Commit 46fac35

Browse files
feat(UniverSheet): add Lang parameter (#401)
* refactor: 更新样式 * refactor: 移除不需要的设置 * refactor: 重构代码 * refactor: 增加 WorkbookData 参数 * refactor: 精简 options 提高可读性 * refactor: 增加内置接收数据处理逻辑 * refactor: 更新 lang 转换 * refactor: 增加lang配置 * feat: 增加 Lang 自动设置 * chore: bump version 9.0.3 --------- Co-authored-by: zhaijunlei <276318515@qq.com>
1 parent 02a9b29 commit 46fac35

48 files changed

Lines changed: 628 additions & 61 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/components/BootstrapBlazor.UniverSheet/BootstrapBlazor.UniverSheet.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>9.0.2</Version>
4+
<Version>9.0.3</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.UniverSheet/Components/UniverSheet.razor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

55
using Microsoft.AspNetCore.Components;
6+
using System.Globalization;
67

78
namespace BootstrapBlazor.Components;
89

@@ -47,6 +48,16 @@ public partial class UniverSheet
4748

4849
private UniverSheetData? _lastData;
4950

51+
/// <summary>
52+
/// <inheritdoc/>
53+
/// </summary>
54+
protected override void OnParametersSet()
55+
{
56+
base.OnParametersSet();
57+
58+
Lang ??= CultureInfo.CurrentUICulture.Name;
59+
}
60+
5061
/// <summary>
5162
/// <inheritdoc/>
5263
/// </summary>

src/components/BootstrapBlazor.UniverSheet/Components/UniverSheet.razor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ export async function init(id, invoke, options) {
88
return;
99
}
1010

11+
const { theme, lang, plugins, data } = options;
1112
const univerSheet = {
1213
el,
1314
invoke,
14-
options
15+
data,
16+
plugins,
17+
theme,
18+
lang
1519
};
20+
1621
await createUniverSheetAsync(univerSheet);
1722
Data.set(id, univerSheet);
1823

src/components/BootstrapBlazor.UniverSheet/Components/UniverSheetData.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public class UniverSheetData
2121
public string? CommandName { get; set; }
2222

2323
/// <summary>
24-
/// 获得/设置 数据 默认 null 未设置
24+
/// 获得/设置 UniverSheet workbook 数据 默认 null 未设置
25+
/// </summary>
26+
public object? WorkbookData { get; set; }
27+
28+
/// <summary>
29+
/// 获得/设置 附加业务数据 默认 null 未设置
2530
/// </summary>
2631
public object? Data { get; set; }
2732
}

src/components/BootstrapBlazor.UniverSheet/wwwroot/plugin.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import DataService from './data-service.js'
22

3-
const { Plugin, Injector, setDependencies, UniverInstanceType } = UniverCore;
3+
const { Plugin, Injector, setDependencies } = UniverCore;
44

5-
// 定义插件类
65
export class DefaultPlugin extends Plugin {
76
static pluginName = 'DefaultPlugin';
87

@@ -28,10 +27,10 @@ export class DefaultPlugin extends Plugin {
2827
}
2928

3029
receiveData(payload) {
31-
const { messageName, commandName, data } = payload;
30+
const { messageName, commandName, data, workbookData } = payload;
3231
if (messageName === null) {
3332
if (commandName === 'SetWorkbook') {
34-
this.setWorkbookData(JSON.parse(data));
33+
this.setWorkbookData(JSON.parse(workbookData));
3534
}
3635
else if (commandName === 'GetWorkbook') {
3736
return this.getWorkbookData();
@@ -65,7 +64,7 @@ export class DefaultPlugin extends Plugin {
6564
delete data.resources;
6665
return {
6766
messageName: null,
68-
commandName: 'Save',
67+
commandName: null,
6968
data: JSON.stringify(data)
7069
};
7170
}

src/components/BootstrapBlazor.UniverSheet/wwwroot/univer.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { addScript, addLink } from '../BootstrapBlazor/modules/utility.js'
22
import DataService from './data-service.js'
33

4-
const loadAssets = async () => {
5-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/react.production.min.js');
6-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/react-dom.production.min.js');
7-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/rxjs.umd.min.js');
8-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.presets.umd.min.js');
9-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-core.umd.min.js');
10-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-drawing.umd.min.js');
11-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.sheets-zen-editor.umd.min.js');
12-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-data-validation.umd.min.js');
4+
const loadAssets = async lang => {
5+
console.log(lang, 'lang');
6+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/react.production.min.js');
7+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/react-dom.production.min.js');
8+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/rxjs.umd.min.js');
9+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.presets.umd.min.js');
10+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-core/index.umd.min.js');
11+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-drawing/index.umd.min.js');
12+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.sheets-zen-editor/index.umd.min.js');
13+
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-data-validation/index.umd.min.js');
1314

14-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-core.locales.zh-CN.js');
15-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-drawing.locales.zhCN.js');
16-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.sheets-zen-editor.locales.zh-CN.js');
17-
await addScript('./_content/BootstrapBlazor.UniverSheet/univer/js/univerjs.preset-sheets-data-validation.locales.zh-CN.js');
15+
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-core/locales/${lang}.js`);
16+
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-drawing/locales/${lang}.js`);
17+
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.sheets-zen-editor/locales/${lang}.js`);
18+
await addScript(`./_content/BootstrapBlazor.UniverSheet/univer/univerjs.preset-sheets-data-validation/locales/${lang}.js`);
1819

19-
await addLink('./_content/BootstrapBlazor.UniverSheet/univer/css/univer-sheet.bundle.css');
20+
await addLink('./_content/BootstrapBlazor.UniverSheet/univer/univer-sheet.bundle.css');
2021
}
2122

22-
2323
export async function createUniverSheetAsync(sheet) {
24-
await loadAssets();
25-
24+
await loadAssets(sheet.lang);
25+
2626
const { el } = sheet;
2727
const { LocaleType, merge } = UniverCore;
2828
const { createUniver } = UniverPresets;
@@ -31,18 +31,18 @@ export async function createUniverSheetAsync(sheet) {
3131
const { UniverSheetsZenEditorPlugin } = UniverSheetsZenEditor
3232
const { UniverSheetsDataValidationPlugin } = UniverSheetsDataValidation
3333
const { UniverSheetsDataValidationUIPlugin } = UniverSheetsDataValidationUi
34-
const { defaultTheme } = UniverDesign;
35-
34+
const lang = sheet.lang.replace('-', '')
35+
const langStr = lang.charAt(0).toUpperCase() + lang.slice(1)
3636
const options = {
37-
theme: sheet.options.theme ?? defaultTheme,
38-
locale: sheet.options.lang ?? LocaleType.ZH_CN,
37+
theme: UniverDesign[sheet.theme] ?? UniverDesign.defaultTheme, //'defaultTheme' | greenTheme
38+
locale: lang,
3939
locales: {
40-
[LocaleType.ZH_CN]: merge(
40+
[lang]: merge(
4141
{},
42-
UniverPresetSheetsCoreZhCN,
43-
UniverPresetSheetsDrawingZhCN,
44-
UniverSheetsZenEditorZhCN,
45-
UniverSheetsDataValidationUiZhCN,
42+
window[`UniverPresetSheetsCore${langStr}`],
43+
window[`UniverPresetSheetsDrawing${langStr}`],
44+
window[`UniverSheetsZenEditor${langStr}`],
45+
window[`UniverSheetsDataValidationUi${langStr}`],
4646
),
4747
},
4848
plugins: [
@@ -51,7 +51,7 @@ export async function createUniverSheetAsync(sheet) {
5151
UniverSheetsDataValidationUIPlugin,
5252
]
5353
};
54-
const plugins = sheet.options.plugins ?? {
54+
const plugins = sheet.plugins ?? {
5555
DefaultPlugin: '_content/BootstrapBlazor.UniverSheet/plugin.js'
5656
};
5757
for (const name in plugins) {
@@ -70,9 +70,9 @@ export async function createUniverSheetAsync(sheet) {
7070
...options
7171
});
7272

73-
const { data } = sheet.options.data || {};
74-
if (data) {
75-
const option = typeof data === 'string' ? JSON.parse(data) : data;
73+
const { workbookData } = sheet.data || {};
74+
if (workbookData) {
75+
const option = typeof workbookData === 'string' ? JSON.parse(workbookData) : workbookData;
7676
univerAPI.createWorkbook(option);
7777
}
7878
else {

src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/css/univer-sheet.bundle.css

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

src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/js/react-dom.production.min.js renamed to src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/react-dom.production.min.js

File renamed without changes.

src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/js/react.production.min.js renamed to src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/react.production.min.js

File renamed without changes.

src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/js/rxjs.umd.min.js renamed to src/components/BootstrapBlazor.UniverSheet/wwwroot/univer/rxjs.umd.min.js

File renamed without changes.

0 commit comments

Comments
 (0)