From 66371f591ae8a0e6ac7856881373c7dbf4b026db Mon Sep 17 00:00:00 2001 From: tayttt Date: Fri, 26 Jun 2026 01:16:52 +0800 Subject: [PATCH] feat: restrict advanced system settings --- .../BusinessConfigManager.cs | 1 - .../ViewModels/TreeMenuViewModel.cs | 6 + .../Views/TitleView.xaml | 8 +- .../config/client-settings.json | 3 +- .../ViewModels/SystemSettingsViewModel.cs | 123 +++++++++++++----- .../Views/SystemSettingsView.xaml | 84 ++++++------ 6 files changed, 151 insertions(+), 74 deletions(-) diff --git a/Txgy.EWS.Client.Common/BusinessConfigManager.cs b/Txgy.EWS.Client.Common/BusinessConfigManager.cs index 5d1f76f..2a08d9d 100644 --- a/Txgy.EWS.Client.Common/BusinessConfigManager.cs +++ b/Txgy.EWS.Client.Common/BusinessConfigManager.cs @@ -312,7 +312,6 @@ namespace Txgy.EWS.Client.Common Require(config.Database?.Tables?.PostWaveDataTable, "database.tables.postWaveDataTable"); Require(config.Database?.Tables?.PostFocalmechanismTable, "database.tables.postFocalmechanismTable"); GetConnectionStringFromConfig(config, "TencetnMySQL"); - GetConnectionStringFromConfig(config, "NasMySQL"); DateTime.Parse(config.Report.DailyReportStartTime); } diff --git a/Txgy.EWS.Client.MainModule/ViewModels/TreeMenuViewModel.cs b/Txgy.EWS.Client.MainModule/ViewModels/TreeMenuViewModel.cs index 2a5b17d..a04b1b0 100644 --- a/Txgy.EWS.Client.MainModule/ViewModels/TreeMenuViewModel.cs +++ b/Txgy.EWS.Client.MainModule/ViewModels/TreeMenuViewModel.cs @@ -15,6 +15,7 @@ namespace Txgy.EWS.Client.MainModule.ViewModels public class TreeMenuViewModel : BindableBase { private const string SystemSettingsTargetView = "SystemSettingsView"; + private const string AdvancedSystemSettingsTargetView = "SystemSettingsAdvanced"; public List Menus { get; set; } = new List(); @@ -45,6 +46,11 @@ namespace Txgy.EWS.Client.MainModule.ViewModels { foreach (var item in sub) { + if (string.Equals(item.TargetView, AdvancedSystemSettingsTargetView, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + MenuItemModel mm = new MenuItemModel(_regionManager) { MenuHeader = item.MenuHeader, diff --git a/Txgy.EWS.Client.PageModule/Views/TitleView.xaml b/Txgy.EWS.Client.PageModule/Views/TitleView.xaml index 43047cf..c00f081 100644 --- a/Txgy.EWS.Client.PageModule/Views/TitleView.xaml +++ b/Txgy.EWS.Client.PageModule/Views/TitleView.xaml @@ -211,6 +211,8 @@ VerticalAlignment="Center" d:Text="10000" FontSize="18" + FontWeight="Bold" + Foreground="Blue" Text="{Binding ReceivedEventCount}" /> @@ -222,6 +224,8 @@ VerticalAlignment="Center" d:Text="10000" FontSize="18" + FontWeight="Bold" + Foreground="Blue" Text="{Binding AlarmedEventCount}" /> @@ -232,7 +236,9 @@ diff --git a/Txgy.EWS.Client.Start/config/client-settings.json b/Txgy.EWS.Client.Start/config/client-settings.json index 8efcb30..1483c46 100644 --- a/Txgy.EWS.Client.Start/config/client-settings.json +++ b/Txgy.EWS.Client.Start/config/client-settings.json @@ -25,8 +25,7 @@ }, "database": { "connections": { - "TencetnMySQL": "Data Source=bj-cdb-q64mbxr6.sql.tencentcdb.com;Port=60027;Database=yuwu2026;User=yuwudba;Password=Yw123456;SslMode = none;", - "NasMySQL": "Data Source=tayfx.work;Port=60027;Database=YuwuN1100;User=yuwudba;Password=Yw123456;SslMode = none;" + "TencetnMySQL": "Data Source=bj-cdb-q64mbxr6.sql.tencentcdb.com;Port=60027;Database=yuwu2026;User=yuwudba;Password=Yw123456;SslMode = none;" }, "tables": { "realtimeResultTable": "realtimeeventresult", diff --git a/Txgy.EWS.Client.SysModule/ViewModels/SystemSettingsViewModel.cs b/Txgy.EWS.Client.SysModule/ViewModels/SystemSettingsViewModel.cs index 2ce47a8..93a6f29 100644 --- a/Txgy.EWS.Client.SysModule/ViewModels/SystemSettingsViewModel.cs +++ b/Txgy.EWS.Client.SysModule/ViewModels/SystemSettingsViewModel.cs @@ -4,15 +4,26 @@ using Prism.Mvvm; using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; +using System.Windows; using System.Windows.Input; using System.Windows.Media; using Txgy.EWS.Client.Common; using Txgy.EWS.Client.Common.MessageEvents; +using Txgy.EWS.Client.Entity; namespace Txgy.EWS.Client.SysModule.ViewModels { public class SystemSettingsViewModel : BindableBase { + private const string AdvancedSettingsTargetView = "SystemSettingsAdvanced"; + private static readonly string[] AdvancedSettingsFallbackTargetViews = + { + "MenuManagementView", + "RoleManagementView", + "UserManagementView" + }; + private readonly IEventAggregator _eventAggregator; private string _statusMessage; private Brush _statusBrush = Brushes.Gray; @@ -20,6 +31,7 @@ namespace Txgy.EWS.Client.SysModule.ViewModels public SystemSettingsViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; + CanEditAdvancedSettings = HasAdvancedSettingsPermission(); ReloadFromConfig(); } @@ -37,6 +49,9 @@ namespace Txgy.EWS.Client.SysModule.ViewModels set => SetProperty(ref _statusBrush, value); } + public bool CanEditAdvancedSettings { get; } + public Visibility AdvancedSettingsVisibility => CanEditAdvancedSettings ? Visibility.Visible : Visibility.Collapsed; + public string ApiDomain { get; set; } public string AlarmSetting { get; set; } public string AlarmLevelConfig { get; set; } @@ -56,7 +71,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels public string DataLookbackHours { get; set; } public string DataCacheTimeLenMins { get; set; } public string TencentMySql { get; set; } - public string NasMySql { get; set; } public string RealtimeResultTable { get; set; } public string RealtimeWaveDataTable { get; set; } public string RealtimeFocalmechanismTable { get; set; } @@ -96,7 +110,7 @@ namespace Txgy.EWS.Client.SysModule.ViewModels try { var previousConfig = BusinessConfigManager.Current; - var config = BuildConfig(); + var config = BuildConfig(previousConfig); var savedConfig = BusinessConfigManager.Save(config); var shouldReloadWarningData = ShouldReloadWarningData(previousConfig, savedConfig); GlobalConfig.ApplyBusinessConfig(savedConfig); @@ -145,7 +159,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels DataLookbackHours = config.Runtime.DataLookbackHours.ToString("0.##", CultureInfo.InvariantCulture); DataCacheTimeLenMins = config.Runtime.DataCacheTimeLenMins.ToString(CultureInfo.InvariantCulture); TencentMySql = GetConnection(config, "TencetnMySQL"); - NasMySql = GetConnection(config, "NasMySQL"); RealtimeResultTable = config.Database.Tables.RealtimeResultTable; RealtimeWaveDataTable = config.Database.Tables.RealtimeWaveDataTable; RealtimeFocalmechanismTable = config.Database.Tables.RealtimeFocalmechanismTable; @@ -166,19 +179,18 @@ namespace Txgy.EWS.Client.SysModule.ViewModels RaiseAllSettingPropertiesChanged(); } - private BusinessConfig BuildConfig() + private BusinessConfig BuildConfig(BusinessConfig currentConfig) { DateTime.Parse(Require(DailyReportStartTime, "日报起始时间")); var dataLookbackHours = ParseDouble(DataLookbackHours, "数据回看时长"); DataCacheTimeLenMins = ((int)Math.Round(dataLookbackHours * 60.0)).ToString(CultureInfo.InvariantCulture); + var endpointSettings = BuildEndpointSettings(currentConfig); + var databaseSettings = BuildDatabaseSettings(currentConfig); return new BusinessConfig { - Endpoints = new EndpointSettings - { - ApiDomain = Require(ApiDomain, "API 域名") - }, + Endpoints = endpointSettings, Paths = new PathSettings { AlarmSetting = Require(AlarmSetting, "报警配置"), @@ -190,35 +202,19 @@ namespace Txgy.EWS.Client.SysModule.ViewModels DwgJsonSetting = Require(DwgJsonSetting, "DWG 图层配置"), WavesMseedFilePath = Require(WavesMseedFilePath, "Mseed 缓存目录"), WavesTxtFilePath = Require(WavesTxtFilePath, "Txt 缓存目录"), - LocalSqLiteDb = Require(LocalSqLiteDb, "本地 SQLite"), + LocalSqLiteDb = CanEditAdvancedSettings ? Require(LocalSqLiteDb, "本地 SQLite") : currentConfig.Paths.LocalSqLiteDb, DwgSettings = EmptyToNull(DwgSettings), CadSettingsFileName = EmptyToNull(CadSettingsFileName) }, Runtime = new RuntimeSettings { - IsDesign = IsDesign, - IsRealtime = IsRealtime, + IsDesign = CanEditAdvancedSettings ? IsDesign : currentConfig.Runtime.IsDesign, + IsRealtime = CanEditAdvancedSettings ? IsRealtime : currentConfig.Runtime.IsRealtime, RefreshInterval = ParseInt(RefreshInterval, "刷新间隔"), DataLookbackHours = dataLookbackHours, DataCacheTimeLenMins = ParseInt(DataCacheTimeLenMins, "数据缓存时长") }, - Database = new DatabaseSettings - { - Connections = new Dictionary - { - { "TencetnMySQL", Require(TencentMySql, "腾讯 MySQL") }, - { "NasMySQL", Require(NasMySql, "NAS MySQL") } - }, - Tables = new TableSettings - { - RealtimeResultTable = Require(RealtimeResultTable, "实时结果表"), - RealtimeWaveDataTable = Require(RealtimeWaveDataTable, "实时波形表"), - RealtimeFocalmechanismTable = Require(RealtimeFocalmechanismTable, "实时震源机制表"), - PostResultTable = Require(PostResultTable, "后处理结果表"), - PostWaveDataTable = Require(PostWaveDataTable, "后处理波形表"), - PostFocalmechanismTable = Require(PostFocalmechanismTable, "后处理震源机制表") - } - }, + Database = databaseSettings, Branding = new BrandingSettings { CommpanyName = Require(CommpanyName, "公司名称"), @@ -242,6 +238,59 @@ namespace Txgy.EWS.Client.SysModule.ViewModels }; } + private EndpointSettings BuildEndpointSettings(BusinessConfig currentConfig) + { + return new EndpointSettings + { + ApiDomain = CanEditAdvancedSettings ? Require(ApiDomain, "API 域名") : currentConfig.Endpoints.ApiDomain + }; + } + + private DatabaseSettings BuildDatabaseSettings(BusinessConfig currentConfig) + { + if (!CanEditAdvancedSettings) + { + return new DatabaseSettings + { + Connections = new Dictionary + { + { "TencetnMySQL", GetConnection(currentConfig, "TencetnMySQL") } + }, + Tables = CopyTableSettings(currentConfig.Database.Tables) + }; + } + + return new DatabaseSettings + { + Connections = new Dictionary + { + { "TencetnMySQL", Require(TencentMySql, "腾讯 MySQL") } + }, + Tables = new TableSettings + { + RealtimeResultTable = Require(RealtimeResultTable, "实时结果表"), + RealtimeWaveDataTable = Require(RealtimeWaveDataTable, "实时波形表"), + RealtimeFocalmechanismTable = Require(RealtimeFocalmechanismTable, "实时震源机制表"), + PostResultTable = Require(PostResultTable, "后处理结果表"), + PostWaveDataTable = Require(PostWaveDataTable, "后处理波形表"), + PostFocalmechanismTable = Require(PostFocalmechanismTable, "后处理震源机制表") + } + }; + } + + private TableSettings CopyTableSettings(TableSettings source) + { + return new TableSettings + { + RealtimeResultTable = source.RealtimeResultTable, + RealtimeWaveDataTable = source.RealtimeWaveDataTable, + RealtimeFocalmechanismTable = source.RealtimeFocalmechanismTable, + PostResultTable = source.PostResultTable, + PostWaveDataTable = source.PostWaveDataTable, + PostFocalmechanismTable = source.PostFocalmechanismTable + }; + } + private string GetConnection(BusinessConfig config, string name) { if (config.Database.Connections != null && config.Database.Connections.TryGetValue(name, out var value)) @@ -252,6 +301,23 @@ namespace Txgy.EWS.Client.SysModule.ViewModels return string.Empty; } + private bool HasAdvancedSettingsPermission() + { + var menus = GlobalData.CurrentUserInfo?.Menus; + if (menus == null) + { + return false; + } + + return ContainsTargetView(menus, AdvancedSettingsTargetView) || + AdvancedSettingsFallbackTargetViews.Any(targetView => ContainsTargetView(menus, targetView)); + } + + private bool ContainsTargetView(IEnumerable menus, string targetView) + { + return menus.Any(menu => string.Equals(menu.TargetView, targetView, StringComparison.OrdinalIgnoreCase)); + } + private string Require(string value, string name) { if (string.IsNullOrWhiteSpace(value)) @@ -314,7 +380,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels RaisePropertyChanged(nameof(DataLookbackHours)); RaisePropertyChanged(nameof(DataCacheTimeLenMins)); RaisePropertyChanged(nameof(TencentMySql)); - RaisePropertyChanged(nameof(NasMySql)); RaisePropertyChanged(nameof(RealtimeResultTable)); RaisePropertyChanged(nameof(RealtimeWaveDataTable)); RaisePropertyChanged(nameof(RealtimeFocalmechanismTable)); diff --git a/Txgy.EWS.Client.SysModule/Views/SystemSettingsView.xaml b/Txgy.EWS.Client.SysModule/Views/SystemSettingsView.xaml index dcc5024..3bd92c9 100644 --- a/Txgy.EWS.Client.SysModule/Views/SystemSettingsView.xaml +++ b/Txgy.EWS.Client.SysModule/Views/SystemSettingsView.xaml @@ -60,18 +60,7 @@ - - - - - - - - - - - - + @@ -82,20 +71,14 @@ - - - - - + + + + - - - - - - - + + @@ -137,8 +120,6 @@ - - @@ -147,15 +128,38 @@ - + + + + + + + + + + + + + + + + + + + + + + + + @@ -165,20 +169,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + +