packServer/desktop/Services/OrderQueryService.cs
liufumingren 51abccbaaf desktop:加登录页、托盘图标、防多开(单实例 + 参数转发)
- LoginWindow:服务器地址 / 账号 / 密码 / 记住账号 → POST /api/web/auth/login 拿 user JWT;
  本地已有令牌时先用 GET /api/web/me 验证,有效就跳过登录(窗口一闪而过),无效清掉令牌留下重登。
- TrayIconService(WinForms NotifyIcon,csproj 开 UseWindowsForms):
  关窗口 = 隐藏到托盘(本机服务继续跑),双击托盘恢复,右键菜单「打开主界面 / 服务地址 / 版本 / 退出」;
  第一次缩到托盘冒一次气泡提示。退出只走托盘「退出」(App 改 ShutdownMode=OnExplicitShutdown)。
- 防多开:SingleInstance(Local\ 命名互斥体 + 命名管道)。第二个实例不抢 17311 端口,
  把 yuncang://open?code=… 转给已运行实例(在托盘里也会被弹出来并按 code 查询)后自己退出;
  还在登录界面时先把 URL 存起来,登录完成后再查。
- 生命周期调整:本机 HTTP 服务与托盘在 App 里创建(登录前就可用),主窗口只管展示与操作;
  日志改成全局 AppLog(窗口没开时的日志也会在窗口打开后补上)。
- 新增 AppSettings / SessionStore:%LOCALAPPDATA%\YuncangTrace\settings.json、session.json
  (服务器地址默认 http://127.0.0.1:7300;换服务器不会复用旧令牌)。
- 新增 ApiClient(登录 / 校验令牌)、MainWindow「退出登录」(清令牌回登录页)。
- 程序/托盘图标:Assets/app.ico + tools/make-icon.ps1(品牌蓝 + 白色播放三角)。
- csproj 关闭 ImplicitUsings:WPF 与 WinForms 同时开启时隐式命名空间会让
  MessageBox / Application / Clipboard 等产生歧义。

⚠️ 本机没有 .NET SDK,无法编译验证;已做 XAML/XML 良构与括号平衡检查。
2026-10-17 10:23:50 +08:00

52 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
namespace YuncangTrace.LocalService.Services;
/// <summary>一次查询的结果(HTTP 层和界面都复用)</summary>
/// <param name="Ok">是否查到</param>
/// <param name="StatusCode">HTTP 状态码(200 / 400 / 404 / 500)</param>
/// <param name="Message">失败原因</param>
/// <param name="Data">成功时的数据(**平铺**一个对象,前端按「项目/值」两列直接渲染)</param>
public sealed record QueryResult(bool Ok, int StatusCode, string Message, object? Data)
{
public static QueryResult Success(object data) => new(true, 200, "ok", data);
public static QueryResult BadRequest(string message) => new(false, 400, message, null);
public static QueryResult NotFound(string message) => new(false, 404, message, null);
public static QueryResult Failed(string message) => new(false, 500, message, null);
}
/// <summary>
/// 按运单号查信息
///
/// ⚠️ **这里是接你们真实数据的地方**:现在返回演示数据(任何 code 都返回同一份)。
/// 真实实现通常是:查本地 SQLite / 扫描本地打包视频目录 / 调内部接口,
/// 然后把结果按字段平铺返回(前端页面按 key-value 展示,字段随你加)。
/// </summary>
public sealed class OrderQueryService
{
public QueryResult Query(string? code)
{
var value = (code ?? string.Empty).Trim();
if (value.Length == 0) return QueryResult.BadRequest("缺少运单号");
// ↓↓↓ 换成真实查询逻辑 ↓↓↓
var data = new Dictionary<string, object?>
{
["code"] = value,
["orderNo"] = "SO-20261017-001",
["channel"] = "CH-1",
["printStatus"] = "已打印",
["scanTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
["videoPath"] = @"D:\video\2026-10-17\demo.mp4",
["source"] = "演示数据(请替换 OrderQueryService.Query)",
};
// ↑↑↑ 换成真实查询逻辑 ↑↑↑
return QueryResult.Success(data);
}
}