Kayna臒a G枚zat

淇瀵艰埅鏍忛変腑鐘舵 - 鐐瑰嚮鍚庢纭珮浜綋鍓峊ab

纾 鏇 1 hafta 枚nce
ebeveyn
i艧leme
4d0bcc5edc

+ 27 - 0
src/YZWater.Avalonia/Converters/BoolConverters.cs

@@ -0,0 +1,27 @@
+using Avalonia.Data.Converters;
+using Avalonia.Media;
+using System;
+using System.Globalization;
+
+namespace YZWater.Avalonia.Converters;
+
+/// <summary>
+/// 甯冨皵鍊艰浆鎹㈠櫒闆嗗悎
+/// </summary>
+public static class BoolConverters
+{
+    /// <summary>
+    /// true 鈫 #00897B (Success缁), false 鈫 #6B7280 (鐏拌壊)
+    /// </summary>
+    public static readonly IValueConverter ToBrush =
+        new FuncValueConverter<bool, IBrush>(active =>
+            active ? new SolidColorBrush(Color.Parse("#00897B"))
+                   : new SolidColorBrush(Color.Parse("#6B7280")));
+
+    /// <summary>
+    /// true 鈫 Bold, false 鈫 Normal
+    /// </summary>
+    public static readonly IValueConverter ToFontWeight =
+        new FuncValueConverter<bool, FontWeight>(active =>
+            active ? FontWeight.Bold : FontWeight.Normal);
+}

+ 94 - 16
src/YZWater.Avalonia/Views/MainWindow.axaml

@@ -2,6 +2,7 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:vm="using:YZWater.Core.ViewModels"
         xmlns:views="using:YZWater.Avalonia.Views"
+        xmlns:conv="using:YZWater.Avalonia.Converters"
         x:Class="YZWater.Avalonia.Views.MainWindow"
         x:DataType="vm:MainViewModel"
         Title="YZ WATER - 姹℃按澶勭悊鐩戞帶绯荤粺"
@@ -14,30 +15,107 @@
         <vm:MainViewModel/>
     </Window.DataContext>
 
-    <!-- 鐩存帴浣跨敤 DockPanel 濉弧绐楀彛锛屼笉浣跨敤 AdaptiveContainer -->
     <DockPanel>
         <!-- 搴曢儴瀵艰埅鏍 -->
         <Border DockPanel.Dock="Bottom" Background="#111820" BorderBrush="#1C2333" BorderThickness="0,1,0,0" Padding="4,0">
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="0">
-                <Button Content="PROCESS" Command="{Binding ShowViewACommand}"
-                        FontFamily="Consolas, monospace" FontSize="11" Padding="20,8"
-                        Background="Transparent" Foreground="#00897B" BorderThickness="0"/>
+                <!-- PROCESS -->
+                <Button Command="{Binding ShowViewACommand}" Padding="20,8" BorderThickness="0" Cursor="Hand">
+                    <Button.Content>
+                        <StackPanel Orientation="Horizontal" Spacing="6">
+                            <Border Width="3" Height="14" CornerRadius="1"
+                                    Background="{Binding IsTabAActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                            <TextBlock Text="PROCESS" FontFamily="Consolas, monospace" FontSize="11"
+                                       FontWeight="{Binding IsTabAActive, Converter={x:Static conv:BoolConverters.ToFontWeight}}"
+                                       Foreground="{Binding IsTabAActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                        </StackPanel>
+                    </Button.Content>
+                    <Button.Styles>
+                        <Style Selector="Button">
+                            <Setter Property="Background" Value="Transparent"/>
+                        </Style>
+                    </Button.Styles>
+                </Button>
+
                 <Border Background="#1C2333" Width="1" Height="20" VerticalAlignment="Center"/>
