From 4bff6e1e8777aecfcf07722d9e27e35bdb1e5a90 Mon Sep 17 00:00:00 2001 From: ssss <111@qq.com> Date: Fri, 3 Jul 2026 14:29:18 +0800 Subject: [PATCH] =?UTF-8?q?chore(wpf):=20=E4=B8=BAImportViewModel=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ImportViewModel.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/WCTDataMiner.Wpf/ViewModels/ImportViewModel.cs b/src/WCTDataMiner.Wpf/ViewModels/ImportViewModel.cs index 081b1f8..3aeca9d 100644 --- a/src/WCTDataMiner.Wpf/ViewModels/ImportViewModel.cs +++ b/src/WCTDataMiner.Wpf/ViewModels/ImportViewModel.cs @@ -1,5 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Microsoft.Extensions.Logging; using Microsoft.Win32; using System.Collections.ObjectModel; using WCTDataMiner.Core.Services; @@ -12,6 +13,7 @@ namespace WCTDataMiner.Wpf.ViewModels; public partial class ImportViewModel : ObservableObject { private readonly ParseService _parseService; + private readonly ILogger _logger; [ObservableProperty] private string _selectedPath = ""; @@ -31,9 +33,10 @@ public partial class ImportViewModel : ObservableObject [ObservableProperty] private ObservableCollection _importResults = new(); - public ImportViewModel(ParseService parseService) + public ImportViewModel(ParseService parseService, ILogger logger) { _parseService = parseService; + _logger = logger; } [RelayCommand] @@ -50,6 +53,7 @@ public partial class ImportViewModel : ObservableObject { SelectedPath = dialog.FileName; StatusMessage = $"已选择文件: {System.IO.Path.GetFileName(SelectedPath)}"; + _logger.LogDebug("用户选择文件: {FilePath}", SelectedPath); } } @@ -66,6 +70,7 @@ public partial class ImportViewModel : ObservableObject { SelectedPath = dialog.FolderName; StatusMessage = $"已选择目录: {System.IO.Path.GetFileName(SelectedPath)}"; + _logger.LogDebug("用户选择目录: {FolderPath}, 递归={IsRecursive}", SelectedPath, IsRecursive); } } @@ -82,6 +87,8 @@ public partial class ImportViewModel : ObservableObject ImportResults.Clear(); StatusMessage = "正在导入..."; + _logger.LogInformation("开始导入: {Path}, 递归={IsRecursive}", SelectedPath, IsRecursive); + try { if (System.IO.File.Exists(SelectedPath)) @@ -90,6 +97,8 @@ public partial class ImportViewModel : ObservableObject var report = await _parseService.ParseFileAsync(SelectedPath); ImportResults.Add(new ImportResultItem(report)); StatusMessage = $"导入完成: Qfod={report.QfodCount}, Ploss={report.PlossCount}, 错误={report.ErrorCount}"; + _logger.LogInformation("单文件导入完成: {FileName}, Qfod={Qfod}, Ploss={Ploss}, 错误={Errors}", + report.FileName, report.QfodCount, report.PlossCount, report.ErrorCount); } else if (System.IO.Directory.Exists(SelectedPath)) { @@ -107,15 +116,19 @@ public partial class ImportViewModel : ObservableObject } StatusMessage = $"导入完成: {reports.Count} 个文件, Qfod={totalQfod}, Ploss={totalPloss}, 错误={totalErrors}"; + _logger.LogInformation("目录导入完成: {FileCount} 个文件, Qfod={Qfod}, Ploss={Ploss}, 错误={Errors}", + reports.Count, totalQfod, totalPloss, totalErrors); } else { StatusMessage = "路径不存在"; + _logger.LogWarning("导入路径不存在: {Path}", SelectedPath); } } catch (Exception ex) { StatusMessage = $"导入失败: {ex.Message}"; + _logger.LogError(ex, "导入失败: {Path}", SelectedPath); } finally {