feat(client): P1 真实数据接入地基(#6 6A)
- api_config.dart:API 基址单源(消除各处重复 _kApiUrl) - api_client.dart:统一鉴权 HTTP 客户端,401→AuthNotifier.refresh→重试一次, 错误统一 AuthApiException;+ 单测覆盖 401 刷新重试 - 模型 me/device/plan/usage_point(对齐后端 snake_case 契约) - account_api.dart:/v1/me、/v1/plans、/v1/me/devices(列表+删)、/v1/usage、 /v1/redeem、/v1/ads/unlock 封装 - auth_provider:注入 AuthApi + refresh();account_providers 装配 ApiClient/AccountApi - 顺带修复 onboarding 提交遗留的测试 stub(_NullTokenStore 缺 isOnboarded/markOnboarded) flutter analyze 0 error;114 tests passed。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// me.dart — 当前账户聚合视图(GET /v1/me)。
|
||||
//
|
||||
// 一发覆盖账号/套餐/配额/今日+周流量,对齐后端契约
|
||||
// (server/internal/httpapi/account.go + web/usercenter http.ts)。
|
||||
|
||||
/// 账户档案。字段对齐后端 snake_case JSON。
|
||||
class Me {
|
||||
const Me({
|
||||
required this.email,
|
||||
required this.plan,
|
||||
this.expiresAt,
|
||||
this.devicesUsed = 0,
|
||||
this.devicesMax = 1,
|
||||
this.quotaTodayMin,
|
||||
this.dataTodayGb = 0,
|
||||
this.weeklyGb = const [],
|
||||
this.totpEnabled = false,
|
||||
});
|
||||
|
||||
final String email;
|
||||
|
||||
/// 'free' | 'pro' | 'team'。
|
||||
final String plan;
|
||||
|
||||
/// 订阅到期(UTC);免费版/无订阅为 null。
|
||||
final DateTime? expiresAt;
|
||||
|
||||
final int devicesUsed;
|
||||
final int devicesMax;
|
||||
|
||||
/// 今日额度上限(分钟);null = 不限(pro/team)。
|
||||
final int? quotaTodayMin;
|
||||
|
||||
/// 今日已用流量(GB)。
|
||||
final double dataTodayGb;
|
||||
|
||||
/// 近 7 天每日流量(GB),旧→新。
|
||||
final List<double> weeklyGb;
|
||||
|
||||
final bool totpEnabled;
|
||||
|
||||
bool get isFree => plan == 'free';
|
||||
|
||||
factory Me.fromJson(Map<String, dynamic> m) {
|
||||
final exp = (m['expires_at'] ?? m['expire_at']) as String?;
|
||||
return Me(
|
||||
email: m['email'] as String? ?? '',
|
||||
plan: m['plan'] as String? ?? 'free',
|
||||
expiresAt: (exp != null && exp.isNotEmpty) ? DateTime.tryParse(exp) : null,
|
||||
devicesUsed: (m['devices_used'] as num?)?.toInt() ?? 0,
|
||||
devicesMax: (m['devices_max'] as num?)?.toInt() ?? 1,
|
||||
quotaTodayMin: (m['quota_today_min'] as num?)?.toInt(),
|
||||
dataTodayGb: (m['data_today_gb'] as num?)?.toDouble() ?? 0,
|
||||
weeklyGb: ((m['weekly_gb'] as List<dynamic>?) ?? const [])
|
||||
.map((e) => (e as num).toDouble())
|
||||
.toList(),
|
||||
totpEnabled: m['totp_enabled'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user