-                <Button Content="PARAMS" Command="{Binding ShowViewBCommand}"
-                        FontFamily="Consolas, monospace" FontSize="11" Padding="20,8"
-                        Background="Transparent" Foreground="#9CA3AF" BorderThickness="0"/>
+
+                <!-- PARAMS -->
+                <Button Command="{Binding ShowViewBCommand}" Padding="20,8" BorderThickness="0" Cursor="Hand">
+                    <Button.Content>
+                        <StackPanel Orientation="Horizontal" Spacing="6">
+                            <Border Width="3" Height="14" CornerRadius="1"
+                                    Background="{Binding IsTabBActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                            <TextBlock Text="PARAMS" FontFamily="Consolas, monospace" FontSize="11"
+                                       FontWeight="{Binding IsTabBActive, Converter={x:Static conv:BoolConverters.ToFontWeight}}"
+                                       Foreground="{Binding IsTabBActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                        </StackPanel>
+                    </Button.Content>
+                    <Button.Styles>
+                        <Style Selector="Button">
+                            <Setter Property="Background" Value="Transparent"/>
+                        </Style>
+                    </Button.Styles>
+                </Button>
+
                 <Border Background="#1C2333" Width="1" Height="20" VerticalAlignment="Center"/>
-                <Button Content="FLOW" Command="{Binding ShowViewCCommand}"
-                        FontFamily="Consolas, monospace" FontSize="11" Padding="20,8"
-                        Background="Transparent" Foreground="#9CA3AF" BorderThickness="0"/>
+
+                <!-- FLOW -->
+                <Button Command="{Binding ShowViewCCommand}" Padding="20,8" BorderThickness="0" Cursor="Hand">
+                    <Button.Content>
+                        <StackPanel Orientation="Horizontal" Spacing="6">
+                            <Border Width="3" Height="14" CornerRadius="1"
+                                    Background="{Binding IsTabCActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                            <TextBlock Text="FLOW" FontFamily="Consolas, monospace" FontSize="11"
+                                       FontWeight="{Binding IsTabCActive, Converter={x:Static conv:BoolConverters.ToFontWeight}}"
+                                       Foreground="{Binding IsTabCActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                        </StackPanel>
+                    </Button.Content>
+                    <Button.Styles>
+                        <Style Selector="Button">
+                            <Setter Property="Background" Value="Transparent"/>
+                        </Style>
+                    </Button.Styles>
+                </Button>
+
                 <Border Background="#1C2333" Width="1" Height="20" VerticalAlignment="Center"/>
-                <Button Content="ALARM" Command="{Binding ShowViewDCommand}"
-                        FontFamily="Consolas, monospace" FontSize="11" Padding="20,8"
-                        Background="Transparent" Foreground="#9CA3AF" BorderThickness="0"/>
+
+                <!-- ALARM -->
+                <Button Command="{Binding ShowViewDCommand}" Padding="20,8" BorderThickness="0" Cursor="Hand">
+                    <Button.Content>
+                        <StackPanel Orientation="Horizontal" Spacing="6">
+                            <Border Width="3" Height="14" CornerRadius="1"
+                                    Background="{Binding IsTabDActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                            <TextBlock Text="ALARM" FontFamily="Consolas, monospace" FontSize="11"
+                                       FontWeight="{Binding IsTabDActive, Converter={x:Static conv:BoolConverters.ToFontWeight}}"
+                                       Foreground="{Binding IsTabDActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                        </StackPanel>
+                    </Button.Content>
+                    <Button.Styles>
+                        <Style Selector="Button">
+                            <Setter Property="Background" Value="Transparent"/>
+                        </Style>
+                    </Button.Styles>
+                </Button>
+
                 <Border Background="#1C2333" Width="1" Height="20" VerticalAlignment="Center"/>
-                <Button Content="ABOUT" Command="{Binding ShowViewECommand}"
-                        FontFamily="Consolas, monospace" FontSize="11" Padding="20,8"
-                        Background="Transparent" Foreground="#9CA3AF" BorderThickness="0"/>
+
+                <!-- ABOUT -->
+                <Button Command="{Binding ShowViewECommand}" Padding="20,8" BorderThickness="0" Cursor="Hand">
+                    <Button.Content>
+                        <StackPanel Orientation="Horizontal" Spacing="6">
+                            <Border Width="3" Height="14" CornerRadius="1"
+                                    Background="{Binding IsTabEActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                            <TextBlock Text="ABOUT" FontFamily="Consolas, monospace" FontSize="11"
+                                       FontWeight="{Binding IsTabEActive, Converter={x:Static conv:BoolConverters.ToFontWeight}}"
+                                       Foreground="{Binding IsTabEActive, Converter={x:Static conv:BoolConverters.ToBrush}}"/>
+                        </StackPanel>
+                    </Button.Content>
+                    <Button.Styles>
+                        <Style Selector="Button">
+                            <Setter Property="Background" Value="Transparent"/>
+                        </Style>
+                    </Button.Styles>
+                </Button>
             </StackPanel>
         </Border>
 

