Skip to content

Commit 6b47ea9

Browse files
committed
refactor: 代码重构增加基类
1 parent 4b0ff0e commit 6b47ea9

16 files changed

+223
-438
lines changed

src/BootstrapBlazor/Components/Upload/ButtonUpload.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace BootstrapBlazor.Components
22
@typeparam TValue
3-
@inherits UploadBase<TValue>
3+
@inherits FileListUploadBase<TValue>
44

55
@if (IsShowLabel)
66
{
@@ -16,11 +16,12 @@
1616
OnGetFileFormat="@OnGetFileFormat" OnCancel="OnCancel" CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
1717
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
1818
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
19-
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete"
19+
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete"
2020
FileIconExcel="@FileIconExcel" FileIconDocx="@FileIconDocx" FileIconPPT="@FileIconPPT"
2121
FileIconAudio="@FileIconAudio" FileIconVideo="@FileIconVideo"
2222
FileIconCode="@FileIconCode" FileIconPdf="@FileIconPdf" FileIconZip="@FileIconZip"
23-
FileIconArchive="@FileIconArchive" FileIconImage="@FileIconImage" FileIconFile="@FileIconFile"></UploadPreviewList>
23+
FileIconArchive="@FileIconArchive" FileIconImage="@FileIconImage" FileIconFile="@FileIconFile">
24+
</UploadPreviewList>
2425
}
2526
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
2627
</div>

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

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ public partial class ButtonUpload<TValue>
1919
[Parameter]
2020
public string? LoadingIcon { get; set; }
2121

22-
/// <summary>
23-
/// 获得/设置 下载按钮图标
24-
/// </summary>
25-
[Parameter]
26-
public string? DownloadIcon { get; set; }
27-
2822
/// <summary>
2923
/// 获得/设置 上传失败状态图标
3024
/// </summary>
@@ -37,12 +31,6 @@ public partial class ButtonUpload<TValue>
3731
[Parameter]
3832
public string? ValidStatusIcon { get; set; }
3933

40-
/// <summary>
41-
/// 获得/设置 删除按钮图标
42-
/// </summary>
43-
[Parameter]
44-
public string? DeleteIcon { get; set; }
45-
4634
/// <summary>
4735
/// 获得/设置 浏览按钮图标
4836
/// </summary>
@@ -92,104 +80,10 @@ public partial class ButtonUpload<TValue>
9280
[Parameter]
9381
public Func<string?, string>? OnGetFileFormat { get; set; }
9482

95-
/// <summary>
96-
/// 获得/设置 是否显示下载按钮 默认 false
97-
/// </summary>
98-
[Parameter]
99-
public bool ShowDownloadButton { get; set; }
100-
101-
/// <summary>
102-
/// 获得/设置 点击下载按钮回调方法 默认 null
103-
/// </summary>
104-
[Parameter]
105-
public Func<UploadFile, Task>? OnDownload { get; set; }
106-
107-
/// <summary>
108-
/// 获得/设置 取消图标
109-
/// </summary>
110-
[Parameter]
111-
public string? CancelIcon { get; set; }
112-
113-
/// <summary>
114-
/// 获得/设置 点击取消按钮回调此方法 默认 null
115-
/// </summary>
116-
[Parameter]
117-
public Func<UploadFile, Task>? OnCancel { get; set; }
118-
119-
/// <summary>
120-
/// 获得/设置 Excel 类型文件图标
121-
/// </summary>
122-
[Parameter]
123-
public string? FileIconExcel { get; set; }
124-
125-
/// <summary>
126-
/// 获得/设置 Excel 类型文件图标
127-
/// </summary>
128-
[Parameter]
129-
public string? FileIconDocx { get; set; }
130-
131-
/// <summary>
132-
/// 获得/设置 Excel 类型文件图标
133-
/// </summary>
134-
[Parameter]
135-
public string? FileIconPPT { get; set; }
136-
137-
/// <summary>
138-
/// 获得/设置 Excel 类型文件图标
139-
/// </summary>
140-
[Parameter]
141-
public string? FileIconAudio { get; set; }
142-
143-
/// <summary>
144-
/// 获得/设置 Excel 类型文件图标
145-
/// </summary>
146-
[Parameter]
147-
public string? FileIconVideo { get; set; }
148-
149-
/// <summary>
150-
/// 获得/设置 Excel 类型文件图标
151-
/// </summary>
152-
[Parameter]
153-
public string? FileIconCode { get; set; }
154-
155-
/// <summary>
156-
/// 获得/设置 Excel 类型文件图标
157-
/// </summary>
158-
[Parameter]
159-
public string? FileIconPdf { get; set; }
160-
161-
/// <summary>
162-
/// 获得/设置 Excel 类型文件图标
163-
/// </summary>
164-
[Parameter]
165-
public string? FileIconZip { get; set; }
166-
167-
/// <summary>
168-
/// 获得/设置 Excel 类型文件图标
169-
/// </summary>
170-
[Parameter]
171-
public string? FileIconArchive { get; set; }
172-
173-
/// <summary>
174-
/// 获得/设置 Excel 类型文件图标
175-
/// </summary>
176-
[Parameter]
177-
public string? FileIconImage { get; set; }
178-
179-
/// <summary>
180-
/// 获得/设置 Excel 类型文件图标
181-
/// </summary>
182-
[Parameter]
183-
public string? FileIconFile { get; set; }
184-
18583
[Inject]
18684
[NotNull]
18785
private IStringLocalizer<UploadBase<TValue>>? Localizer { get; set; }
18886

