Skip to content

Commit 4fffebd

Browse files
authored
feat(AvatarUpload): preview function may be required (#6418)
* chore: 更新 Logging 到最新版本 * doc: 更新单词拼写错误 * refactor: 增加预览功能 * feat: 增加预览实例方法 * test: 增加单元测试 * feat: bump version 9.8.1
1 parent c47c61b commit 4fffebd

File tree

8 files changed

+37
-5
lines changed

8 files changed

+37
-5
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<PackageReference Include="BootstrapBlazor.Vditor" Version="9.0.0" />
7676
<PackageReference Include="BootstrapBlazor.VideoPlayer" Version="9.0.3" />
7777
<PackageReference Include="BootstrapBlazor.WinBox" Version="9.0.7" />
78-
<PackageReference Include="Longbow.Logging" Version="9.0.0" />
78+
<PackageReference Include="Longbow.Logging" Version="9.0.1" />
7979
<PackageReference Include="Longbow.Tasks" Version="9.0.0" />
8080
</ItemGroup>
8181

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,7 @@
30753075
"SelectsEnumTitle": "Enumerate the data",
30763076
"SelectsEnumIntro": "an example of a type enumerated a <code>select</code> component binding",
30773077
"SelectsEnumDescription1": "Enumeration When the binding value is an empty enumeration type, the component automatically adds preferences internally through the <code>PlaceHolder</code> value, and when the <code>PlaceHolder</code> value is not set, <b>please select ... </b>as a preference, and this example binds <code>the EnumEducation</code> enumeration type data",
3078-
"SelectsEnumDescription2": "Setting <code>PalceHolder</code> is not valid when the binding value is an enumerated type",
3078+
"SelectsEnumDescription2": "Setting <code>PlaceHolder</code> is not valid when the binding value is an enumerated type",
30793079
"SelectsEnumSelectText1": "Can be empty",
30803080
"SelectsEnumSelectText2": "Not empty",
30813081
"SelectsEnumSelectText3": "Using enum integer values ​​as Items",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,7 @@
30753075
"SelectsEnumTitle": "枚举数据",
30763076
"SelectsEnumIntro": "<code>Select</code> 组件绑定枚举类型示例",
30773077
"SelectsEnumDescription1": "当绑定值为可为空枚举类型时,组件内部自动通过 <code>PlaceHolder</code> 值添加首选项,未设置 <code>PlaceHolder</code> 值时,使用资源文件中的 <b>请选择 ...</b> 作为首选项,本示例绑定 <code>EnumEducation</code> 枚举类型",
3078-
"SelectsEnumDescription2": "绑定值为枚举类型时,设置 <code>PalceHolder</code> 无效",
3078+
"SelectsEnumDescription2": "绑定值为枚举类型时,设置 <code>PlaceHolder</code> 无效",
30793079
"SelectsEnumSelectText1": "可为空",
30803080
"SelectsEnumSelectText2": "不为空",
30813081
"SelectsEnumSelectText3": "使用枚举整形值作为集合",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.8.1-beta06</Version>
4+
<Version>9.8.1</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

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: 18 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,18 @@ protected override async Task TriggerOnChanged(UploadFile file)
144150
await base.TriggerOnChanged(file);
145151
}
146152

153+
/// <summary>
154+
/// 预览当前头像方法
155+
/// </summary>
156+
/// <returns></returns>
157+
public async Task Preview()
158+
{
159+
if(ShowPreviewList)
160+
{
161+
await InvokeVoidAsync("preview", PreviewerId, 0);
162+
}
163+
}
164+
147165
private IReadOnlyCollection<ValidationResult> _results = [];
148166

149167
/// <summary>

src/BootstrapBlazor/wwwroot/modules/upload.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export function init(id) {
8484
})
8585
}
8686

87+
export function preview(previewerId, index) {
88+
const prev = Data.get(previewerId);
89+
if (prev) {
90+
prev.viewer.show(index);
91+
}
92+
}
93+
8794
export async function getPreviewUrl(id, fileName) {
8895
let url = '';
8996
const upload = Data.get(id);

test/UnitTest/Components/UploadAvatarTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
7676
new()
7777
})));
7878

79+
// call preview
80+
await cut.InvokeAsync(() => cut.Instance.Preview());
81+
7982
// upload-item-delete
8083
var button = cut.Find(".upload-item-delete");
8184
await cut.InvokeAsync(() => button.Click());

0 commit comments

Comments
 (0)