Skip to content

Commit c866e93

Browse files
j4587698ArgoZhang
andauthored
feat(Editor): add OnFileUpload parameter (#6638)
* Editor增加Upload回调 * refactor: 精简代码 * doc: 增加 OnFileUpload 回调方法说明 * doc: 增加默认焦点设置 * feat: 更新说明文档 --------- Co-authored-by: Argo Zhang <[email protected]>
1 parent 7e351bd commit c866e93

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<PackageReference Include="BootstrapBlazor.Sortable" Version="9.0.3" />
7171
<PackageReference Include="BootstrapBlazor.Splitting" Version="9.0.3" />
7272
<PackageReference Include="BootstrapBlazor.SvgEditor" Version="9.0.3" />
73-
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.4" />
73+
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.6" />
7474
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
7575
<PackageReference Include="BootstrapBlazor.Tasks.Dashboard" Version="9.0.0" />
7676
<PackageReference Include="BootstrapBlazor.TcpSocket" Version="9.0.0" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Router AppAssembly="@typeof(Program).Assembly">
22
<Found Context="routeData">
33
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="routeData" Selector="h3" />
45
</Found>
56
</Router>

src/BootstrapBlazor.Server/Components/Samples/Editors.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@page "/editor"
2+
23
@inject SwalService SwalService
34
@inject PackageVersionService VersionManager
45
@inject IStringLocalizer<Editors> Localizer
6+
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
57

68
<h3>@Localizer["EditorsTitle"]</h3>
79

@@ -38,7 +40,7 @@
3840
</DemoBlock>
3941

4042
<DemoBlock Title="@Localizer["EditorIsEditorTitle"]" Introduction="@Localizer["EditorIsEditorIntro"]" Name="IsEditor">
41-
<Editor IsEditor="true" />
43+
<Editor IsEditor="true" OnFileUpload="OnFileUpload" />
4244
</DemoBlock>
4345

4446
<DemoBlock Title="@Localizer["EditorHeightTitle"]" Introduction="@Localizer["EditorHeightIntro"]" Name="Height">

src/BootstrapBlazor.Server/Components/Samples/Editors.razor.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ private async Task InsertHtmlAsync()
111111
await Editor.DoMethodAsync("pasteHTML", $"<h1>{Localizer["DoMethodAsyncPasteHTML"]}</h1>");
112112
}
113113

114+
private async Task<string> OnFileUpload(EditorUploadFile uploadFile)
115+
{
116+
var url = Path.Combine("images", "uploader", $"{Path.GetFileNameWithoutExtension(uploadFile.FileName)}-{DateTimeOffset.Now:yyyyMMddHHmmss}{Path.GetExtension(uploadFile.FileName)}");
117+
var fileName = Path.Combine(WebsiteOption.CurrentValue.WebRootPath, url);
118+
await uploadFile.SaveToFileAsync(fileName);
119+
120+
// 此处返回空字符串底层使用 URL.createObjectURL 方法创建 Blob 对象地址
121+
// 实战中可以返回 SSO 地址或者 base64 字符串等
122+
return "";
123+
}
124+
114125
private string? _editorCode;
115126

116127
private async Task OnGetCode()
@@ -167,6 +178,14 @@ private AttributeItem[] GetAttributes() =>
167178
Type = "IEnumerable<EditorToolbarButton>",
168179
ValueList = " — ",
169180
DefaultValue = " — "
181+
},
182+
new()
183+
{
184+
Name = "OnFileUpload",
185+
Description = Localizer["OnFileUploadAttribute"],
186+
Type = "Func<EditorUploadFile, Task>",
187+
ValueList = " — ",
188+
DefaultValue = " — "
170189
}
171190
];
172191
}

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@
25362536
"EditorPlaceholderIntro": "The prompt message when a null value is set by setting the <code>Placeholder</code> attribute",
25372537
"EditorPlaceholderDescription": "The default prompt is <b>Edit after clicking</b>",
25382538
"EditorIsEditorTitle": "Display as a rich text edit box by default",
2539-
"EditorIsEditorIntro": "Set the component to be directly displayed as a rich text edit box by setting the <code>IsEditor</code> property",
2539+
"EditorIsEditorIntro": "Set the component to be directly displayed as a rich text edit box by setting the <code>IsEditor</code> property. When uploading an image, you can get the image information through the <code>OnFileUpload</code> callback method",
25402540
"EditorHeightTitle": "Custom height",
25412541
"EditorHeightIntro": "Set the height of the component by setting the <code>Height</code> property",
25422542
"EditorOnValueChangedTitle": "Two-way binding",
@@ -2577,7 +2577,8 @@
25772577
"DoMethodAsyncButton2": "Update to H2",
25782578
"DoMethodAsyncButton3": "Insert Image",
25792579
"DoMethodAsyncButton4": "Get Code",
2580-
"DoMethodAsyncPasteHTML": "Here is the content inserted by the external button"
2580+
"DoMethodAsyncPasteHTML": "Here is the content inserted by the external button",
2581+
"OnFileUploadAttribute": "File upload callback method"
25812582
},
25822583
"BootstrapBlazor.Server.Components.Samples.EditorForms": {
25832584
"Title": "EditorForm",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@
25372537
"EditorPlaceholderIntro": "通过设置 <code>Placeholder</code> 属性来设置空值时的提示消息",
25382538
"EditorPlaceholderDescription": "默认提示是 <b>点击后进行编辑</b>",
25392539
"EditorIsEditorTitle": "默认显示为富文本编辑框",
2540-
"EditorIsEditorIntro": "通过设置 <code>IsEditor</code> 属性来设置组件直接显示为富文本编辑框",
2540+
"EditorIsEditorIntro": "通过设置 <code>IsEditor</code> 属性来设置组件直接显示为富文本编辑框,上传图片时可以通过 <code>OnFileUpload</code> 回调方法获得图片信息",
25412541
"EditorHeightTitle": "自定义高度",
25422542
"EditorHeightIntro": "通过设置 <code>Height</code> 属性来设置组件高度",
25432543
"EditorOnValueChangedTitle": "双向绑定",
@@ -2578,7 +2578,8 @@
25782578
"DoMethodAsyncButton2": "将段落修改为 H2",
25792579
"DoMethodAsyncButton3": "添加一张图片",
25802580
"DoMethodAsyncButton4": "获得组件内容",
2581-
"DoMethodAsyncPasteHTML": "这里是外部按钮插入的内容"
2581+
"DoMethodAsyncPasteHTML": "这里是外部按钮插入的内容",
2582+
"OnFileUploadAttribute": "文件上传回调方法"
25822583
},
25832584
"BootstrapBlazor.Server.Components.Samples.EditorForms": {
25842585
"Title": "EditorForm 表单组件",

0 commit comments

Comments
 (0)