using System; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Threading; using TeamAAS.Logging; namespace TeamAAS.Dialogs.Dialogs { /// /// 日志条目详情窗(由实时日志控件 LogView 双击弹出): /// 显示 类别 / 时间 / 来源(公共=[source],插件=[流程][任务])/ 插件详细度 / 完整内容,支持一键复制。 /// public partial class LogDetailWindow { private readonly LogEntry _entry; public LogDetailWindow(LogEntry entry) { InitializeComponent(); UiScaler.Attach(this); // 分辨率/DPI 自适应 _entry = entry; Populate(); } private void Populate() { var e = _entry; if (e == null) { MessageText.Text = ""; return; } Title = "日志详情 - " + e.CategoryText; CategoryText.Text = e.CategoryText; CategoryBadge.Background = CategoryBrush(e.Category); TimeText.Text = e.Time.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 来源:公共日志显示 [ProductManager] 之类,插件显示 [流程][任务] SourceValue.Text = string.IsNullOrWhiteSpace(e.OriginText) ? "—" : e.OriginText; if (e.IsPlugin) { FlowRow.Visibility = Visibility.Visible; FlowValue.Text = e.Flow + " / " + e.Task; LevelRow.Visibility = Visibility.Visible; LevelValue.Text = e.Level + " 级(" + (e.Tier == 2 ? "常规" : "详细") + " · " + e.TierText + ")"; } else { FlowRow.Visibility = Visibility.Collapsed; LevelRow.Visibility = Visibility.Collapsed; } MessageText.Text = e.Message; } private static Brush CategoryBrush(LogLevel category) { string hex; switch (category) { case LogLevel.Warning: hex = "#FF9800"; break; case LogLevel.Error: hex = "#F44336"; break; default: hex = "#2D6CDF"; break; } var brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex)); brush.Freeze(); return brush; } private string BuildFullText() { var e = _entry; if (e == null) return ""; var sb = new StringBuilder(); sb.Append("[类别] ").Append(e.CategoryText).AppendLine(); sb.Append("[时间] ").Append(e.Time.ToString("yyyy-MM-dd HH:mm:ss.fff")).AppendLine(); sb.Append("[来源] ").Append(string.IsNullOrWhiteSpace(e.OriginText) ? "—" : e.OriginText).AppendLine(); if (e.IsPlugin) { sb.Append("[流程/任务] ").Append(e.Flow).Append(" / ").Append(e.Task).AppendLine(); sb.Append("[详细度] ").Append(e.Level).Append(" 级 / ").Append(e.TierText).AppendLine(); } sb.Append("[内容]").AppendLine(); sb.Append(e.Message); return sb.ToString(); } private void BtnCopyMessage_Click(object sender, RoutedEventArgs e) => Copy(_entry?.Message, BtnCopyMessage, "复制内容"); private void BtnCopyAll_Click(object sender, RoutedEventArgs e) => Copy(BuildFullText(), BtnCopyAll, "复制全部"); private static void Copy(string text, Button button, string restoreLabel) { if (string.IsNullOrEmpty(text)) return; try { Clipboard.SetText(text); button.Content = "已复制"; var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1.5) }; timer.Tick += (s, args) => { button.Content = restoreLabel; timer.Stop(); }; timer.Start(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("[LogDetailWindow] copy failed: " + ex.Message); } } private void BtnClose_Click(object sender, RoutedEventArgs e) => Close(); } }