diff --git a/BaseFrame/App.xaml b/BaseFrame/App.xaml new file mode 100644 index 0000000..363f5af --- /dev/null +++ b/BaseFrame/App.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BaseFrame/App.xaml.cs b/BaseFrame/App.xaml.cs new file mode 100644 index 0000000..f2aa19b --- /dev/null +++ b/BaseFrame/App.xaml.cs @@ -0,0 +1,47 @@ +using BaseFrame.ViewModels; +using BaseFrame.ViewModels.Dialogs; +using BaseFrame.Views; +using BaseFrame.Views.Dialogs; +using Castle.DynamicProxy; +using ECCS.Views; +using System.Configuration; +using System.Data; +using System.Reflection; +using System.Windows; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace BaseFrame +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : PrismApplication + { + protected override Window CreateShell() + { + return Container.Resolve(); + } + protected override void OnInitialized() + { + base.OnInitialized(); + + var regionManager = Container.Resolve(); + regionManager.RequestNavigate("ShellViewManager", "MonitorView"); + } + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + //注册视图 + containerRegistry.RegisterForNavigation("MonitorView"); + containerRegistry.RegisterForNavigation("SettingView"); + containerRegistry.RegisterForNavigation("UpdateInfoView"); + //注册弹窗 + containerRegistry.RegisterDialog("MessageBox"); + + + + } + + + } + +} diff --git a/BaseFrame/AssemblyInfo.cs b/BaseFrame/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/BaseFrame/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/BaseFrame/Converters/BooleanToVisibilityConverter.cs b/BaseFrame/Converters/BooleanToVisibilityConverter.cs new file mode 100644 index 0000000..52b6c7d --- /dev/null +++ b/BaseFrame/Converters/BooleanToVisibilityConverter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace BaseFrame.Converters +{ + public class BooleanToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool input = value is bool b && b; + bool invert = parameter?.ToString()?.ToLower() == "invert"; + + if (invert) + input = !input; + + return input ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + bool output = value is Visibility v && v == Visibility.Visible; + bool invert = parameter?.ToString()?.ToLower() == "invert"; + + if (invert) + output = !output; + + return output; + } + } +} diff --git a/BaseFrame/ECCS.csproj b/BaseFrame/ECCS.csproj new file mode 100644 index 0000000..9be13d0 --- /dev/null +++ b/BaseFrame/ECCS.csproj @@ -0,0 +1,64 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/BaseFrame/MultidimensionalTableConfig.cs b/BaseFrame/MultidimensionalTableConfig.cs new file mode 100644 index 0000000..3a38b96 --- /dev/null +++ b/BaseFrame/MultidimensionalTableConfig.cs @@ -0,0 +1,66 @@ +using Newtonsoft.Json; +using System; +using System.IO; + +namespace ECCS +{ + public sealed class MultidimensionalTableConfig + { + private static readonly object _lock = new(); + private static MultidimensionalTableConfig? _instance; + + /// + /// 单例实例(首次访问自动从文件加载) + /// + public static MultidimensionalTableConfig Instance + { + get + { + lock (_lock) + { + if (_instance == null) + { + _instance = Load(); + } + return _instance; + } + } + } + + /// + /// exe 目录下的 config.json + /// + [JsonIgnore] + private static string ConfigFilePath => + Path.Combine(AppContext.BaseDirectory, "config.json"); + + // ===== 配置项 ===== + public string AppToken { get; set; } + public string DefaultTableId { get; set; } + public bool DefaultTableIsDeleted { get; set; } + + /// + /// 保存到 config.json + /// + public void Save() + { + var json = JsonConvert.SerializeObject(this, Formatting.Indented); + File.WriteAllText(ConfigFilePath, json); + } + + /// + /// 从 config.json 加载 + /// + private static MultidimensionalTableConfig Load() + { + if (!File.Exists(ConfigFilePath)) + { + return new MultidimensionalTableConfig(); + } + + var json = File.ReadAllText(ConfigFilePath); + return JsonConvert.DeserializeObject(json) + ?? new MultidimensionalTableConfig(); + } + } +} diff --git a/BaseFrame/PubEvent/OverlayEvent.cs b/BaseFrame/PubEvent/OverlayEvent.cs new file mode 100644 index 0000000..7060ba7 --- /dev/null +++ b/BaseFrame/PubEvent/OverlayEvent.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseFrame.PubEvent +{ + public class OverlayEvent : PubSubEvent + { + } +} diff --git a/BaseFrame/PubEvent/WaitingEvent.cs b/BaseFrame/PubEvent/WaitingEvent.cs new file mode 100644 index 0000000..d900f22 --- /dev/null +++ b/BaseFrame/PubEvent/WaitingEvent.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseFrame.PubEvent +{ + public class WaitingEvent : PubSubEvent + { + } +} diff --git a/BaseFrame/Resources/Images/error.png b/BaseFrame/Resources/Images/error.png new file mode 100644 index 0000000..de079d0 Binary files /dev/null and b/BaseFrame/Resources/Images/error.png differ diff --git a/BaseFrame/Resources/Images/info.png b/BaseFrame/Resources/Images/info.png new file mode 100644 index 0000000..8fed1fb Binary files /dev/null and b/BaseFrame/Resources/Images/info.png differ diff --git a/BaseFrame/Resources/Images/warning.png b/BaseFrame/Resources/Images/warning.png new file mode 100644 index 0000000..1acd082 Binary files /dev/null and b/BaseFrame/Resources/Images/warning.png differ diff --git a/BaseFrame/Resources/Styles/WindowStyle.xaml b/BaseFrame/Resources/Styles/WindowStyle.xaml new file mode 100644 index 0000000..393226b --- /dev/null +++ b/BaseFrame/Resources/Styles/WindowStyle.xaml @@ -0,0 +1,22 @@ + + + + + diff --git a/BaseFrame/ViewModels/DialogViewModelBase.cs b/BaseFrame/ViewModels/DialogViewModelBase.cs new file mode 100644 index 0000000..a04a98c --- /dev/null +++ b/BaseFrame/ViewModels/DialogViewModelBase.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ECCS.ViewModels +{ + public abstract class DialogViewModelBase : BindableBase,IDialogAware + { + public IEventAggregator _eventAggregator; + public DialogCloseListener RequestClose { get; set; } + public DialogViewModelBase(IContainerProvider containerProvider) + { + _eventAggregator = containerProvider.Resolve(); + } + #region Dialog + + public virtual bool CanCloseDialog() => true; + public virtual void OnDialogClosed() { } + public virtual void OnDialogOpened(IDialogParameters parameters) { } + #endregion + } +} diff --git a/BaseFrame/ViewModels/Dialogs/MessageBoxViewModel.cs b/BaseFrame/ViewModels/Dialogs/MessageBoxViewModel.cs new file mode 100644 index 0000000..cb500c8 --- /dev/null +++ b/BaseFrame/ViewModels/Dialogs/MessageBoxViewModel.cs @@ -0,0 +1,123 @@ +using BaseFrame.PubEvent; +using ControlzEx.Standard; +using ECCS.ViewModels; +using Prism.Commands; +using Prism.Mvvm; +using System.Windows.Input; + +namespace BaseFrame.ViewModels.Dialogs +{ + public class MessageBoxViewModel : DialogViewModelBase + { + #region 属性 + + private string _Title; + public string Title + { + get => _Title; + set => SetProperty(ref _Title, value); + } + + private string _Message = ""; + public string Message + { + get => _Message; + set => SetProperty(ref _Message, value); + } + + private string _Icon= $"pack://siteoforigin:,,,/Resources/Images/info.png"; + public string Icon + { + get => _Icon; + set => SetProperty(ref _Icon, value); + } + + private bool _ShowYes; + public bool ShowYes + { + get => _ShowYes; + set => SetProperty(ref _ShowYes, value); + } + + private bool _ShowNo; + public bool ShowNo + { + get => _ShowNo; + set => SetProperty(ref _ShowNo, value); + } + + private bool _ShowOk; + public bool ShowOk + { + get => _ShowOk; + set => SetProperty(ref _ShowOk, value); + } + + private bool _ShowCancel; + public bool ShowCancel + { + get => _ShowCancel; + set => SetProperty(ref _ShowCancel, value); + } + + #endregion + + #region 命令 + public ICommand YesCommand { get; set; } + public ICommand NoCommand { get; set; } + public ICommand OkCommand { get; set; } + public ICommand CancelCommand { get; set; } + #endregion + + public DialogCloseListener RequestClose { get; set; } + + public MessageBoxViewModel(IContainerProvider containerProvider):base(containerProvider) + { + YesCommand = new DelegateCommand(OnYes); + NoCommand = new DelegateCommand(OnNo); + OkCommand = new DelegateCommand(OnOk); + CancelCommand = new DelegateCommand(OnCancel); + } + + private void CloseDialog(ButtonResult result) + { + var parameters = new DialogParameters(); + RequestClose.Invoke(new DialogResult(result)); + } + + private void OnYes() => CloseDialog(ButtonResult.Yes); + private void OnNo() => CloseDialog(ButtonResult.No); + private void OnOk() => CloseDialog(ButtonResult.OK); + private void OnCancel() => CloseDialog(ButtonResult.Cancel); + + #region Prism Dialog 规范 + public bool CanCloseDialog() => true; + + public override void OnDialogClosed() + { + _eventAggregator.GetEvent().Publish(false); + } + + public override void OnDialogOpened(IDialogParameters parameters) + { + _eventAggregator.GetEvent().Publish(true); + Title = parameters.GetValue("Title"); + Message = parameters.GetValue("Message"); + var iconKey = parameters.GetValue("Icon"); // info / error / warn + Icon = iconKey switch + { + "info" => $"pack://siteoforigin:,,,/Resources/Images/info.png", + "error" => $"pack://siteoforigin:,,,/Resources/Images/error.png", + "warn" => $"pack://siteoforigin:,,,/Resources/Images/warning.png", + _ => $"pack://siteoforigin:,,,/Resources/Images/info.png" // 默认 + }; + + + ShowYes = parameters.GetValue("ShowYes"); + ShowNo = parameters.GetValue("ShowNo"); + ShowOk = parameters.GetValue("ShowOk"); + ShowCancel = parameters.GetValue("ShowCancel"); + } + #endregion + } +} diff --git a/BaseFrame/ViewModels/MonitorViewModel.cs b/BaseFrame/ViewModels/MonitorViewModel.cs new file mode 100644 index 0000000..20cb103 --- /dev/null +++ b/BaseFrame/ViewModels/MonitorViewModel.cs @@ -0,0 +1,40 @@ +using BaseFrame.PubEvent; +using ECCS.ViewModels; +using NLog; +using Prism.Dialogs; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace BaseFrame.ViewModels +{ + public class MonitorViewModel : NavigateViewModelBase + { + #region 属性 + + + #endregion + #region 命令 + + + + #endregion + public MonitorViewModel(IContainerProvider containerProvider) : base(containerProvider) + { + + + } + #region 命令处理 + + + + #endregion + + + } +} diff --git a/BaseFrame/ViewModels/NavigateViewModelBase.cs b/BaseFrame/ViewModels/NavigateViewModelBase.cs new file mode 100644 index 0000000..e149c05 --- /dev/null +++ b/BaseFrame/ViewModels/NavigateViewModelBase.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ECCS.ViewModels +{ + public abstract class NavigateViewModelBase : BindableBase, INavigationAware + { + public DialogCloseListener RequestClose { get; set; } + public IEventAggregator _eventAggregator; + public IDialogService _dialogService; + public NavigateViewModelBase(IContainerProvider containerProvider) + { + _eventAggregator = containerProvider.Resolve(); + _dialogService = containerProvider.Resolve(); + + } + + #region Navigation + + public virtual void OnNavigatedTo(NavigationContext navigationContext) { } + + public virtual bool IsNavigationTarget(NavigationContext navigationContext) => true; + + public virtual void OnNavigatedFrom(NavigationContext navigationContext) { } + + #endregion + } + +} diff --git a/BaseFrame/ViewModels/SettingViewModel.cs b/BaseFrame/ViewModels/SettingViewModel.cs new file mode 100644 index 0000000..4c60100 --- /dev/null +++ b/BaseFrame/ViewModels/SettingViewModel.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ECCS.ViewModels +{ + public class SettingViewModel : NavigateViewModelBase + { + #region 属性 + + + #endregion + #region 命令 + + + + #endregion + public SettingViewModel(IContainerProvider containerProvider) : base(containerProvider) + { + + + } + #region 命令处理 + + + + #endregion + + } +} diff --git a/BaseFrame/ViewModels/ShellViewModel.cs b/BaseFrame/ViewModels/ShellViewModel.cs new file mode 100644 index 0000000..24747f8 --- /dev/null +++ b/BaseFrame/ViewModels/ShellViewModel.cs @@ -0,0 +1,94 @@ +using BaseFrame.Views; + +using MaterialDesignThemes.Wpf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace BaseFrame.ViewModels +{ + public class ShellViewModel : BindableBase + { + #region 属性 + private bool _IsLeftDrawerOpen; + + public bool IsLeftDrawerOpen + { + get => _IsLeftDrawerOpen; + set => SetProperty(ref _IsLeftDrawerOpen, value); + } + + #endregion + #region 命令 + public ICommand LeftDrawerOpenCommand { get; set; } + public ICommand MinimizeCommand { get; set; } + public ICommand MaximizeCommand { get; set; } + public ICommand CloseCommand { get; set; } + public ICommand NavigateCommand { get; set; } + + #endregion + + private IEventAggregator _eventAggregator; + private IRegionManager _regionManager; + public ShellViewModel( IContainerProvider containerProvider) + { + _eventAggregator = containerProvider.Resolve(); + _regionManager = containerProvider.Resolve(); + LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen); + MinimizeCommand = new DelegateCommand(MinimizeWindow); + MaximizeCommand = new DelegateCommand(MaximizeWindow); + CloseCommand = new DelegateCommand(CloseWindow); + NavigateCommand = new DelegateCommand(Navigate); + + } + #region 命令处理 + private void Navigate(string content) + { + switch (content) + { + case "监控界面": + _regionManager.RequestNavigate("ShellViewManager", "MonitorView"); + break; + + case "设置界面": + _regionManager.RequestNavigate("ShellViewManager", "SettingView"); + break; + + case "更新界面": + _regionManager.RequestNavigate("ShellViewManager", "UpdateInfoView"); + break; + + default: + break; + } + } + + private void LeftDrawerOpen() + { + IsLeftDrawerOpen = true; + } + private void MinimizeWindow(Window window) + { + if (window != null) + window.WindowState = WindowState.Minimized; + } + + private void MaximizeWindow(Window window) + { + if (window != null) + { + window.WindowState = window.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; + } + } + + private void CloseWindow(Window window) + { + window?.Close(); + } + #endregion + } +} diff --git a/BaseFrame/ViewModels/UpdateInfoViewModel.cs b/BaseFrame/ViewModels/UpdateInfoViewModel.cs new file mode 100644 index 0000000..54c3dd2 --- /dev/null +++ b/BaseFrame/ViewModels/UpdateInfoViewModel.cs @@ -0,0 +1,36 @@ +using Prism.Dialogs; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ECCS.ViewModels +{ + public class UpdateInfoViewModel : NavigateViewModelBase + { + #region 属性 + + + #endregion + #region 命令 + + + + #endregion + + public UpdateInfoViewModel(IContainerProvider containerProvider) : base(containerProvider) + { + + + } + #region 命令处理 + + + + #endregion + + + } +} diff --git a/BaseFrame/Views/Dialogs/MessageBoxView.xaml b/BaseFrame/Views/Dialogs/MessageBoxView.xaml new file mode 100644 index 0000000..820701b --- /dev/null +++ b/BaseFrame/Views/Dialogs/MessageBoxView.xaml @@ -0,0 +1,87 @@ + + +