Skip to content

Commit 83442e2

Browse files
committed
refactor: 增加预览功能
1 parent f22754c commit 83442e2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/BootstrapBlazor/Components/Upload/AvatarUpload.razor

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
<BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
88
}
9-
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id">
9+
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id" data-bb-previewer-id="@PreviewerId">
1010
<div class="upload-body is-avatar">
1111
@if (IsUploadButtonAtFirst && ShowAddButton())
1212
{
@@ -41,6 +41,10 @@
4141
@RenderAdd
4242
}
4343
</div>
44+
@if (ShowPreviewList)
45+
{
46+
<ImagePreviewer Id="@PreviewerId" PreviewList="PreviewList"></ImagePreviewer>
47+
}
4448
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
4549
</div>
4650

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ public partial class AvatarUpload<TValue>
115115
.AddClass(InvalidStatusIcon)
116116
.Build();
117117

118+
private bool ShowPreviewList => Files.Count != 0;
119+
120+
private string PreviewerId => $"prev_{Id}";
121+
122+
private List<string?> PreviewList => [.. Files.Select(i => i.PrevUrl)];
123+
118124
/// <summary>
119125
/// <inheritdoc/>
120126
/// </summary>
@@ -144,6 +150,14 @@ protected override async Task TriggerOnChanged(UploadFile file)
144150
await base.TriggerOnChanged(file);
145151
}
146152

153+
public async Task Preview()
154+
{
155+
if(ShowPreviewList)
156+
{
157+
158+
}
159+
}
160+
147161
private IReadOnlyCollection<ValidationResult> _results = [];
148162

149163
/// <summary>

0 commit comments

Comments
 (0)