feat(routing): 域名级系统锁冲突提示 + 重置默认按钮 + 客户端 follow-up 清理

承接 FT-A(GET /v1/me/routing 含只读 system_locked_domains)。

- RoutingProfile 加只读 systemLockedDomains(fromJson 读/toJson 不输出);
  routing_screen 冲突检测扩展到域名类规则(domain/domain_suffix/domain_keyword
  命中锁定域名 → systemLocked),ip_cidr 私网启发式保留。
- RoutingProfile.defaults() + RoutingProfileNotifier.resetToDefault()(复用
  _persist:乐观更新/失败回滚/存成功后自动重连,保留只读 systemLockedDomains
  不丢)+ routing_screen 加「重置默认」按钮与二次确认弹层(新增 3 个 l10n 键)。
- RoutingRule.copyWith 用哨兵支持 note 显式清空为 null;RoutingRule/Builtin/
  RoutingProfile 加值相等 operator==/hashCode。
- T8 smartRouteSub 清理:grep 全仓发现 design/prototype/i18n/alias.json →
  gen_proto_i18n.mjs(CI 漂移闸)仍有活引用,按计划口径不删,详见
  .superpowers/sdd/task-FTB-report.md。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-29 06:57:58 +08:00
parent 3159dd75c1
commit 2930d76cf3
14 changed files with 410 additions and 17 deletions
+76 -3
View File
@@ -1,8 +1,10 @@
// routing_profile.dart — 可配置分流档案(GET/POST /v1/me/routing)。
//
// 对齐后端契约(server/internal/httpapi 分流端点):
// {mode, builtin:{china_direct,lan_direct,private_via_tunnel}, rules:[...], final}。
// {mode, builtin:{china_direct,lan_direct,private_via_tunnel}, rules:[...], final,
// system_locked_domains:[...]}(FT-A 起响应含只读私有服务域名清单)。
// 手写 fromJson/toJson(项目无 json_serializable,仿 lib/models/me.dart)。
import 'package:flutter/foundation.dart' show listEquals;
/// 分流模式。
/// 'rule' = 按规则(内置 + 自定义) | 'global' = 全局代理 | 'direct' = 全局直连。
@@ -55,8 +57,24 @@ class Builtin {
lanDirect: lanDirect ?? this.lanDirect,
privateViaTunnel: privateViaTunnel ?? this.privateViaTunnel,
);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Builtin &&
runtimeType == other.runtimeType &&
chinaDirect == other.chinaDirect &&
lanDirect == other.lanDirect &&
privateViaTunnel == other.privateViaTunnel;
@override
int get hashCode => Object.hash(chinaDirect, lanDirect, privateViaTunnel);
}
/// copyWith 的哨兵值:用于区分「未传参(保留原值)」与「显式传 null(清空该字段)」,
/// 仅 [RoutingRule.note] 需要(其它字段无「清空」语义,`??` 已够用)。
const _noteSentinel = Object();
/// 单条自定义分流规则。
///
/// **enabled 语义**(计划裁决):构造默认 `true`;[toJson] 恒输出 `enabled` 字段
@@ -95,20 +113,35 @@ class RoutingRule {
'enabled': enabled,
};
/// [note] 用哨兵:不传 → 保留原值;显式传 `null` → 清空为 null。
RoutingRule copyWith({
String? type,
String? value,
String? action,
String? note,
Object? note = _noteSentinel,
bool? enabled,
}) =>
RoutingRule(
type: type ?? this.type,
value: value ?? this.value,
action: action ?? this.action,
note: note ?? this.note,
note: identical(note, _noteSentinel) ? this.note : note as String?,
enabled: enabled ?? this.enabled,
);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is RoutingRule &&
runtimeType == other.runtimeType &&
type == other.type &&
value == other.value &&
action == other.action &&
note == other.note &&
enabled == other.enabled;
@override
int get hashCode => Object.hash(type, value, action, note, enabled);
}
/// 分流档案(账户级,单份)。
@@ -118,6 +151,7 @@ class RoutingProfile {
this.builtin = const Builtin(),
this.rules = const [],
this.finalAction = 'proxy',
this.systemLockedDomains = const [],
});
final RoutingMode mode;
@@ -127,6 +161,11 @@ class RoutingProfile {
/// 兜底动作(JSON key 为保留字 `final`,Dart 侧改名)。'proxy' | 'direct'。
final String finalAction;
/// **只读**:系统强制走隧道的私有服务域名清单(服务端 `PANGOLIN_PRIVATE_SPLIT_DOMAINS`,
/// FT-A 起随 GET /v1/me/routing 下发)。`toJson()` 不输出——服务端忽略,且此字段
/// 客户端不可写。
final List<String> systemLockedDomains;
factory RoutingProfile.fromJson(Map<String, dynamic> m) => RoutingProfile(
mode: m['mode'] as String? ?? 'rule',
builtin: m['builtin'] != null
@@ -136,6 +175,8 @@ class RoutingProfile {
.map((e) => RoutingRule.fromJson(e as Map<String, dynamic>))
.toList(),
finalAction: m['final'] as String? ?? 'proxy',
systemLockedDomains:
(m['system_locked_domains'] as List?)?.cast<String>() ?? const [],
);
Map<String, dynamic> toJson() => {
@@ -145,16 +186,48 @@ class RoutingProfile {
'final': finalAction,
};
/// 出厂默认档案(对齐服务端 `routing.Default()`):智能分流 + 内置全开 + 无自定义规则。
/// 不含 systemLockedDomains(那是账户相关的只读回显,由调用方按需保留;见
/// RoutingProfileNotifier.resetToDefault())。
factory RoutingProfile.defaults() => const RoutingProfile(
mode: 'rule',
builtin: Builtin(),
rules: [],
finalAction: 'proxy',
);
RoutingProfile copyWith({
RoutingMode? mode,
Builtin? builtin,
List<RoutingRule>? rules,
String? finalAction,
List<String>? systemLockedDomains,
}) =>
RoutingProfile(
mode: mode ?? this.mode,
builtin: builtin ?? this.builtin,
rules: rules ?? this.rules,
finalAction: finalAction ?? this.finalAction,
systemLockedDomains: systemLockedDomains ?? this.systemLockedDomains,
);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is RoutingProfile &&
runtimeType == other.runtimeType &&
mode == other.mode &&
builtin == other.builtin &&
listEquals(rules, other.rules) &&
finalAction == other.finalAction &&
listEquals(systemLockedDomains, other.systemLockedDomains);
@override
int get hashCode => Object.hash(
mode,
builtin,
Object.hashAll(rules),
finalAction,
Object.hashAll(systemLockedDomains),
);
}