189-
[Inject]
190-
[NotNull]
191-
private IIconTheme? IconTheme { get; set; }
192-
19387
private string? ClassString => CssBuilder.Default("upload")
19488
.AddClassFromAttributes(AdditionalAttributes)
19589
.Build();
@@ -199,7 +93,7 @@ public partial class ButtonUpload<TValue>
19993
.Build();
20094

20195
/// <summary>
202-
/// OnParametersSet 方法
96+
/// <inheritdoc/>
20397
/// </summary>
20498
protected override void OnParametersSet()
20599
{
@@ -208,6 +102,4 @@ protected override void OnParametersSet()
208102
BrowserButtonText ??= Localizer[nameof(BrowserButtonText)];
209103
BrowserButtonIcon ??= IconTheme.GetIconByKey(ComponentIcons.ButtonUploadBrowserButtonIcon);
210104
}
211-
212-
private bool CheckStatus() => IsDisabled || !CanUpload();
213105
}

src/BootstrapBlazor/Components/Upload/CardUpload.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace BootstrapBlazor.Components
22
@typeparam TValue
3-
@inherits UploadBase<TValue>
3+
@inherits FileListUploadBase<TValue>
44

55
@if (IsShowLabel)
66
{

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

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public partial class CardUpload<TValue>
3030

3131
private bool ShowPreviewList => Files.Count != 0;
3232

33-
private List<string?> PreviewList => Files.Select(i => i.PrevUrl).ToList();
33+
private List<string?> PreviewList => [.. Files.Select(i => i.PrevUrl)];
3434

3535
private string? GetDeleteButtonDisabledString(UploadFile item) => (!IsDisabled && item.Uploaded) ? null : "disabled";
3636

@@ -72,24 +72,12 @@ public partial class CardUpload<TValue>
7272
[Parameter]
7373
public string? StatusIcon { get; set; }
7474

75-
/// <summary>
76-
/// 获得/设置 删除图标
77-
/// </summary>
78-
[Parameter]
79-
public string? DeleteIcon { get; set; }
80-
8175
/// <summary>
8276
/// 获得/设置 移除图标
8377
/// </summary>
8478
[Parameter]
8579
public string? RemoveIcon { get; set; }
8680

87-
/// <summary>
88-
/// 获得/设置 下载图标
89-
/// </summary>
90-
[Parameter]
91-
public string? DownloadIcon { get; set; }
92-
9381
/// <summary>
9482
/// 获得/设置 放大图标
9583
/// </summary>
@@ -110,124 +98,24 @@ public partial class CardUpload<TValue>
11098
[ExcludeFromCodeCoverage]
11199
public bool ShowDeletedButton { get; set; } = true;
112100

113-
/// <summary>
114-
/// 获得/设置 是否显示删除按钮 默认 true 显示
115-
/// </summary>
116-
[Parameter]
117-
public bool ShowDeleteButton { get; set; } = true;
118-
119101
/// <summary>
120102
/// 获得/设置 继续上传按钮是否在列表前 默认 false
121103
/// </summary>
122104
[Parameter]
123105
public bool IsUploadButtonAtFirst { get; set; }
124106

125-
/// <summary>
126-
/// 获得/设置 是否显示下载按钮 默认 false
127-
/// </summary>
128-
[Parameter]
129-
public bool ShowDownloadButton { get; set; }
130-
131-
/// <summary>
132-
/// 获得/设置 点击下载按钮回调方法 默认 null
133-
/// </summary>
134-
[Parameter]
135-
public Func<UploadFile, Task>? OnDownload { get; set; }
136-
137-
/// <summary>
138-
/// 获得/设置 点击取消按钮回调此方法 默认 null
139-
/// </summary>
140-
[Parameter]
141-
public Func<UploadFile, Task>? OnCancel { get; set; }
142-
143107
/// <summary>
144108
/// 获得/设置 点击 Zoom 图标回调方法
145109
/// </summary>
146110
[Parameter]
147111
public Func<UploadFile, Task>? OnZoomAsync { get; set; }
148112

149-
/// <summary>
150-
/// 获得/设置 取消图标
151-
/// </summary>
152-
[Parameter]
153-
public string? CancelIcon { get; set; }
154-
155113
/// <summary>
156114
/// 获得/设置 图标文件扩展名集合 ".png"
157115
/// </summary>
158116
[Parameter]
159117
public List<string>? AllowExtensions { get; set; }
160118

161-
/// <summary>
162-
/// 获得/设置 Excel 类型文件图标
163-
/// </summary>
164-
[Parameter]
165-
public string? FileIconExcel { get; set; }
166-
167-
/// <summary>
168-
/// 获得/设置 Docx 类型文件图标
169-
/// </summary>
170-
[Parameter]
171-
public string? FileIconDocx { get; set; }
172-
173-
/// <summary>
174-
/// 获得/设置 PPT 类型文件图标
175-
/// </summary>
176-
[Parameter]
177-
public string? FileIconPPT { get; set; }
178-
179-
/// <summary>
180-
/// 获得/设置 Audio 类型文件图标
181-
/// </summary>
182-
[Parameter]
183-
public string? FileIconAudio { get; set; }
184-
185-
/// <summary>
186-
/// 获得/设置 Video 类型文件图标
187-
/// </summary>
188-
[Parameter]
189-
public string? FileIconVideo { get; set; }
190-
191-
/// <summary>
192-
/// 获得/设置 File 类型文件图标
193-
/// </summary>
194-
[Parameter]
195-
public string? FileIconCode { get; set; }
196-
197-
/// <summary>
198-
/// 获得/设置 Pdf 类型文件图标
199-
/// </summary>
200-
[Parameter]
201-
public string? FileIconPdf { get; set; }
202-
203-
/// <summary>
204-
/// 获得/设置 Zip 类型文件图标
205-
/// </summary>
206-
[Parameter]
207-
public string? FileIconZip { get; set; }
208-
209-
/// <summary>
210-
/// 获得/设置 Archive 类型文件图标
211-
/// </summary>
212-
[Parameter]
213-
public string? FileIconArchive { get; set; }
214-
215-
/// <summary>
216-
/// 获得/设置 Image 类型文件图标
217-
/// </summary>
218-
[Parameter]
219-
public string? FileIconImage { get; set; }
220-
221-
/// <summary>
222-
/// 获得/设置 File 类型文件图标
223-
/// </summary>
224-
[Parameter]
225-
public string? FileIconFile { get; set; }
226-
227-
[Inject]
228-
[NotNull]
229-
private IIconTheme? IconTheme { get; set; }
230-
231119
private string? ActionClassString => CssBuilder.Default("upload-item-actions")
232120
.AddClass("btn-browser", IsDisabled == false)
233121
.Build();
@@ -241,23 +129,8 @@ protected override void OnParametersSet()
241129

242130
AddIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadAddIcon);
243131
StatusIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadStatusIcon);
244-
DeleteIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadDeleteIcon);
245-
RemoveIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadRemoveIcon);
246-
DownloadIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadDownloadIcon);
247132
ZoomIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadZoomIcon);
248-
249-
CancelIcon ??= IconTheme.GetIconByKey(ComponentIcons.UploadCancelIcon);
250-
FileIconExcel ??= IconTheme.GetIconByKey(ComponentIcons.FileIconExcel);
251-
FileIconDocx ??= IconTheme.GetIconByKey(ComponentIcons.FileIconDocx);
252-
FileIconPPT ??= IconTheme.GetIconByKey(ComponentIcons.FileIconPPT);
253-
FileIconAudio ??= IconTheme.GetIconByKey(ComponentIcons.FileIconAudio);
254-
FileIconVideo ??= IconTheme.GetIconByKey(ComponentIcons.FileIconVideo);
255-
FileIconCode ??= IconTheme.GetIconByKey(ComponentIcons.FileIconCode);
256-
FileIconPdf ??= IconTheme.GetIconByKey(ComponentIcons.FileIconPdf);
257-
FileIconZip ??= IconTheme.GetIconByKey(ComponentIcons.FileIconZip);
258-
FileIconArchive ??= IconTheme.GetIconByKey(ComponentIcons.FileIconArchive);
259-
FileIconImage ??= IconTheme.GetIconByKey(ComponentIcons.FileIconImage);
260-
FileIconFile ??= IconTheme.GetIconByKey(ComponentIcons.FileIconFile);
133+
RemoveIcon ??= IconTheme.GetIconByKey(ComponentIcons.CardUploadRemoveIcon);
261134
}
262135

263136
private async Task OnCardFileDelete(UploadFile item)

src/BootstrapBlazor/Components/Upload/DropUpload.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@namespace BootstrapBlazor.Components
2-
@inherits UploadBase<string>
2+
@inherits FileListUploadBase<string>
33

44
@if (IsShowLabel)
55
{
@@ -54,7 +54,7 @@
5454
OnGetFileFormat="@OnGetFileFormat" OnCancel="OnCancel" CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
5555
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
5656
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
57-
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete"
57+
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete"
5858
FileIconExcel="@FileIconExcel" FileIconDocx="@FileIconDocx" FileIconPPT="@FileIconPPT"
5959
FileIconAudio="@FileIconAudio" FileIconVideo="@FileIconVideo"
6060
FileIconCode="@FileIconCode" FileIconPdf="@FileIconPdf" FileIconZip="@FileIconZip"

0 commit comments

Comments
 (0)