1. 全局替换tool_center/inspiration为discover模块,统一路由路径 2. 调整AppRoutes路由常量,将discover作为主Tab页,inspiration作为子页面 3. 更新页面注册表与路由配置,修正跳转目标 4. 调整启动页可选配置项,修正路由ID对应关系 5. 新增翻译服务、内容发现、热搜相关工具类与数据模型 6. 修复缓存清理后未刷新统计的问题,调整x86_64架构注释 7. 更新AGENTS.md文档约束规则 8. 新增一批调试用截图资源文件
141 lines
4.4 KiB
Dart
141 lines
4.4 KiB
Dart
// ============================================================
|
|
// 闲言APP — 翻译消息模型
|
|
// 创建时间: 2026-05-19
|
|
// 更新时间: 2026-05-24
|
|
// 作用: 翻译助手的消息数据模型,区分用户原文和翻译结果
|
|
// 上次更新: 新增 toJson/fromJson 支持历史持久化
|
|
// ============================================================
|
|
|
|
enum TranslateMessageRole { user, assistant }
|
|
|
|
enum TranslateStatus {
|
|
pending,
|
|
translating,
|
|
completed,
|
|
failed,
|
|
}
|
|
|
|
class TranslateMessage {
|
|
const TranslateMessage({
|
|
required this.id,
|
|
required this.sessionId,
|
|
required this.role,
|
|
required this.content,
|
|
required this.createdAt,
|
|
this.sourceLang,
|
|
this.sourceLangName,
|
|
this.targetLang,
|
|
this.targetLangName,
|
|
this.autoDetected = false,
|
|
this.detectedLang,
|
|
this.detectedLangName,
|
|
this.apiProvider,
|
|
this.status = TranslateStatus.completed,
|
|
this.errorMessage,
|
|
});
|
|
|
|
final String id;
|
|
final String sessionId;
|
|
final TranslateMessageRole role;
|
|
final String content;
|
|
final DateTime createdAt;
|
|
|
|
final String? sourceLang;
|
|
final String? sourceLangName;
|
|
final String? targetLang;
|
|
final String? targetLangName;
|
|
|
|
final bool autoDetected;
|
|
final String? detectedLang;
|
|
final String? detectedLangName;
|
|
|
|
final String? apiProvider;
|
|
final TranslateStatus status;
|
|
final String? errorMessage;
|
|
|
|
TranslateMessage copyWith({
|
|
String? id,
|
|
String? sessionId,
|
|
TranslateMessageRole? role,
|
|
String? content,
|
|
DateTime? createdAt,
|
|
String? sourceLang,
|
|
String? sourceLangName,
|
|
String? targetLang,
|
|
String? targetLangName,
|
|
bool? autoDetected,
|
|
String? detectedLang,
|
|
String? detectedLangName,
|
|
String? apiProvider,
|
|
TranslateStatus? status,
|
|
String? errorMessage,
|
|
}) {
|
|
return TranslateMessage(
|
|
id: id ?? this.id,
|
|
sessionId: sessionId ?? this.sessionId,
|
|
role: role ?? this.role,
|
|
content: content ?? this.content,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
sourceLang: sourceLang ?? this.sourceLang,
|
|
sourceLangName: sourceLangName ?? this.sourceLangName,
|
|
targetLang: targetLang ?? this.targetLang,
|
|
targetLangName: targetLangName ?? this.targetLangName,
|
|
autoDetected: autoDetected ?? this.autoDetected,
|
|
detectedLang: detectedLang ?? this.detectedLang,
|
|
detectedLangName: detectedLangName ?? this.detectedLangName,
|
|
apiProvider: apiProvider ?? this.apiProvider,
|
|
status: status ?? this.status,
|
|
errorMessage: errorMessage ?? this.errorMessage,
|
|
);
|
|
}
|
|
|
|
bool get isFailed => status == TranslateStatus.failed;
|
|
bool get isTranslating => status == TranslateStatus.translating;
|
|
bool get isCompleted => status == TranslateStatus.completed;
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'sessionId': sessionId,
|
|
'role': role.name,
|
|
'content': content,
|
|
'createdAt': createdAt.millisecondsSinceEpoch,
|
|
'sourceLang': sourceLang,
|
|
'sourceLangName': sourceLangName,
|
|
'targetLang': targetLang,
|
|
'targetLangName': targetLangName,
|
|
'autoDetected': autoDetected,
|
|
'detectedLang': detectedLang,
|
|
'detectedLangName': detectedLangName,
|
|
'apiProvider': apiProvider,
|
|
'status': status.name,
|
|
'errorMessage': errorMessage,
|
|
};
|
|
|
|
factory TranslateMessage.fromJson(Map<String, dynamic> json) =>
|
|
TranslateMessage(
|
|
id: json['id'] as String? ?? '',
|
|
sessionId: json['sessionId'] as String? ?? '',
|
|
role: TranslateMessageRole.values.firstWhere(
|
|
(r) => r.name == json['role'],
|
|
orElse: () => TranslateMessageRole.user,
|
|
),
|
|
content: json['content'] as String? ?? '',
|
|
createdAt: json['createdAt'] != null
|
|
? DateTime.fromMillisecondsSinceEpoch(json['createdAt'] as int)
|
|
: DateTime.now(),
|
|
sourceLang: json['sourceLang'] as String?,
|
|
sourceLangName: json['sourceLangName'] as String?,
|
|
targetLang: json['targetLang'] as String?,
|
|
targetLangName: json['targetLangName'] as String?,
|
|
autoDetected: json['autoDetected'] as bool? ?? false,
|
|
detectedLang: json['detectedLang'] as String?,
|
|
detectedLangName: json['detectedLangName'] as String?,
|
|
apiProvider: json['apiProvider'] as String?,
|
|
status: TranslateStatus.values.firstWhere(
|
|
(s) => s.name == json['status'],
|
|
orElse: () => TranslateStatus.completed,
|
|
),
|
|
errorMessage: json['errorMessage'] as String?,
|
|
);
|
|
}
|