Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CardUpload): add CanPreviewCallback parameter #3719

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public partial class CardUpload<TValue>

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

/// <summary>
/// 获得/设置 是否允许预览回调方法 默认 null
/// </summary>
[Parameter]
public Func<UploadFile, bool>? CanPreviewCallback { get; set; }

/// <summary>
/// 获得/设置 图标模板
/// </summary>
Expand Down Expand Up @@ -108,13 +114,17 @@ protected override void OnParametersSet()
ZoomIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadZoomIcon);
}

private static bool IsImage(UploadFile item)
private bool IsImage(UploadFile item)
{
bool ret;
if (item.File != null)
{
ret = item.File.ContentType.Contains("image", StringComparison.OrdinalIgnoreCase) || CheckExtensions(item.File.Name);
}
else if (CanPreviewCallback != null)
{
ret = CanPreviewCallback(item);
}
else
{
ret = IsBase64Format() || CheckExtensions(item.FileName ?? item.PrevUrl ?? "");
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Extensions/IEditorItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private static bool IsVisible(this IEditorItem item, ItemChangedType changedType
{
ret = changedType switch
{
ItemChangedType.Add => col.IsVisibleWhenAdd.HasValue ? col.IsVisibleWhenAdd.Value : col.Visible,
_ => col.IsVisibleWhenEdit.HasValue ? col.IsVisibleWhenEdit.Value : col.Visible
ItemChangedType.Add => col.IsVisibleWhenAdd ?? col.Visible,
_ => col.IsVisibleWhenEdit ?? col.Visible
};
}
return ret;
Expand Down