Skip to content

Commit f8f7641

Browse files
authored
feat(CardUpload): add CanPreviewCallback parameter (#3719)
* feat: 增加 webp 支持 * feat: 增加 CanPreviewCallback 回调方法 * refactor: 精简代码 * refactor: 撤销 webp 支持
1 parent bf3d335 commit f8f7641

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public partial class CardUpload<TValue>
3535

3636
private string PreviewerId => $"prev_{Id}";
3737

38+
/// <summary>
39+
/// 获得/设置 是否允许预览回调方法 默认 null
40+
/// </summary>
41+
[Parameter]
42+
public Func<UploadFile, bool>? CanPreviewCallback { get; set; }
43+
3844
/// <summary>
3945
/// 获得/设置 图标模板
4046
/// </summary>
@@ -108,13 +114,17 @@ protected override void OnParametersSet()
108114
ZoomIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadZoomIcon);
109115
}
110116

111-
private static bool IsImage(UploadFile item)
117+
private bool IsImage(UploadFile item)
112118
{
113119
bool ret;
114120
if (item.File != null)
115121
{
116122
ret = item.File.ContentType.Contains("image", StringComparison.OrdinalIgnoreCase) || CheckExtensions(item.File.Name);
117123
}
124+
else if (CanPreviewCallback != null)
125+
{
126+
ret = CanPreviewCallback(item);
127+
}
118128
else
119129
{
120130
ret = IsBase64Format() || CheckExtensions(item.FileName ?? item.PrevUrl ?? "");

src/BootstrapBlazor/Extensions/IEditorItemExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private static bool IsVisible(this IEditorItem item, ItemChangedType changedType
5151
{
5252
ret = changedType switch
5353
{
54-
ItemChangedType.Add => col.IsVisibleWhenAdd.HasValue ? col.IsVisibleWhenAdd.Value : col.Visible,
55-
_ => col.IsVisibleWhenEdit.HasValue ? col.IsVisibleWhenEdit.Value : col.Visible
54+
ItemChangedType.Add => col.IsVisibleWhenAdd ?? col.Visible,
55+
_ => col.IsVisibleWhenEdit ?? col.Visible
5656
};
5757
}
5858
return ret;

0 commit comments

Comments
 (0)