工单 优化 ,增加图片
This commit is contained in:
1 parent
bf5a70597c
commit
cf2efbcb16
27 files changed
+3555
-1538
No files matched your search
@@ -1,6 +1,10 @@
|
||||
using OrderSupportTicket.Models.Api;
|
||||
using OrderSupportTicket.Models.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WPFCommon.Models;
|
||||
|
||||
namespace OrderSupportTicket.ViewModels;
|
||||
@@ -22,6 +26,7 @@ public sealed class ChatMessageViewModel : BindableBaseEx
|
||||
{
|
||||
if (dto == null)
|
||||
throw new ArgumentNullException(nameof(dto));
|
||||
Attachments = new ObservableCollection<ChatAttachmentViewModel>();
|
||||
MessageId = dto.MessageId;
|
||||
SequenceNo = dto.SequenceNo;
|
||||
SenderType = dto.SenderType;
|
||||
@@ -33,6 +38,7 @@ public sealed class ChatMessageViewModel : BindableBaseEx
|
||||
? "该消息已撤回"
|
||||
: (dto.Text ?? string.Empty);
|
||||
CreatedAt = ParseTimestamp(dto.CreatedAt);
|
||||
ReplaceAttachments(dto.Attachments);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,9 +87,18 @@ public sealed class ChatMessageViewModel : BindableBaseEx
|
||||
public string Content
|
||||
{
|
||||
get => _content;
|
||||
private set => SetValue(ref _content, value);
|
||||
private set
|
||||
{
|
||||
if (SetValue(ref _content, value))
|
||||
RaisePropertyChanged(nameof(HasText));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有可展示的文字内容。
|
||||
/// </summary>
|
||||
public bool HasText => !string.IsNullOrWhiteSpace(Content);
|
||||
|
||||
/// <summary>
|
||||
/// 消息是否已撤回。
|
||||
/// </summary>
|
||||
@@ -106,6 +121,16 @@ public sealed class ChatMessageViewModel : BindableBaseEx
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息中的公开图片附件。
|
||||
/// </summary>
|
||||
public ObservableCollection<ChatAttachmentViewModel> Attachments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含图片附件。
|
||||
/// </summary>
|
||||
public bool HasAttachments => Attachments.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// 当前消息是否由客户发送。
|
||||
/// </summary>
|
||||
@@ -120,6 +145,50 @@ public sealed class ChatMessageViewModel : BindableBaseEx
|
||||
? string.Empty
|
||||
: CreatedAt.ToLocalTime().ToString("MM-dd HH:mm", CultureInfo.CurrentCulture);
|
||||
|
||||
/// <summary>
|
||||
/// 使用服务端最新数据更新消息。短时图片地址会随每次查询变化,因此需要刷新附件。
|
||||
/// </summary>
|
||||
public void UpdateFrom(TicketMessageDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return;
|
||||
|
||||
SenderDisplayName = string.IsNullOrWhiteSpace(dto.SenderName)
|
||||
? (IsCustomer ? "我" : "客服")
|
||||
: dto.SenderName;
|
||||
IsRecalled = dto.Recalled;
|
||||
Content = dto.Recalled
|
||||
? "该消息已撤回"
|
||||
: (dto.Text ?? string.Empty);
|
||||
CreatedAt = ParseTimestamp(dto.CreatedAt);
|
||||
ReplaceAttachments(dto.Attachments);
|
||||
}
|
||||
|
||||
private void ReplaceAttachments(IEnumerable<TicketAttachmentDto> attachments)
|
||||
{
|
||||
Attachments.Clear();
|
||||
foreach (var dto in attachments ?? Enumerable.Empty<TicketAttachmentDto>())
|
||||
{
|
||||
if (dto == null)
|
||||
continue;
|
||||
Attachments.Add(new ChatAttachmentViewModel(dto));
|
||||
}
|
||||
RaisePropertyChanged(nameof(HasAttachments));
|
||||
_ = LoadAttachmentsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAttachmentsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(Attachments.Select(item => item.LoadAsync()));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 单张图片加载失败时保留占位提示,不影响文字留言显示。
|
||||
}
|
||||
}
|
||||
|
||||
private static DateTimeOffset ParseTimestamp(string value)
|
||||
{
|
||||
if (DateTimeOffset.TryParse(
|
||||
|
||||
Reference in new issue
Block a user