Skip to content

Commit a4a8e71

Browse files
committed
feat: 增加 ImageCropperData 结构体
1 parent 1efe80f commit a4a8e71

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

src/components/BootstrapBlazor.ImageCropper/ImageCropper.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class ImageCropper
3434
/// 获得/设置 剪裁调整结束回调方法
3535
/// </summary>
3636
[Parameter]
37-
public Func<Task>? OnCropEndAsync { get; set; }
37+
public Func<ImageCropperData, Task>? OnCropEndAsync { get; set; }
3838

3939
/// <summary>
4040
/// 获取/设置 裁剪选项
@@ -170,11 +170,11 @@ public Task Disable()
170170
/// </summary>
171171
/// <returns></returns>
172172
[JSInvokable]
173-
public async Task TriggerOnCropEndAsync()
173+
public async Task TriggerOnCropEndAsync(ImageCropperData data)
174174
{
175-
if(OnCropEndAsync != null)
175+
if (OnCropEndAsync != null)
176176
{
177-
await Task.CompletedTask;
177+
await OnCropEndAsync(data);
178178
}
179179
}
180180
}

src/components/BootstrapBlazor.ImageCropper/ImageCropper.razor.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ export async function init(id, invoke, options) {
1111
}
1212

1313
const image = el.querySelector(".bb-cropper-image");
14-
const cropper = new Cropper(image, getOptions(options.options));
14+
const { options: op, triggerOnCropEndAsync } = options;
15+
if (triggerOnCropEndAsync) {
16+
let cropData = null;
17+
op.cropend = () => {
18+
invoke.invokeMethodAsync(triggerOnCropEndAsync, cropData);
19+
cropData = null;
20+
}
21+
op.crop = e => {
22+
cropData = e.detail;
23+
}
24+
}
25+
const cropper = new Cropper(image, getOptions(op));
1526

1627
Data.set(id, { el, invoke, options, cropper });
1728
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
/// <summary>
8+
/// 裁切数据实体类
9+
/// </summary>
10+
public struct ImageCropperData
11+
{
12+
/// <summary>
13+
/// 获得/设置 裁剪框高度值
14+
/// </summary>
15+
public float Height { get; set; }
16+
17+
/// <summary>
18+
/// 获得/设置 裁剪框宽度值
19+
/// </summary>
20+
public float Width { get; set; }
21+
22+
/// <summary>
23+
/// 获得/设置 裁剪框 X 值
24+
/// </summary>
25+
public float X { get; set; }
26+
27+
/// <summary>
28+
/// 获得/设置 裁剪框 Y 值
29+
/// </summary>
30+
public float Y { get; set; }
31+
32+
/// <summary>
33+
/// 获得/设置 裁剪框旋转角度值
34+
/// </summary>
35+
public float Rotate { get; set; }
36+
37+
/// <summary>
38+
/// 获得/设置 裁剪框 X 轴缩放值
39+
/// </summary>
40+
public float ScaleX { get; set; }
41+
42+
/// <summary>
43+
/// 获得/设置 裁剪框 Y 轴缩放值
44+
/// </summary>
45+
public float ScaleY { get; set; }
46+
}

0 commit comments

Comments
 (0)