+ 22 - 49
src/YZWater.Core/ViewModels/MainViewModel.cs

@@ -31,6 +31,13 @@ public partial class MainViewModel : ObservableObject
     [ObservableProperty]
     private int _selectedTabIndex;
 
+    // 鍚 Tab 婵娲荤姸鎬
+    [ObservableProperty] private bool _isTabAActive = true;
+    [ObservableProperty] private bool _isTabBActive;
+    [ObservableProperty] private bool _isTabCActive;
+    [ObservableProperty] private bool _isTabDActive;
+    [ObservableProperty] private bool _isTabEActive;
+
     public MainViewModel()
     {
         _viewAViewModel = new ViewAViewModel();
@@ -40,88 +47,54 @@ public partial class MainViewModel : ObservableObject
         _viewEViewModel = new ViewEViewModel();
 
         _currentView = _viewAViewModel;
-
-        // 鍚姩瀹氭椂鍣ㄦ洿鏂版椂闂
         StartTimer();
     }
 
-    /// <summary>
-    /// 鍒囨崲鍒拌鍥 A (涓诲伐鑹)
-    /// </summary>
+    private void SetActiveTab(int index)
+    {
+        SelectedTabIndex = index;
+        IsTabAActive = index == 0;
+        IsTabBActive = index == 1;
+        IsTabCActive = index == 2;
+        IsTabDActive = index == 3;
+        IsTabEActive = index == 4;
+    }
+
     [RelayCommand]
     private void ShowViewA()
     {
         CurrentView = _viewAViewModel;
-        SelectedTabIndex = 0;
-        Log.Debug("鍒囨崲鍒颁富宸ヨ壓瑙嗗浘");
+        SetActiveTab(0);
     }
 
-    /// <summary>
-    /// 鍒囨崲鍒拌鍥 B (鍙傛暟璁剧疆)
-    /// </summary>
     [RelayCommand]
     private void ShowViewB()
     {
         CurrentView = _viewBViewModel;
-        SelectedTabIndex = 1;
-        Log.Debug("鍒囨崲鍒板弬鏁拌缃鍥");
+        SetActiveTab(1);
     }
 
-    /// <summary>
-    /// 鍒囨崲鍒拌鍥 C (娴侀噺璁板綍)
-    /// </summary>
     [RelayCommand]
     private void ShowViewC()
     {
         CurrentView = _viewCViewModel;
-        SelectedTabIndex = 2;
-        Log.Debug("鍒囨崲鍒版祦閲忚褰曡鍥");
+        SetActiveTab(2);
     }
 
-    /// <summary>
-    /// 鍒囨崲鍒拌鍥 D (鎶ヨ璁板綍)
-    /// </summary>
     [RelayCommand]
     private void ShowViewD()
     {
         CurrentView = _viewDViewModel;
-        SelectedTabIndex = 3;
-        Log.Debug("鍒囨崲鍒版姤璀﹁褰曡鍥");
+        SetActiveTab(3);
     }
 
-    /// <summary>
-    /// 鍒囨崲鍒拌鍥 E (鍏充簬)
-    /// </summary>
     [RelayCommand]
     private void ShowViewE()
     {
         CurrentView = _viewEViewModel;
-        SelectedTabIndex = 4;
-        Log.Debug("鍒囨崲鍒板叧浜庤鍥");
-    }
-
-    /// <summary>
-    /// 杩炴帴 PLC
-    /// </summary>
-    [RelayCommand]
-    private async Task ConnectPlcAsync()
-    {
-        IsPlcConnected = await PlcService.ConnectAsync();
-    }
-
-    /// <summary>
-    /// 鏂紑 PLC
-    /// </summary>
-    [RelayCommand]
-    private void DisconnectPlc()
-    {
-        PlcService.Disconnect();
-        IsPlcConnected = false;
+        SetActiveTab(4);
     }
 
-    /// <summary>
-    /// 鍚姩瀹氭椂鍣
-    /// </summary>
     private void StartTimer()
     {
         var timer = new System.Timers.Timer(1000);