Skip to content

Commit 0fc543e

Browse files
committed
doc: 更新 ImageCropper 示例
1 parent 964ebe2 commit 0fc543e

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
<PackageTips Name="BootstrapBlazor.ImageCropper" />
77

88
<DemoBlock Title="@Localizer["ImageCropperNormalText"]" Introduction="@Localizer["ImageCropperNormalIntro"]" Name="Normal">
9-
<ImageCropper @ref="Cropper" Url="@images[0]" DefaultButton="false" />
9+
<ImageCropper @ref="_cropper" Url="@images[0]"></ImageCropper>
1010
<section ignore>
1111
<BootstrapInputGroup>
12-
<Button Text="OK" OnClick="(async () => Base64 = await Cropper.Crop())" />
13-
<Button Text="@Localizer["ImageCropperResetText"]" OnClick="Cropper.Reset" />
12+
<Button Text="OK" OnClick="Crop" />
13+
<Button Text="@Localizer["ImageCropperResetText"]" OnClick="_cropper.Reset" />
1414
<Button Text="@Localizer["ImageCropperReplaceText"]" OnClick="OnClickReplace" />
15+
<Button Text="@Localizer["ImageCropperRotateText"]" OnClick="Rotate" />
16+
<Button Text="@Localizer["ImageCropperEnableText"]" OnClick="_cropper.Enable" />
17+
<Button Text="@Localizer["ImageCropperDisabledText"]" OnClick="_cropper.Disable" />
18+
<Button Text="@Localizer["ImageCropperClearText"]" OnClick="_cropper.Clear" />
1519
</BootstrapInputGroup>
16-
<Textarea Value="@Base64" rows="3" class="mt-3" />
20+
<Textarea Value="@_base64String" rows="3" class="mt-3" />
1721
</section>
1822
</DemoBlock>
1923

24+
<DemoBlock Title="@Localizer["ImageCropperNormalText"]" Introduction="@Localizer["ImageCropperNormalIntro"]" Name="Normal">
25+
<ImageCropper Url="@images[0]" CropperShape="ImageCropperShape.Round" />
26+
</DemoBlock>
27+
2028
<AttributeTable Items="@GetAttributes()" />

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

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@
55
namespace BootstrapBlazor.Server.Components.Samples;
66

