packServer/desktop/MainWindow.xaml
liufumingren 680fff84df desktop:新增 WPF 本机软件(本机 HTTP 服务 + yuncang:// 启动协议)
给前端 `/local` 公共页与 Chrome 插件对接的本机软件(net8.0-windows + UseWPF):

- Services/LocalHttpServer.cs:HttpListener 监听 localhost:17311(同时注册 127.0.0.1 前缀)
  - GET /api/health      探活(2xx 即认为已启动)
  - GET /api/query/{code} 按运单号查信息,成功时字段平铺返回
  - CORS 全量响应头 + Access-Control-Allow-Private-Network(公网 https 页面访问 localhost 的
    PNA 预检),预检 OPTIONS 直接 204
  - 根路径给一个说明页,方便浏览器里手工排查
- Services/OrderQueryService.cs:★ 接真实数据源的位置(现为演示数据)
- Services/ProtocolHelper.cs:HKCU\Software\Classes\yuncang 注册/反注册、解析
  yuncang://open?code=xxx(免管理员)
- Services/SingleInstance.cs:互斥体 + 命名管道,被协议再次拉起时把参数转给已运行窗口,
  不会去抢 17311 端口
- MainWindow:运行状态、服务地址(复制/浏览器打开)、注册启动协议、测试查询、运行日志
- App.xaml.cs:单实例判断 + 协议参数处理;启动即自动起服务

README 里写了编译/发布命令、接口契约、协议注册(含 reg 命令与打包工具做法)、
接真实数据的示例,以及端口权限(netsh http add urlalloc)/端口占用等常见问题。

⚠️ 本机没装 .NET SDK,无法在这里编译验证;XAML/manifest/csproj 已做 XML 良构校验。
2026-10-17 10:13:09 +08:00

93 lines
5.3 KiB
XML

<Window x:Class="YuncangTrace.LocalService.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="云仓视频溯源软件(本机服务)"
Height="620" Width="780"
MinHeight="520" MinWidth="680"
WindowStartupLocation="CenterScreen"
Background="{StaticResource BgBrush}"
FontFamily="Microsoft YaHei UI, Segoe UI"
FontSize="13">
<Grid Margin="18">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- ① 标题 + 运行状态 -->
<DockPanel Grid.Row="0" Margin="0,0,0,14">
<TextBlock DockPanel.Dock="Right"
Text="云仓视频溯源系统"
Foreground="{StaticResource MutedBrush}"
VerticalAlignment="Center" />
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="StatusDot" Width="10" Height="10" Margin="0,0,8,0"
VerticalAlignment="Center" Fill="{StaticResource BadBrush}" />
<TextBlock Text="本机服务" FontSize="18" FontWeight="SemiBold" VerticalAlignment="Center" />
<TextBlock x:Name="StatusText" Text="未启动" Margin="10,0,0,2"
Foreground="{StaticResource MutedBrush}" VerticalAlignment="Bottom" />
</StackPanel>
</DockPanel>
<!-- ② 服务地址 -->
<Border Grid.Row="1" Background="White" BorderBrush="{StaticResource LineBrush}"
BorderThickness="1" CornerRadius="8" Padding="12,10" Margin="0,0,0,10">
<DockPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
<Button Content="复制地址" Padding="10,4" Margin="0,0,8,0" Click="CopyAddress_Click" />
<Button Content="在浏览器打开" Padding="10,4" Click="OpenInBrowser_Click" />
</StackPanel>
<TextBlock Text="服务地址" Foreground="{StaticResource MutedBrush}" VerticalAlignment="Center" Margin="0,0,10,0" />
<TextBox x:Name="AddressBox" IsReadOnly="True" BorderThickness="0" Background="Transparent"
FontFamily="Consolas, Microsoft YaHei UI" VerticalContentAlignment="Center" />
</DockPanel>
</Border>
<!-- ③ 操作按钮 + 协议状态 -->
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,0,0,6">
<Button x:Name="StartStopButton" Content="停止服务" Padding="14,6" Click="StartStop_Click" />
<Button x:Name="ProtocolButton" Content="注册启动协议" Padding="14,6" Margin="10,0,0,0" Click="Protocol_Click" />
<Button Content="复制唤醒地址" Padding="14,6" Margin="10,0,0,0" Click="CopyLaunchUrl_Click" />
<TextBlock x:Name="ProtocolText" Margin="14,0,0,0" VerticalAlignment="Center"
Foreground="{StaticResource MutedBrush}" TextTrimming="CharacterEllipsis" />
</StackPanel>
<!-- ④ 查询测试 -->
<Border Grid.Row="3" Background="White" BorderBrush="{StaticResource LineBrush}"
BorderThickness="1" CornerRadius="8" Padding="12,10" Margin="0,6,0,10">
<StackPanel>
<DockPanel>
<Button DockPanel.Dock="Right" Content="查询" Padding="16,5" Margin="8,0,0,0" Click="Query_Click" />
<TextBlock Text="测试查询" Foreground="{StaticResource MutedBrush}" VerticalAlignment="Center" Margin="0,0,10,0" />
<TextBox x:Name="QueryBox" Padding="6,3" VerticalContentAlignment="Center"
ToolTip="输入运单号后回车" KeyDown="QueryBox_KeyDown" />
</DockPanel>
<TextBox x:Name="ResultBox" Margin="0,10,0,0" Height="130" IsReadOnly="True"
AcceptsReturn="True" AcceptsTab="True" TextWrapping="NoWrap"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
FontFamily="Consolas, Microsoft YaHei UI" FontSize="12" Padding="8"
Background="#F9FAFB" BorderBrush="{StaticResource LineBrush}" />
</StackPanel>
</Border>
<!-- ⑤ 日志 -->
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="运行日志" Foreground="{StaticResource MutedBrush}" Margin="2,0,0,4" />
<Border Grid.Row="1" Background="White" BorderBrush="{StaticResource LineBrush}"
BorderThickness="1" CornerRadius="8" Padding="4">
<ListBox x:Name="LogList" BorderThickness="0" Background="Transparent"
FontFamily="Consolas, Microsoft YaHei UI" FontSize="12"
ScrollViewer.HorizontalScrollBarVisibility="Auto" />
</Border>
</Grid>
</Grid>
</Window>