diff --git a/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor b/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor index 1aa36e044..7ca69bc97 100644 --- a/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor +++ b/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor @@ -8,6 +8,10 @@ }
+ @if (IsUploadButtonAtFirst && CheckCanUpload()) + { + @RenderAdd + } @foreach (var item in GetUploadFiles()) {
@@ -35,17 +39,22 @@ }
} - @if (CheckCanUpload()) + @if (!IsUploadButtonAtFirst && CheckCanUpload()) { -
-
- - - -
-
+ @RenderAdd }
+ +@code { + RenderFragment RenderAdd => + @
+
+ + + +
+
; +} diff --git a/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs b/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs index 9f0fd407c..ca0d79c6e 100644 --- a/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs +++ b/src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs @@ -98,6 +98,12 @@ public partial class AvatarUpload [Parameter] public string? InvalidStatusIcon { get; set; } + /// + /// 获得/设置 继续上传按钮是否在列表前 默认 false + /// + [Parameter] + public bool IsUploadButtonAtFirst { get; set; } + [Inject] [NotNull] private IIconTheme? IconTheme { get; set; } diff --git a/src/BootstrapBlazor/Components/Upload/CardUpload.razor b/src/BootstrapBlazor/Components/Upload/CardUpload.razor index b57891eac..9a02c28b9 100644 --- a/src/BootstrapBlazor/Components/Upload/CardUpload.razor +++ b/src/BootstrapBlazor/Components/Upload/CardUpload.razor @@ -8,6 +8,10 @@ }
+ @if (IsUploadButtonAtFirst && CheckCanUpload()) + { + @RenderAdd + } @foreach (var item in GetUploadFiles()) {
@@ -66,18 +70,9 @@
} - @if (CheckCanUpload()) + @if (!IsUploadButtonAtFirst && CheckCanUpload()) { -
-
- @if (!IsDisabled) - { - - - - } -
-
+ @RenderAdd }
@@ -87,3 +82,17 @@ }
+ +@code { + RenderFragment RenderAdd => + @
+
+ @if (!IsDisabled) + { + + + + } +
+
; +} diff --git a/src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs b/src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs index 82bac0881..4b1461b66 100644 --- a/src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs +++ b/src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs @@ -95,6 +95,12 @@ public partial class CardUpload [Parameter] public bool ShowDeletedButton { get; set; } = true; + /// + /// 获得/设置 继续上传按钮是否在列表前 默认 false + /// + [Parameter] + public bool IsUploadButtonAtFirst { get; set; } + [Inject] [NotNull] private IIconTheme? IconTheme { get; set; } diff --git a/src/BootstrapBlazor/wwwroot/modules/upload.js b/src/BootstrapBlazor/wwwroot/modules/upload.js index 922b27340..97e0ddaa5 100644 --- a/src/BootstrapBlazor/wwwroot/modules/upload.js +++ b/src/BootstrapBlazor/wwwroot/modules/upload.js @@ -15,7 +15,6 @@ export function init(id) { inputFile.click() }) - //阻止浏览器默认行为 EventHandler.on(document, "dragleave", preventHandler) EventHandler.on(document, 'drop', preventHandler) EventHandler.on(document, 'dragenter', preventHandler) @@ -23,15 +22,12 @@ export function init(id) { EventHandler.on(el, 'drop', e => { try { - //获取文件对象 const fileList = e.dataTransfer.files - - //检测是否是拖拽文件到页面的操作 if (fileList.length === 0) { return false } - inputFile.files = e.dataTransfer.files + inputFile.files = fileList const event = new Event('change', { bubbles: true }) inputFile.dispatchEvent(event) } catch (e) { @@ -69,9 +65,9 @@ export function dispose(id) { const upload = Data.get(id) Data.remove(id) - const el = upload.el - const preventHandler = upload.preventHandler if (upload) { + const { el, preventHandler } = upload; + EventHandler.off(el, 'click') EventHandler.off(el, 'drop') EventHandler.off(el, 'paste') diff --git a/test/UnitTest/Components/UploadTest.cs b/test/UnitTest/Components/UploadTest.cs index 901fd47bd..98cf5fb01 100644 --- a/test/UnitTest/Components/UploadTest.cs +++ b/test/UnitTest/Components/UploadTest.cs @@ -205,6 +205,12 @@ public class UploadTest : BootstrapBlazorTestBase { pb.Add(a => a.IsDisabled, true); }); + + // IsUploadButtonAtFirst + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.IsUploadButtonAtFirst, true); + }); } [Fact] @@ -760,6 +766,12 @@ public class UploadTest : BootstrapBlazorTestBase { new("test.png") }))); + + // IsUploadButtonAtFirst + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.IsUploadButtonAtFirst, true); + }); } [Fact]