From 63be26ef9ea3b0e9f29d065238294dae600c52e7 Mon Sep 17 00:00:00 2001 From: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Sun, 13 Jul 2025 13:12:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E6=A4=8D=E4=BA=86=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim/App.xaml.cs | 1 + CRSim/CRSim.csproj | 5 +- CRSim/MainWindow.xaml.cs | 5 + CRSim/Styles/Controls.xaml | 7 ++ CRSim/ViewModels/SettingsPageViewModel.cs | 124 ++++++++++++++++++++++ CRSim/Views/ScreenSimulatorPage.xaml | 11 +- CRSim/Views/ScreenSimulatorPage.xaml.cs | 5 - CRSim/Views/SettingsPage.xaml | 124 ++++++++++++++++++++++ CRSim/Views/SettingsPage.xaml.cs | 18 ++++ CRSim/Views/StationManagementPage.xaml | 22 ++-- 10 files changed, 299 insertions(+), 23 deletions(-) create mode 100644 CRSim/ViewModels/SettingsPageViewModel.cs create mode 100644 CRSim/Views/SettingsPage.xaml create mode 100644 CRSim/Views/SettingsPage.xaml.cs diff --git a/CRSim/App.xaml.cs b/CRSim/App.xaml.cs index 119e9e3..a3397b2 100644 --- a/CRSim/App.xaml.cs +++ b/CRSim/App.xaml.cs @@ -33,6 +33,7 @@ services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); PluginService.InitializePlugins(context, services, parsedOptions.ExternalPluginPath); }) .Build(); diff --git a/CRSim/CRSim.csproj b/CRSim/CRSim.csproj index 08dc072..e6923ce 100644 --- a/CRSim/CRSim.csproj +++ b/CRSim/CRSim.csproj @@ -13,7 +13,7 @@ enable None preview - 2.3.100 + 2.3.101.0 @@ -82,6 +82,9 @@ Designer + + Designer + Designer diff --git a/CRSim/MainWindow.xaml.cs b/CRSim/MainWindow.xaml.cs index 0e1fb0b..141f20b 100644 --- a/CRSim/MainWindow.xaml.cs +++ b/CRSim/MainWindow.xaml.cs @@ -29,6 +29,11 @@ public sealed partial class MainWindow : Window private void nvSample_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs e) { + if(e.IsSettingsSelected) + { + contentFrame.Navigate(typeof(Views.SettingsPage)); + return; + } if (nvSample.SelectedItem is NavigationViewItem selectedItem && selectedItem.Tag is string pageTag) { var pageType = Type.GetType($"CRSim.Views.{pageTag}"); diff --git a/CRSim/Styles/Controls.xaml b/CRSim/Styles/Controls.xaml index 32daefb..0b2b26c 100644 --- a/CRSim/Styles/Controls.xaml +++ b/CRSim/Styles/Controls.xaml @@ -7,4 +7,11 @@ + diff --git a/CRSim/ViewModels/SettingsPageViewModel.cs b/CRSim/ViewModels/SettingsPageViewModel.cs new file mode 100644 index 0000000..caf9f56 --- /dev/null +++ b/CRSim/ViewModels/SettingsPageViewModel.cs @@ -0,0 +1,124 @@ +using System.Reflection; + +namespace CRSim.ViewModels +{ + public partial class SettingsPageViewModel : ObservableObject + { + [ObservableProperty] + public partial string PageTitle { get; set; } = "设置"; + + [ObservableProperty] + public partial string AppVersion { get; set; } = ""; + + private Settings _settings; + private readonly ISettingsService _settingsService; + private readonly IDatabaseService _databaseService; + private readonly IDialogService _dialogService; + #region 偏好设置 + [ObservableProperty] + public partial string TimeOffset { get; set; } + + [ObservableProperty] + public partial string DepartureCheckInAdvanceDuration { get; set; } + + [ObservableProperty] + public partial string PassingCheckInAdvanceDuration { get; set; } + + [ObservableProperty] + public partial string StopDisplayUntilDepartureDuration { get; set; } + + [ObservableProperty] + public partial string StopDisplayFromArrivalDuration { get; set; } + + [ObservableProperty] + public partial string StopCheckInAdvanceDuration { get; set; } + + [ObservableProperty] + public partial string MaxPages { get; set; } + + [ObservableProperty] + public partial string SwitchPageSeconds { get; set; } + + [ObservableProperty] + public partial string UserKey { get; set; } + + [ObservableProperty] + public partial bool LoadTodayOnly { get; set; } + + [ObservableProperty] + public partial bool ReopenUnclosedScreensOnLoad { get; set; } + #endregion + public SettingsPageViewModel(ISettingsService settingsService, IDatabaseService databaseService, IDialogService dialogService) + { + _settingsService = settingsService; + _databaseService = databaseService; + _dialogService = dialogService; + var version = Assembly.GetExecutingAssembly().GetName().Version; + AppVersion = $"Version {version}"; + LoadSettings(); + } + + private void LoadSettings() + { + _settings = _settingsService.GetSettings(); + TimeOffset = _settings.TimeOffset.TotalMinutes.ToString(); + DepartureCheckInAdvanceDuration = _settings.DepartureCheckInAdvanceDuration.TotalMinutes.ToString(); + PassingCheckInAdvanceDuration = _settings.PassingCheckInAdvanceDuration.TotalMinutes.ToString(); + StopDisplayUntilDepartureDuration = _settings.StopDisplayUntilDepartureDuration.TotalMinutes.ToString(); + StopDisplayFromArrivalDuration = _settings.StopDisplayFromArrivalDuration.TotalMinutes.ToString(); + StopCheckInAdvanceDuration = _settings.StopCheckInAdvanceDuration.TotalMinutes.ToString(); + MaxPages = _settings.MaxPages.ToString(); + SwitchPageSeconds = _settings.SwitchPageSeconds.ToString(); + UserKey = _settings.UserKey; + LoadTodayOnly = _settings.LoadTodayOnly; + ReopenUnclosedScreensOnLoad = _settings.ReopenUnclosedScreensOnLoad; + } + + [RelayCommand] + public void Unload() + { + UpdateSettings(TimeOffset, true, value => _settings.TimeOffset = TimeSpan.FromMinutes(value)); + UpdateSettings(DepartureCheckInAdvanceDuration, false, value => _settings.DepartureCheckInAdvanceDuration = TimeSpan.FromMinutes(value)); + UpdateSettings(PassingCheckInAdvanceDuration, false, value => _settings.PassingCheckInAdvanceDuration = TimeSpan.FromMinutes(value)); + UpdateSettings(StopDisplayUntilDepartureDuration, false, value => _settings.StopDisplayUntilDepartureDuration = TimeSpan.FromMinutes(value)); + UpdateSettings(StopDisplayFromArrivalDuration, false, value => _settings.StopDisplayFromArrivalDuration = TimeSpan.FromMinutes(value)); + UpdateSettings(StopCheckInAdvanceDuration, false, value => _settings.StopCheckInAdvanceDuration = TimeSpan.FromMinutes(value)); + UpdateSettings(MaxPages, false, value => _settings.MaxPages = value); + UpdateSettings(SwitchPageSeconds, false, value => _settings.SwitchPageSeconds = value); + _settings.UserKey = UserKey; + _settings.LoadTodayOnly = LoadTodayOnly; + _settings.ReopenUnclosedScreensOnLoad = ReopenUnclosedScreensOnLoad; + _settingsService.SaveSettings(); + } + private void UpdateSettings(string input, bool allowNegative, Action updateAction) + { + if (int.TryParse(input, out int value) && (allowNegative || value >= 0)) + { + updateAction(value); + } + } + + [RelayCommand] + public async Task ClearData() + { + if (!await _dialogService.GetConfirmAsync("该操作将会清空所有数据,请否继续?")) return; + _databaseService.ClearData(); + await _databaseService.SaveData(); + } + [RelayCommand] + public async Task ExportData() + { + string? path = await _dialogService.SaveFileAsync(".json", "data"); + if (string.IsNullOrWhiteSpace(path)) return; + await _databaseService.ExportData(path); + } + [RelayCommand] + public async Task ImportData() + { + string? path = await _dialogService.GetFileAsync([".json"]); + if (string.IsNullOrWhiteSpace(path)) return; + _databaseService.ImportData(path); + await _databaseService.SaveData(); + } + } +} \ No newline at end of file diff --git a/CRSim/Views/ScreenSimulatorPage.xaml b/CRSim/Views/ScreenSimulatorPage.xaml index 5cedc5a..53d8d84 100644 --- a/CRSim/Views/ScreenSimulatorPage.xaml +++ b/CRSim/Views/ScreenSimulatorPage.xaml @@ -15,7 +15,6 @@ xmlns:models="using:CRSim.Models" xmlns:coremodels="using:CRSim.Core.Models" xmlns:pluginmodels="using:CRSim.Core.Models.Plugin" - Loaded="Page_Loaded" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewmodels:ScreenSimulatorPageViewModel}"> @@ -44,7 +43,7 @@ + Foreground="{ThemeResource TextFillColorSecondaryBrush}" VerticalAlignment="Bottom" Margin="4,0,0,0"/> @@ -53,7 +52,7 @@ - + @@ -96,12 +95,12 @@ - - + @@ -152,7 +151,7 @@ - +