feat(client): 节点 status=down 在列表置灰+「不可用」+禁选(#7 客户端侧)
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
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
#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>
This commit is contained in:
@@ -16,6 +16,7 @@ class Node {
|
|||||||
this.tag = NodeTag.none,
|
this.tag = NodeTag.none,
|
||||||
this.host = '',
|
this.host = '',
|
||||||
this.port = 0,
|
this.port = 0,
|
||||||
|
this.status = 'up',
|
||||||
});
|
});
|
||||||
|
|
||||||
/// 服务端 UUID,用于 POST /v1/nodes/{uuid}/connect。
|
/// 服务端 UUID,用于 POST /v1/nodes/{uuid}/connect。
|
||||||
@@ -37,6 +38,12 @@ class Node {
|
|||||||
final String host;
|
final String host;
|
||||||
final int port;
|
final int port;
|
||||||
|
|
||||||
|
/// 节点状态(来自 /v1/nodes):'up' 可用;其余(如 'down')= agent 离线/不可用。
|
||||||
|
final String status;
|
||||||
|
|
||||||
|
/// 不可用:status 非 'up'(节点 agent 离线,连了也会 503)。
|
||||||
|
bool get isDown => status != 'up';
|
||||||
|
|
||||||
/// 延迟标签:测得显示「Nms」,未测显示「—」。
|
/// 延迟标签:测得显示「Nms」,未测显示「—」。
|
||||||
String get pingLabel => ping > 0 ? '${ping}ms' : '—';
|
String get pingLabel => ping > 0 ? '${ping}ms' : '—';
|
||||||
|
|
||||||
@@ -50,6 +57,7 @@ class Node {
|
|||||||
tag: tag,
|
tag: tag,
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
|
status: status,
|
||||||
);
|
);
|
||||||
|
|
||||||
String localizedName(AppLang lang) => lang == AppLang.zh ? nameZh : nameEn;
|
String localizedName(AppLang lang) => lang == AppLang.zh ? nameZh : nameEn;
|
||||||
|
|||||||
@@ -158,38 +158,48 @@ class _NodeGridTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final c = context.pangolin;
|
final c = context.pangolin;
|
||||||
return Material(
|
final down = node.isDown; // 节点不可用(agent 离线):置灰 + 「不可用」+ 禁选。
|
||||||
color: active ? c.accentSubtle : c.surface,
|
final unavail = lang == AppLang.zh ? '不可用' : 'Unavailable';
|
||||||
shape: RoundedRectangleBorder(
|
return Opacity(
|
||||||
borderRadius: BorderRadius.circular(PangolinRadius.lg),
|
opacity: down ? 0.55 : 1.0,
|
||||||
side: BorderSide(color: active ? c.accentBorder : c.border, width: 1.5),
|
child: Material(
|
||||||
),
|
color: (active && !down) ? c.accentSubtle : c.surface,
|
||||||
clipBehavior: Clip.antiAlias,
|
shape: RoundedRectangleBorder(
|
||||||
child: InkWell(
|
borderRadius: BorderRadius.circular(PangolinRadius.lg),
|
||||||
onTap: onTap,
|
side: BorderSide(color: (active && !down) ? c.accentBorder : c.border, width: 1.5),
|
||||||
child: Padding(
|
),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 11),
|
clipBehavior: Clip.antiAlias,
|
||||||
child: Row(children: [
|
child: InkWell(
|
||||||
CountryCode(code: node.code, active: active),
|
onTap: down ? null : onTap,
|
||||||
const SizedBox(width: 12),
|
child: Padding(
|
||||||
Expanded(
|
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 11),
|
||||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
|
child: Row(children: [
|
||||||
Text(node.localizedName(lang),
|
CountryCode(code: node.code, active: active && !down),
|
||||||
overflow: TextOverflow.ellipsis,
|
const SizedBox(width: 12),
|
||||||
style: PangolinText.sm.copyWith(color: c.fg1, fontWeight: FontWeight.w600, fontSize: 14.5)),
|
Expanded(
|
||||||
Text(node.localizedSub(lang),
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
|
||||||
overflow: TextOverflow.ellipsis,
|
Text(node.localizedName(lang),
|
||||||
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w400)),
|
overflow: TextOverflow.ellipsis,
|
||||||
]),
|
style: PangolinText.sm.copyWith(color: c.fg1, fontWeight: FontWeight.w600, fontSize: 14.5)),
|
||||||
),
|
Text(node.localizedSub(lang),
|
||||||
const SizedBox(width: 8),
|
overflow: TextOverflow.ellipsis,
|
||||||
Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.end, children: [
|
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w400)),
|
||||||
Text(node.pingLabel, style: PangolinText.mono.copyWith(color: c.fg2, fontSize: 12)),
|
]),
|
||||||
const SizedBox(height: 5),
|
),
|
||||||
SignalBars(ping: node.ping),
|
const SizedBox(width: 8),
|
||||||
|
if (down)
|
||||||
|
Text(unavail,
|
||||||
|
style: PangolinText.caption.copyWith(color: c.danger, fontWeight: FontWeight.w600, fontSize: 12))
|
||||||
|
else ...[
|
||||||
|
Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.end, children: [
|
||||||
|
Text(node.pingLabel, style: PangolinText.mono.copyWith(color: c.fg2, fontSize: 12)),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
SignalBars(ping: node.ping),
|
||||||
|
]),
|
||||||
|
if (active) ...[const SizedBox(width: 8), Icon(PangolinIcons.check, size: 18, color: c.accent)],
|
||||||
|
],
|
||||||
]),
|
]),
|
||||||
if (active) ...[const SizedBox(width: 8), Icon(PangolinIcons.check, size: 18, color: c.accent)],
|
),
|
||||||
]),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class NodesNotifier extends AsyncNotifier<List<Node>> {
|
|||||||
tier: m['tier'] as String? ?? 'free',
|
tier: m['tier'] as String? ?? 'free',
|
||||||
host: m['host'] as String? ?? '',
|
host: m['host'] as String? ?? '',
|
||||||
port: (m['port'] as num?)?.toInt() ?? 0,
|
port: (m['port'] as num?)?.toInt() ?? 0,
|
||||||
|
status: m['status'] as String? ?? 'up',
|
||||||
ping: 0, // 由 _measure 实测回填
|
ping: 0, // 由 _measure 实测回填
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|||||||
@@ -43,33 +43,43 @@ class ServerTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final c = context.pangolin;
|
final c = context.pangolin;
|
||||||
|
final down = node.isDown; // 节点不可用(agent 离线):置灰 + 「不可用」+ 禁选。
|
||||||
|
final unavail = lang == AppLang.zh ? '不可用' : 'Unavailable';
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onTap,
|
onTap: down ? null : onTap,
|
||||||
child: Container(
|
child: Opacity(
|
||||||
color: active ? c.accentSubtle : Colors.transparent,
|
opacity: down ? 0.55 : 1.0,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
child: Container(
|
||||||
child: Row(
|
color: (active && !down) ? c.accentSubtle : Colors.transparent,
|
||||||
children: [
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||||
CountryCode(code: node.code, active: active),
|
child: Row(
|
||||||
const SizedBox(width: 13),
|
children: [
|
||||||
Expanded(
|
CountryCode(code: node.code, active: active && !down),
|
||||||
child: Column(
|
const SizedBox(width: 13),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Expanded(
|
||||||
children: [
|
child: Column(
|
||||||
Text(node.localizedName(lang),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
style: PangolinText.sm
|
children: [
|
||||||
.copyWith(color: c.fg1, fontWeight: FontWeight.w600, fontSize: 15)),
|
Text(node.localizedName(lang),
|
||||||
const SizedBox(height: 2),
|
style: PangolinText.sm
|
||||||
Text(node.localizedSub(lang),
|
.copyWith(color: c.fg1, fontWeight: FontWeight.w600, fontSize: 15)),
|
||||||
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w400)),
|
const SizedBox(height: 2),
|
||||||
],
|
Text(node.localizedSub(lang),
|
||||||
|
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w400)),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
if (down)
|
||||||
Text(node.pingLabel, style: PangolinText.mono.copyWith(color: c.fg2, fontSize: 12)),
|
Text(unavail,
|
||||||
const SizedBox(width: 8),
|
style: PangolinText.caption.copyWith(color: c.danger, fontWeight: FontWeight.w600, fontSize: 12))
|
||||||
SignalBars(ping: node.ping),
|
else ...[
|
||||||
if (active) ...[const SizedBox(width: 10), Icon(PangolinIcons.check, size: 18, color: c.accent)],
|
Text(node.pingLabel, style: PangolinText.mono.copyWith(color: c.fg2, fontSize: 12)),
|
||||||
],
|
const SizedBox(width: 8),
|
||||||
|
SignalBars(ping: node.ping),
|
||||||
|
if (active) ...[const SizedBox(width: 10), Icon(PangolinIcons.check, size: 18, color: c.accent)],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// server_tile_down_test.dart — 节点不可用(status!=up)的列表项渲染断言。
|
||||||
|
// 锁住 #7 客户端侧:agent 离线 → 节点显示「不可用」+ 禁选(onTap 不触发)。
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pangolin_vpn/l10n/app_text.dart';
|
||||||
|
import 'package:pangolin_vpn/models/node.dart';
|
||||||
|
import 'package:pangolin_vpn/pangolin_theme.dart';
|
||||||
|
import 'package:pangolin_vpn/widgets/server_tile.dart';
|
||||||
|
|
||||||
|
import '../helpers/harness.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUpAll(disableGoogleFontsFetching);
|
||||||
|
|
||||||
|
Widget wrap(Node node, VoidCallback onTap) => MaterialApp(
|
||||||
|
theme: PangolinTheme.light,
|
||||||
|
home: Scaffold(body: ServerTile(node: node, lang: AppLang.zh, onTap: onTap)),
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets('节点 down → 显示「不可用」且点击不触发', (t) async {
|
||||||
|
var tapped = false;
|
||||||
|
await t.pumpWidget(wrap(
|
||||||
|
const Node(code: 'US', nameZh: '洛杉矶', nameEn: 'LA', ping: 30, status: 'down'),
|
||||||
|
() => tapped = true,
|
||||||
|
));
|
||||||
|
expect(find.text('不可用'), findsOneWidget);
|
||||||
|
await t.tap(find.byType(ServerTile));
|
||||||
|
await t.pump();
|
||||||
|
expect(tapped, isFalse, reason: 'down 节点禁选,onTap 不触发');
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('节点 up → 不显示「不可用」,点击正常触发', (t) async {
|
||||||
|
var tapped = false;
|
||||||
|
await t.pumpWidget(wrap(
|
||||||
|
const Node(code: 'US', nameZh: '洛杉矶', nameEn: 'LA', ping: 30), // status 默认 up
|
||||||
|
() => tapped = true,
|
||||||
|
));
|
||||||
|
expect(find.text('不可用'), findsNothing);
|
||||||
|
await t.tap(find.byType(ServerTile));
|
||||||
|
await t.pump();
|
||||||
|
expect(tapped, isTrue);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user