diff --git a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
index 901c21d5655..8a75fce5671 100644
--- a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
+++ b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
@@ -45,7 +45,7 @@
-
+
diff --git a/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor b/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor
index 171f3f3d977..b39ec5e355e 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor
+++ b/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor
@@ -6,14 +6,35 @@
-
+
-
-
+
+
+
+
+
+
-
+ @if (!string.IsNullOrEmpty(_base64String))
+ {
+
+
+ }
+
+
+
+
+
+
+
+
+
+ @if (!string.IsNullOrEmpty(_base64String2))
+ {
+
+ }
diff --git a/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor.cs
index 3a5dfb6cd04..286103589df 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor.cs
@@ -5,26 +5,42 @@
namespace BootstrapBlazor.Server.Components.Samples;
///
-/// ImageCroppers
+/// ImageCropper 组件示例
///
public partial class ImageCroppers
{
+ private ImageCropper _cropper = default!;
- [NotNull]
- ImageCropper? Cropper { get; set; }
+ private ImageCropper _roundCropper = default!;
- private string[] images = ["./images/picture.jpg", "./images/ImageList2.jpeg"];
+ private readonly string[] images = ["./images/picture.jpg", "./images/ImageList2.jpeg"];
private int index = 0;
- private string? Base64 { get; set; }
+ private string? _base64String;
+
+ private string? _base64String2;
+
+ private ImageCropperOption _roundOptions = new() { IsRound = true, Radius = "50%" };
private async Task OnClickReplace()
{
index = index == 0 ? 1 : 0;
- await Cropper.Replace(images[index]);
+ await _cropper.Replace(images[index]);
+ }
+
+ private async Task Crop()
+ {
+ _base64String = await _cropper.Crop();
}
+ private async Task RoundCrop()
+ {
+ _base64String2 = await _roundCropper.Crop();
+ }
+
+ private Task Rotate() => _cropper.Rotate(90);
+
///
/// GetAttributes
///
@@ -41,51 +57,35 @@ protected AttributeItem[] GetAttributes() =>
},
new()
{
- Name = "DefaultButton",
- Description = Localizer["AttributesImageCropperDefaultButton"],
+ Name = "IsDisabled",
+ Description = Localizer["AttributesImageCropperIsDisabled"],
Type = "bool",
- ValueList = "-",
- DefaultValue = "true"
+ ValueList = "true|false",
+ DefaultValue = "false"
},
new()
{
- Name = "Preview",
- Description = Localizer["AttributesImageCropperPreview"],
- Type = "bool",
- ValueList = "-",
- DefaultValue = "true"
- },
- new()
- {
- Name = "OnResult()",
- Description = Localizer["AttributesImageCropperOnResult"],
- Type = "Func",
- ValueList = "-",
- DefaultValue = "-"
- },
- new()
- {
- Name = "OnBase64Result()",
- Description = Localizer["AttributesImageCropperOnBase64Result"],
- Type = "Func",
+ Name = "OnCropAsync",
+ Description = Localizer["AttributesImageCropperOnCropAsync"],
+ Type = "Func",
ValueList = "-",
DefaultValue = "-"
},
new()
{
- Name = "Crop()",
- Description = Localizer["AttributesImageCropperCrop"],
- Type = "Task",
+ Name = "Options",
+ Description = Localizer["AttributesImageCropperOptions"],
+ Type = "ImageCropperOption",
ValueList = "-",
DefaultValue = "-"
},
new()
{
- Name = "CropToStream()",
- Description = Localizer["AttributesImageCropperCropToStream"],
- Type = "Task",
+ Name = "CropperShape",
+ Description = Localizer["AttributesImageCropperShape"],
+ Type = "ImageCropperShape",
ValueList = "-",
DefaultValue = "-"
- },
+ }
];
}
diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
index 972543414a4..d4df57c9592 100644
--- a/src/BootstrapBlazor.Server/Locales/en-US.json
+++ b/src/BootstrapBlazor.Server/Locales/en-US.json
@@ -6499,13 +6499,15 @@
"ImageCropperNormalIntro": "Url parameter setting image",
"ImageCropperResetText": "Reset",
"ImageCropperReplaceText": "Replace",
- "AttributesImageCropperUrl": "Image URL or Base64 dataurl",
- "AttributesImageCropperDefaultButton": "Show default button",
- "AttributesImageCropperPreview": "Show preview after cropping",
- "AttributesImageCropperOnResult": "Crop result Stream callback method",
- "AttributesImageCropperOnBase64Result": "Crop result base64 callback method",
- "AttributesImageCropperCrop": "Crop, return base64, and execute OnResult/OnBase64Result callback",
- "AttributesImageCropperCropToStream": "Crop, return Stream"
+ "ImageCropperRotateText": "Rotate",
+ "ImageCropperEnableText": "Enable",
+ "ImageCropperDisabledText": "Disabled",
+ "ImageCropperClearText": "Clear",
+ "AttributesImageCropperUrl": "Image Url",
+ "AttributesImageCropperIsDisabled": "Whether the component is disabled",
+ "AttributesImageCropperOnCropAsync": "Crop result callback method",
+ "AttributesImageCropperOptions": "Crop option",
+ "AttributesImageCropperShape": "Crop shape"
},
"BootstrapBlazor.Server.Components.Samples.Translators": {
"TranslatorsTitle": "Azure Translator",
diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
index 40bcc9e3f68..f5a7733b618 100644
--- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
+++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
@@ -6499,13 +6499,15 @@
"ImageCropperNormalIntro": "Url 参数设置图片",
"ImageCropperResetText": "复位",
"ImageCropperReplaceText": "替换",
- "AttributesImageCropperUrl": "图片URL 或 Base64 dataurl",
- "AttributesImageCropperDefaultButton": "显示默认按钮",
- "AttributesImageCropperPreview": "显示剪裁后预览",
- "AttributesImageCropperOnResult": "剪裁结果 Stream 回调方法",
- "AttributesImageCropperOnBase64Result": "剪裁结果 base64 回调方法",
- "AttributesImageCropperCrop": "剪裁,返回 base64, 并执行 OnResult/OnBase64Result 回调",
- "AttributesImageCropperCropToStream": "剪裁,返回 Stream"
+ "ImageCropperRotateText": "旋转",
+ "ImageCropperEnableText": "启用",
+ "ImageCropperDisabledText": "禁用",
+ "ImageCropperClearText": "清除",
+ "AttributesImageCropperUrl": "图片地址",
+ "AttributesImageCropperIsDisabled": "是否被禁用",
+ "AttributesImageCropperOnCropAsync": "剪裁结果回调方法",
+ "AttributesImageCropperOptions": "裁剪选项",
+ "AttributesImageCropperShape": "裁剪形状"
},
"BootstrapBlazor.Server.Components.Samples.Translators": {
"TranslatorsTitle": "AzureTranslator 翻译服务",
diff --git a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs
index 0f3d90b8bee..ed2b5ab376b 100644
--- a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs
+++ b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs
@@ -25,18 +25,22 @@ public static class JSModuleExtensions
/// A ]]> 模块加载器
public static async Task LoadModule(this IJSRuntime jsRuntime, string fileName, string? version = null)
{
- JSModule? module = null;
if (!string.IsNullOrEmpty(version))
{
fileName = $"{fileName}?v={version}";
}
+
+ JSModule? module;
try
{
var jSObjectReference = await jsRuntime.InvokeAsync(identifier: "import", fileName);
module = new JSModule(jSObjectReference);
}
- catch (Exception) { }
- return module ?? new JSModule(null);
+ catch (Exception)
+ {
+ throw;
+ }
+ return module;
}
///
diff --git a/test/UnitTest/Extensions/JSModuleExtensionsTest.cs b/test/UnitTest/Extensions/JSModuleExtensionsTest.cs
index 1a59319f123..4a23131bcf1 100644
--- a/test/UnitTest/Extensions/JSModuleExtensionsTest.cs
+++ b/test/UnitTest/Extensions/JSModuleExtensionsTest.cs
@@ -19,8 +19,7 @@ public async Task LoadModule_Ok()
public async Task LoadModule_Exception()
{
var jsRuntime = new MockJSRuntime();
- var module = await jsRuntime.LoadModule("./mock.js", "test");
- Assert.NotNull(module);
+ await Assert.ThrowsAsync(() => jsRuntime.LoadModule("./mock.js", "test"));
}
[Fact]