diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index 768be82..0b586a0 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -234,11 +234,23 @@ namespace MainModule.ViewModels #region 命令处理与事件 private async Task OnLoad() { - if (!IsInitialized) + // 设备初始化期间仅对当前台架显示灰度遮罩层,初始化完成后关闭(finally 保证异常时也能关闭) + _eventAggregator.GetEvent().Publish(new ScopeOverlayArgs { Scope = TestStatus, Show = true }); + // 让遮罩层先完成渲染,再进入同步阻塞的设备初始化(泵送 Dispatcher 至 Render 优先级) + System.Windows.Application.Current?.Dispatcher.Invoke(() => { }, System.Windows.Threading.DispatcherPriority.Render); + try { - await _deviceManager.ConnectAllDevices(); - IsInitialized = true; + if (!IsInitialized) + { + await _deviceManager.ConnectAllDevices(); + IsInitialized = true; + } } + finally + { + _eventAggregator.GetEvent().Publish(new ScopeOverlayArgs { Scope = TestStatus, Show = false }); + } + } private void OnRefresh() diff --git a/MainModule/Views/AutomatedTestingView.xaml b/MainModule/Views/AutomatedTestingView.xaml index 2ec97a5..470a558 100644 --- a/MainModule/Views/AutomatedTestingView.xaml +++ b/MainModule/Views/AutomatedTestingView.xaml @@ -128,6 +128,26 @@ + + + + + + + \ No newline at end of file diff --git a/MainModule/Views/AutomatedTestingView.xaml.cs b/MainModule/Views/AutomatedTestingView.xaml.cs index 3d56642..cc8ecec 100644 --- a/MainModule/Views/AutomatedTestingView.xaml.cs +++ b/MainModule/Views/AutomatedTestingView.xaml.cs @@ -1,4 +1,6 @@ -using System; +using Prism.Events; +using MainModule.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,6 +14,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using UIShare.PubEvent; namespace MainModule.Views { @@ -20,9 +23,23 @@ namespace MainModule.Views /// public partial class AutomatedTestingView : UserControl { - public AutomatedTestingView() + public AutomatedTestingView(IEventAggregator eventAggregator) { InitializeComponent(); + eventAggregator.GetEvent().Subscribe(ShowOverlay); + // 台架级加载遮罩:仅台架名称匹配时响应,避免其他台架/主窗口同时变灰 + eventAggregator.GetEvent().Subscribe(ShowScopeOverlay); + } + private void ShowOverlay(bool arg) + { + Overlay.Visibility = arg ? Visibility.Visible : Visibility.Collapsed; + } + + private void ShowScopeOverlay(ScopeOverlayArgs args) + { + // 只处理属于当前台架的遮罩事件(TestStatus 在 OnNavigatedTo 时赋值) + if (DataContext is not AutomatedTestingViewModel vm || vm.TestStatus != args.Scope) return; + Overlay.Visibility = args.Show ? Visibility.Visible : Visibility.Collapsed; } } } diff --git a/UIShare/PubEvent/OverlayEvent.cs b/UIShare/PubEvent/OverlayEvent.cs index dd886db..e476263 100644 --- a/UIShare/PubEvent/OverlayEvent.cs +++ b/UIShare/PubEvent/OverlayEvent.cs @@ -9,4 +9,22 @@ namespace UIShare.PubEvent public class OverlayEvent : PubSubEvent { } + + /// + /// 作用域感知的灰度遮罩事件:仅台架名称与 Scope 匹配的台架视图显示/隐藏加载遮罩, + /// 避免全局 OverlayEvent 导致所有台架及主窗口同时变灰。 + /// + public class ScopeOverlayEvent : PubSubEvent + { + } + + /// 作用域遮罩事件参数。 + public class ScopeOverlayArgs + { + /// 台架名称(与 SystemConfig.Title / TestStatus 一致)。 + public string Scope { get; set; } = string.Empty; + + /// true 显示遮罩,false 隐藏遮罩。 + public bool Show { get; set; } + } }