77
/// <summary>
8-
/// ImageCroppers
8+
/// ImageCropper 组件示例
99
/// </summary>
1010
public partial class ImageCroppers
1111
{
12+
private ImageCropper _cropper = default!;
1213

13-
[NotNull]
14-
ImageCropper? Cropper { get; set; }
15-
16-
private string[] images = ["./images/picture.jpg", "./images/ImageList2.jpeg"];
14+
private readonly string[] images = ["./images/picture.jpg", "./images/ImageList2.jpeg"];
1715

1816
private int index = 0;
1917

20-
private string? Base64 { get; set; }
18+
private string? _base64String;
2119

2220
private async Task OnClickReplace()
2321
{
2422
index = index == 0 ? 1 : 0;
25-
await Cropper.Replace(images[index]);
23+
await _cropper.Replace(images[index]);
2624
}
2725

26+
private async Task Crop()
27+
{
28+
_base64String = await _cropper.Crop();
29+
}
30+
31+
private Task Rotate() => _cropper.Rotate(90);
32+
2833
/// <summary>
2934
/// GetAttributes
3035
/// </summary>
@@ -41,51 +46,35 @@ protected AttributeItem[] GetAttributes() =>
4146
},
4247
new()
4348
{
44-
Name = "DefaultButton",
45-
Description = Localizer["AttributesImageCropperDefaultButton"],
49+
Name = "IsDisabled",
50+
Description = Localizer["AttributesImageCropperIsDisabled"],
4651
Type = "bool",
47-
ValueList = "-",
48-
DefaultValue = "true"
52+
ValueList = "true|false",
53+
DefaultValue = "false"
4954
},
5055
new()
5156
{
52-
Name = "Preview",
53-
Description = Localizer["AttributesImageCropperPreview"],
54-
Type = "bool",
55-
ValueList = "-",
56-
DefaultValue = "true"
57-
},
58-
new()
59-
{
60-
Name = "OnResult()",
61-
Description = Localizer["AttributesImageCropperOnResult"],
62-
Type = "Func",
63-
ValueList = "-",
64-
DefaultValue = "-"
65-
},
66-
new()
67-
{
68-
Name = "OnBase64Result()",
69-
Description = Localizer["AttributesImageCropperOnBase64Result"],
70-
Type = "Func",
57+
Name = "OnCropAsync",
58+
Description = Localizer["AttributesImageCropperOnCropAsync"],
59+
Type = "Func<ImageCropperResult, Task>",
7160
ValueList = "-",
7261
DefaultValue = "-"
7362
},
7463
new()
7564
{
76-
Name = "Crop()",
77-
Description = Localizer["AttributesImageCropperCrop"],
78-
Type = "Task",
65+
Name = "Options",
66+
Description = Localizer["AttributesImageCropperOptions"],
67+
Type = "ImageCropperOption",
7968
ValueList = "-",
8069
DefaultValue = "-"
8170
},
8271
new()
8372
{
84-
Name = "CropToStream()",
85-
Description = Localizer["AttributesImageCropperCropToStream"],
86-
Type = "Task",
73+
Name = "CropperShape",
74+
Description = Localizer["AttributesImageCropperShape"],
75+
Type = "ImageCropperShape",
8776
ValueList = "-",
8877
DefaultValue = "-"
89-
},
78+
}
9079
];
9180
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6499,13 +6499,15 @@
64996499
"ImageCropperNormalIntro": "Url parameter setting image",
65006500
"ImageCropperResetText": "Reset",
65016501
"ImageCropperReplaceText": "Replace",
6502-
"AttributesImageCropperUrl": "Image URL or Base64 dataurl",
6503-
"AttributesImageCropperDefaultButton": "Show default button",
6504-
"AttributesImageCropperPreview": "Show preview after cropping",
6505-
"AttributesImageCropperOnResult": "Crop result Stream callback method",
6506-
"AttributesImageCropperOnBase64Result": "Crop result base64 callback method",
6507-
"AttributesImageCropperCrop": "Crop, return base64, and execute OnResult/OnBase64Result callback",
6508-
"AttributesImageCropperCropToStream": "Crop, return Stream"
6502+
"ImageCropperRotateText": "Rotate",
6503+
"ImageCropperEnableText": "Enable",
6504+
"ImageCropperDisabledText": "Disabled",
6505+
"ImageCropperClearText": "Clear",
6506+
"AttributesImageCropperUrl": "Image Url",
6507+
"AttributesImageCropperIsDisabled": "Whether the component is disabled",
6508+
"AttributesImageCropperOnCropAsync": "Crop result callback method",
6509+
"AttributesImageCropperOptions": "Crop option",
6510+
"AttributesImageCropperShape": "Crop shape"
65096511
},
65106512
"BootstrapBlazor.Server.Components.Samples.Translators": {
65116513
"TranslatorsTitle": "Azure Translator",

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6499,13 +6499,15 @@
64996499
"ImageCropperNormalIntro": "Url 参数设置图片",
65006500
"ImageCropperResetText": "复位",
65016501
"ImageCropperReplaceText": "替换",
6502-
"AttributesImageCropperUrl": "图片URL 或 Base64 dataurl",
6503-
"AttributesImageCropperDefaultButton": "显示默认按钮",
6504-
"AttributesImageCropperPreview": "显示剪裁后预览",
6505-
"AttributesImageCropperOnResult": "剪裁结果 Stream 回调方法",
6506-
"AttributesImageCropperOnBase64Result": "剪裁结果 base64 回调方法",
6507-
"AttributesImageCropperCrop": "剪裁,返回 base64, 并执行 OnResult/OnBase64Result 回调",
6508-
"AttributesImageCropperCropToStream": "剪裁,返回 Stream"
6502+
"ImageCropperRotateText": "旋转",
6503+
"ImageCropperEnableText": "启用",
6504+
"ImageCropperDisabledText": "禁用",
6505+
"ImageCropperClearText": "清除",
6506+
"AttributesImageCropperUrl": "图片地址",
6507+
"AttributesImageCropperIsDisabled": "是否被禁用",
6508+
"AttributesImageCropperOnCropAsync": "剪裁结果回调方法",
6509+
"AttributesImageCropperOptions": "裁剪选项",
6510+
"AttributesImageCropperShape": "裁剪形状"
65096511
},
65106512
"BootstrapBlazor.Server.Components.Samples.Translators": {
65116513
"TranslatorsTitle": "AzureTranslator 翻译服务",

0 commit comments

Comments
 (0)