Files
pangolin/client/lib/models/node.dart
T
wangjia 8049659660
ci-pangolin / Lint — shellcheck (push) Successful in 8s
ci-pangolin / OpenAPI Sync Check (push) Successful in 24s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Successful in 6s
ci-pangolin / Flutter — analyze + test (push) Successful in 24s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (push) Successful in 5s
ci-pangolin / Codegen Drift — token 生成物未漂移 (push) Successful in 5s
ci-pangolin / Go — build + test (push) Successful in 9s
ci-pangolin / E2E Smoke — L4 进程级端到端 (push) Successful in 18s
ci-pangolin / Go — integration (mysql/redis testcontainers) (push) Successful in 4m18s
ci-pangolin / Golden — 视觉回归 (components + auth) (push) Successful in 13s
feat(client): 节点 status=down 在列表置灰+「不可用」+禁选(#7 客户端侧)
#7 服务端已在 agent 离线时把节点判 down,但客户端 Node 模型没读 status、
列表照常显示。补:Node.status 字段 + 解析 /v1/nodes 的 status;ServerTile/
_NodeGridTile 在 isDown 时 Opacity 置灰 + 末尾「不可用」+ onTap 禁用。全平台
共享(lib/widgets+screens)。up 节点 Opacity 1.0 无变化,golden 不动。加 down
状态 widget 测试。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 21:35:52 +08:00

83 lines
2.3 KiB
Dart

// node.dart — 加速节点数据模型
import '../l10n/app_text.dart';
/// 节点标签(决定副标题语义胶囊)。
enum NodeTag { none, streaming, p2p }
/// 单个加速节点。名称按语言单显;副标题脱敏(无红线词)。
class Node {
const Node({
required this.code,
required this.nameZh,
required this.nameEn,
required this.ping,
this.uuid = '',
this.tier = 'free',
this.tag = NodeTag.none,
this.host = '',
this.port = 0,
this.status = 'up',
});
/// 服务端 UUID,用于 POST /v1/nodes/{uuid}/connect。
final String uuid;
/// 2 字母国家码(HK/JP/SG…),界面以码块渲染,绝不用 emoji 国旗。
final String code;
final String nameZh;
final String nameEn;
/// 节点层级:'free' | 'pro'。
final String tier;
/// 客户端实测延迟(ms);0 = 尚未测得(显示 — )。
final int ping;
final NodeTag tag;
/// 节点入口 host/port(来自 /v1/nodes),用于客户端 TCP 实测延迟。
final String host;
final int port;
/// 节点状态(来自 /v1/nodes):'up' 可用;其余(如 'down')= agent 离线/不可用。
final String status;
/// 不可用:status 非 'up'(节点 agent 离线,连了也会 503)。
bool get isDown => status != 'up';
/// 延迟标签:测得显示「Nms」,未测显示「—」。
String get pingLabel => ping > 0 ? '${ping}ms' : '';
Node copyWith({int? ping}) => Node(
code: code,
nameZh: nameZh,
nameEn: nameEn,
ping: ping ?? this.ping,
uuid: uuid,
tier: tier,
tag: tag,
host: host,
port: port,
status: status,
);
String localizedName(AppLang lang) => lang == AppLang.zh ? nameZh : nameEn;
/// 副标题:有标签时显示语义文字,否则用拉丁地名(两语言通用,不串语言)。
String localizedSub(AppLang lang) {
switch (tag) {
case NodeTag.streaming:
return lang == AppLang.zh ? '流媒体优化' : 'Streaming';
case NodeTag.p2p:
return 'P2P';
case NodeTag.none:
return nameEn;
}
}
}
/// 智能选择的哨兵选中值。
const String kSmartNodeCode = 'AUTO';
/// 节点未就绪时的中性占位(非伪造服务器,仅加载窗口短暂展示)。
const Node kPlaceholderNode = Node(code: '··', nameZh: '加载中', nameEn: 'Loading', ping: 0);