Skip to content

Commit ddac24f

Browse files
committed
feat: 添加附件支持和拖放功能到 XSender 组件
1 parent c5cd7c9 commit ddac24f

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/AntDesign.X.Blazor/Components/XSender.razor

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424
</div>
2525
}
2626

27-
<div class="antdx-sender-editor">
27+
<div class="antdx-sender-editor" @ref="Editor">
28+
@if (AttachmentsEnabled)
29+
{
30+
<InputFile class="antdx-sender-file-input"
31+
multiple="@Multiple"
32+
disabled="@(Disabled || ReadOnly)"
33+
accept="@Accept"
34+
@attributes="InputAttributes"
35+
OnChange="@HandleFiles" />
36+
}
37+
2838
@if (ShowAttachmentsPanel)
2939
{
3040
<div class="antdx-sender-attachments-panel">
@@ -192,6 +202,8 @@
192202

193203
@code {
194204
private IJSObjectReference? _module;
205+
private IJSObjectReference? _senderDropZone;
206+
private ElementReference Editor;
195207
private ElementReference TextArea;
196208

197209
[Parameter] public string? Value { get; set; }
@@ -283,6 +295,15 @@
283295
private DotNetObjectReference<XSender>? _speechRef;
284296
private string? _speechBaseValue;
285297

298+
private IDictionary<string, object>? InputAttributes =>
299+
Directory
300+
? new Dictionary<string, object>
301+
{
302+
["webkitdirectory"] = true,
303+
["directory"] = true,
304+
}
305+
: null;
306+
286307
protected override async Task OnAfterRenderAsync(bool firstRender)
287308
{
288309
if (firstRender)
@@ -299,6 +320,25 @@
299320
{
300321
return;
301322
}
323+
324+
if (AttachmentsEnabled)
325+
{
326+
try
327+
{
328+
_senderDropZone = await _module.InvokeAsync<IJSObjectReference>(
329+
"wireAttachmentDropZone",
330+
Editor,
331+
AttachmentsDragHover,
332+
AttachmentsPastable,
333+
Disabled || ReadOnly);
334+
}
335+
catch (JSException)
336+
{
337+
}
338+
catch (InvalidOperationException)
339+
{
340+
}
341+
}
302342
}
303343

304344
await ResizeAsync();
@@ -310,6 +350,11 @@
310350
_speechRef?.Dispose();
311351
_speechRef = null;
312352

353+
if (_senderDropZone is not null)
354+
{
355+
await _senderDropZone.DisposeAsync();
356+
}
357+
313358
if (_module is not null)
314359
{
315360
await _module.DisposeAsync();
@@ -456,6 +501,12 @@
456501
files = files.Take(MaxAttachments.Value).ToArray();
457502
}
458503

504+
if (files.Count > 0)
505+
{
506+
_attachmentsPanelTouched = false;
507+
_attachmentsPanelOpen = true;
508+
}
509+
459510
await OnFilesSelected.InvokeAsync(files);
460511
}
461512

src/AntDesign.X.Blazor/wwwroot/css/antdesign-x.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@
609609
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.10);
610610
}
611611

612+
.antdx-sender-editor.antdx-attachments-drag-over {
613+
border-color: rgba(22, 119, 255, 0.62);
614+
background: color-mix(in srgb, var(--antdx-component-bg) 88%, var(--antdx-color-primary));
615+
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.10);
616+
}
617+
612618
.antdx-sender-header,
613619
.antdx-sender-custom-footer,
614620
.antdx-sender-footer {

0 commit comments

Comments
 (0)