<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="using:NewLife.XCoder.Services"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:NewLife.XCoder.ViewModels"
xmlns:models="clr-namespace:NewLife.XCoder.Models"
mc:Ignorable="d" d:DesignWidth="1100" d:DesignHeight="700"
x:Class="NewLife.XCoder.Views.ApiDiscoverWindow"
x:DataType="vm:ApiDiscoverViewModel"
Title="{loc:Tr 'API service discovery'}" Width="1280" Height="820"
WindowStartupLocation="CenterOwner">
<Window.Resources>
<!-- 单元格左右内边距,行内不再加 padding,避免列宽计算与表头错位 -->
<Thickness x:Key="TableViewCellPadding">10,0</Thickness>
</Window.Resources>
<Window.Styles>
<Style Selector="TextBox.ConfigTextBox">
<Setter Property="Margin" Value="0"/>
<Setter Property="Height" Value="28"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
<!-- 表格按设计稿样式:表头 bg-surface-2 + text-secondary,行悬停 bg-hover,选中 accent-soft -->
<Style Selector="TableView">
<Setter Property="Foreground" Value="{DynamicResource TextPrimary}"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style Selector="TableView /template/ ScrollViewer#PART_ScrollViewer /template/ DockPanel#ContentPanel > Border">
<Setter Property="Background" Value="{DynamicResource BgSurface2}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderDefault}"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Setter Property="Padding" Value="0"/>
</Style>
<Style Selector="TableViewColumnHeader">
<Setter Property="Padding" Value="10,7"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Foreground" Value="{DynamicResource TextSecondary}"/>
</Style>
<Style Selector="TableViewRow">
<Setter Property="Padding" Value="0"/>
<Setter Property="MinHeight" Value="30"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderDefault}"/>
</Style>
<Style Selector="TableViewRow /template/ Border#Border">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="TableViewRow:pointerover /template/ Border#Border">
<Setter Property="Background" Value="{DynamicResource BgHover}"/>
</Style>
<Style Selector="TableViewRow:selected /template/ Border#Border">
<Setter Property="Background" Value="{DynamicResource AccentSoft}"/>
<Setter Property="TextElement.Foreground" Value="{DynamicResource Accent}"/>
</Style>
<Style Selector="TableViewCell">
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</Window.Styles>
<Grid x:Name="RootPanel" Margin="12" RowDefinitions="Auto,Auto,2*,*" RowSpacing="8">
<!-- 标题 -->
<StackPanel Grid.Row="0" Spacing="2">
<TextBlock Text="{loc:Tr 'API service discovery'}" Classes="sectionTitle" />
<TextBlock Text="{loc:Tr 'Broadcast on the LAN or probe NewLife ApiServer by target address; the table lists all device endpoints, and the selected row shows the raw response, copies the address or opens API Debugger.'}"
Classes="dim" TextWrapping="Wrap" />
</StackPanel>
<!-- 配置 -->
<Border Grid.Row="1" Classes="panel" Padding="10,8">
<Grid ColumnDefinitions="Auto,72,Auto,*,Auto,Auto,Auto,Auto,Auto" ColumnSpacing="8">
<TextBlock Text="{loc:Tr 'Port'}" Classes="fieldLabel" />
<TextBox Grid.Column="1" Text="{Binding Port}" Classes="ConfigTextBox" />
<TextBlock Grid.Column="2" Text="{loc:Tr 'Target IP'}" Classes="fieldLabel" />
<TextBox Grid.Column="3" Text="{Binding TargetIp}" Classes="ConfigTextBox"
PlaceholderText="{loc:Tr 'Empty = LAN broadcast; accepts 192.168.1.5, 192.168.1.0/24, 10.0.0.1-10.0.0.20; separate multiple entries with commas'}" />
<Button Grid.Column="4" Content="{loc:Tr 'Scan'}" Command="{Binding ScanCommand}" IsEnabled="{Binding !IsScanning}" Classes="primary" />
<Button Grid.Column="5" Content="{loc:Tr 'Stop'}" Command="{Binding CancelCommand}" IsEnabled="{Binding IsScanning}" Classes="secondary" />
<Button Grid.Column="6" Content="{loc:Tr 'Clear services'}" Command="{Binding ClearServicesCommand}" Classes="secondary" />
<Button Grid.Column="7" Content="{loc:Tr 'Clear logs'}" Command="{Binding ClearLogCommand}" Classes="secondary" />
<Button Grid.Column="8" Name="ExportButton" Content="{loc:Tr 'Export CSV'}" Classes="secondary" />
</Grid>
</Border>
<!-- 服务表:卡片式,表体贴边,表头与面板头分层 -->
<Border Grid.Row="2" Classes="panel" ClipToBounds="True">
<Grid RowDefinitions="Auto,*">
<Grid ColumnDefinitions="Auto,Auto,*,Auto" Margin="12,10,12,9">
<TextBlock Text="{loc:Tr 'Info'}" FontWeight="SemiBold" VerticalAlignment="Center" />
<Border Grid.Column="1" Classes="chip" Margin="8,0,0,0" VerticalAlignment="Center">
<TextBlock Text="{Binding Services.Count, Converter={x:Static loc:LocalizedFormatConverter.Instance}, ConverterParameter='{}{0} services'}" Classes="chipText" />
</Border>
<TextBlock Grid.Column="3" Text="{Binding Status, Converter={x:Static loc:LocalizedTextConverter.Instance}}" Classes="dim" VerticalAlignment="Center" />
</Grid>
<Border Grid.Row="1" BorderBrush="{DynamicResource BorderDefault}" BorderThickness="0,1,0,0">
<Panel>
<TableView Name="ServiceGrid" ItemsSource="{Binding Services}"
SelectedItem="{Binding SelectedService, Mode=TwoWay}"
CanUserResizeColumns="True" Background="Transparent" BorderThickness="0">
<TableView.Columns>
<TableViewColumn Header="{loc:Tr 'ID'}" Binding="{Binding Id}" Width="80" />
<TableViewColumn Header="{loc:Tr 'Name'}" Width="110">
<TableViewColumn.CellTemplate>
<DataTemplate x:DataType="models:ApiServiceInfo">
<TextBlock Text="{Binding Name}" Foreground="{DynamicResource Accent}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</TableViewColumn.CellTemplate>
</TableViewColumn>
<TableViewColumn Header="{loc:Tr 'LocalIP'}" Binding="{Binding LocalIP}" Width="170" />
<TableViewColumn Header="{loc:Tr 'MachineName'}" Binding="{Binding MachineName}" Width="110" />
<TableViewColumn Header="{loc:Tr 'FileVersion'}" Binding="{Binding FileVersion}" Width="100" />
<TableViewColumn Header="{loc:Tr 'OS'}" Binding="{Binding OS}" Width="190" />
<TableViewColumn Header="{loc:Tr 'RemoteIP'}" Binding="{Binding RemoteIP}" Width="100" />
<TableViewColumn Header="{loc:Tr 'Time'}" Binding="{Binding TimeText}" Width="140" />
<TableViewColumn Header="{loc:Tr 'Code'}" Binding="{Binding Code}" Width="90" />
<TableViewColumn Header="{loc:Tr 'Address'}" Binding="{Binding ServerAddress}" Width="*" MinWidth="160" />
</TableView.Columns>
</TableView>
<StackPanel IsVisible="{Binding IsEmpty}" IsHitTestVisible="False" Spacing="4"
HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="🔎" FontSize="26" HorizontalAlignment="Center" />
<TextBlock Text="{loc:Tr 'No services found yet'}" Classes="dim" HorizontalAlignment="Center" />
<TextBlock Text="{loc:Tr 'Click Scan above to discover ApiServer instances on the LAN'}" Classes="dim" HorizontalAlignment="Center" />
</StackPanel>
</Panel>
</Border>
</Grid>
</Border>
<!-- 原始应答与日志 -->
<Grid Grid.Row="3" ColumnDefinitions="*,*" ColumnSpacing="8">
<Border Classes="panel" Padding="10,8">
<Grid RowDefinitions="Auto,*" RowSpacing="4">
<Grid ColumnDefinitions="*,Auto">
<TextBlock Text="{loc:Tr 'Raw response'}" FontWeight="SemiBold" VerticalAlignment="Center" />
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="6">
<Button Name="CopyAddressButton" Content="{loc:Tr 'Copy address'}" Classes="secondary" Padding="10,4" FontSize="12" />
<Button Name="CopyJsonButton" Content="{loc:Tr 'Copy JSON'}" Classes="secondary" Padding="10,4" FontSize="12" />
<Button Name="OpenApiDebugButton" Content="{loc:Tr 'API Debugger'}" Classes="primary" Padding="10,4" FontSize="12" />
</StackPanel>
</Grid>
<Border Grid.Row="1" Classes="editor" MinHeight="0">
<TextBox Name="RawJsonBox" Text="{Binding SelectedService.RawJson}" IsReadOnly="True" AcceptsReturn="True"
TextWrapping="NoWrap" PlaceholderText="{loc:Tr 'Select a service above to view the raw Api/Info response'}" />
</Border>
</Grid>
</Border>
<Border Grid.Column="1" Classes="panel" Padding="10,8">
<Grid RowDefinitions="Auto,*" RowSpacing="4">
<TextBlock Text="{loc:Tr 'Scan log'}" FontWeight="SemiBold" />
<Border Grid.Row="1" Classes="editor" MinHeight="0">
<TextBox Classes="console" Text="{Binding Log, Converter={x:Static loc:LocalizedTextConverter.Instance}}" AcceptsReturn="True" AcceptsTab="True" IsReadOnly="True" />
</Border>
</Grid>
</Border>
</Grid>
</Grid>
</Window>
|