using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace AntDesign { public partial class Upload : AntDomComponentBase { [Parameter] public Func BeforeUpload { get; set; } [Parameter] public Func, Task> BeforeAllUploadAsync { get; set; } [Parameter] public Func, bool> BeforeAllUpload { get; set; } [Parameter] public string Name { get; set; } [Parameter] public string Action { get; set; } [Parameter] public bool Disabled { get; set; } [Parameter] public Dictionary Data { get; set; } [Parameter] public string ListType { get; set; } = "text"; [Parameter] public bool Directory { get; set; } [Parameter] public bool Multiple { get; set; } [Parameter] public string Accept { get; set; } [Parameter] public bool ShowUploadList { get; set; } = true; [Parameter] public List FileList { get; set; } = new List(); [Parameter] public UploadLocale Locale { get; set; } = LocaleProvider.CurrentLocale.Upload; [Parameter] public EventCallback> FileListChanged { get; set; } [Parameter] public List DefaultFileList { get; set; } = new List(); [Parameter] public Dictionary Headers { get; set; } [Parameter] public EventCallback OnSingleCompleted { get; set; } [Parameter] public EventCallback OnCompleted { get; set; } [Parameter] public EventCallback OnChange { get; set; } [Parameter] public Func> OnRemove { get; set; } [Parameter] public EventCallback OnPreview { get; set; } [Parameter] public EventCallback OnDownload { get; set; } [Parameter] public RenderFragment ChildContent { get; set; } [Parameter] public bool ShowButton { get; set; } = true; private bool IsText => ListType == "text"; private bool IsPicture => ListType == "picture"; private bool IsPictureCard => ListType == "picture-card"; private ClassMapper _listClassMapper = new ClassMapper(); protected override void OnInitialized() { base.OnInitialized(); var prefixCls = "ant-upload"; ClassMapper .Add(prefixCls) .If($"{prefixCls}-rtl", () => RTL); _listClassMapper .Add($"{prefixCls}-list") .Get(() => $"{prefixCls}-list-{ListType}") .If($"{prefixCls}-list-rtl", () => RTL); } protected override Task OnInitializedAsync() { FileList.InsertRange(0, DefaultFileList); return base.OnInitializedAsync(); } private async Task RemoveFile(UploadFileItem item) { var canRemove = OnRemove == null || await OnRemove.Invoke(item); if (canRemove) { this.FileList.Remove(item); await this.FileListChanged.InvokeAsync(this.FileList); StateHasChanged(); } } private async Task PreviewFile(UploadFileItem item) { if (item.State == UploadState.Success && OnPreview.HasDelegate) { await OnPreview.InvokeAsync(item); } } private async Task DownloadFile(UploadFileItem item) { if (item.State == UploadState.Success && OnDownload.HasDelegate) { await OnDownload.InvokeAsync(item); } } } }