ebf79d0355
21D — 后端: - Claims 新增 LicenseExpiresAt (*int64 unix 秒),写入 JWT 避免每次查库 - middleware/license_guard.go: CalcLicensePhase / LicenseGuard / GetLicensePhase - grace(0-7d): 允许通行 - readonly(7-15d): 拦截非 GET 写操作 → 403 - locked(15d+): 全部拦截 → 403 - auth.go: issueTokens 在 JWT 中嵌入 license expires_at;Login 检查 locked 拒绝登录 - router: license/* 路由豁免 LicenseGuard(锁定时仍可激活/查状态) 21E — Flutter 前端: - models/license.dart: 新 LicenseInfo,含 phase/maxDevices,去掉旧 activatedAt - core/device/device_id.dart: 持久化 UUID-v4 作为设备 ID(SharedPreferences) - repositories/license_repository.dart: getInfo/activate/deactivate,激活时携带设备信息 - providers/license_provider.dart: 改接 LicenseRepository - settings_screen.dart: activatedAt 改为显示 maxDevices Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
class LicenseInfo {
|
|
final int id;
|
|
final String type; // trial | monthly | annual | lifetime
|
|
final bool isActive;
|
|
final int maxDevices;
|
|
final DateTime? expiresAt;
|
|
final String phase; // normal | grace | readonly | locked
|
|
|
|
const LicenseInfo({
|
|
required this.id,
|
|
required this.type,
|
|
required this.isActive,
|
|
required this.maxDevices,
|
|
required this.phase,
|
|
this.expiresAt,
|
|
});
|
|
|
|
factory LicenseInfo.fromJson(Map<String, dynamic> json) {
|
|
return LicenseInfo(
|
|
id: (json['id'] as num?)?.toInt() ?? 0,
|
|
type: json['type'] as String? ?? 'trial',
|
|
isActive: json['is_active'] as bool? ?? false,
|
|
maxDevices: (json['max_devices'] as num?)?.toInt() ?? 3,
|
|
expiresAt: json['expires_at'] != null
|
|
? DateTime.tryParse(json['expires_at'] as String)
|
|
: null,
|
|
phase: json['phase'] as String? ?? 'normal',
|
|
);
|
|
}
|
|
|
|
String get typeLabel {
|
|
switch (type) {
|
|
case 'monthly':
|
|
return '月度授权';
|
|
case 'annual':
|
|
return '年度授权';
|
|
case 'lifetime':
|
|
return '永久授权';
|
|
default:
|
|
return '试用版';
|
|
}
|
|
}
|
|
|
|
bool get isExpired =>
|
|
expiresAt != null && DateTime.now().isAfter(expiresAt!);
|
|
|
|
int? get daysRemaining {
|
|
if (expiresAt == null) return null;
|
|
final diff = expiresAt!.difference(DateTime.now()).inDays;
|
|
return diff < 0 ? 0 : diff;
|
|
}
|
|
|
|
bool get isReadOnlyPhase => phase == 'readonly' || phase == 'locked';
|
|
bool get isLockedPhase => phase == 'locked';
|
|
bool get needsAttention => phase == 'grace' || phase == 'readonly' || phase == 'locked';
|
|
}
|