init
This commit is contained in:
90
client/lib/shared/models/notification_model.dart
Normal file
90
client/lib/shared/models/notification_model.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'notification_model.g.dart';
|
||||
|
||||
/// 通知模型
|
||||
@JsonSerializable()
|
||||
class NotificationModel {
|
||||
final int id;
|
||||
|
||||
@JsonKey(name: 'user_id')
|
||||
final int userId;
|
||||
|
||||
final String type;
|
||||
final String title;
|
||||
final String content;
|
||||
final String? link;
|
||||
|
||||
@JsonKey(name: 'is_read')
|
||||
final bool isRead;
|
||||
|
||||
final int priority;
|
||||
|
||||
@JsonKey(name: 'created_at')
|
||||
final DateTime createdAt;
|
||||
|
||||
@JsonKey(name: 'read_at')
|
||||
final DateTime? readAt;
|
||||
|
||||
const NotificationModel({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.content,
|
||||
this.link,
|
||||
required this.isRead,
|
||||
required this.priority,
|
||||
required this.createdAt,
|
||||
this.readAt,
|
||||
});
|
||||
|
||||
factory NotificationModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$NotificationModelFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$NotificationModelToJson(this);
|
||||
|
||||
/// 通知类型
|
||||
String get typeLabel {
|
||||
switch (type) {
|
||||
case 'system':
|
||||
return '系统通知';
|
||||
case 'learning':
|
||||
return '学习提醒';
|
||||
case 'achievement':
|
||||
return '成就通知';
|
||||
default:
|
||||
return '通知';
|
||||
}
|
||||
}
|
||||
|
||||
/// 优先级
|
||||
String get priorityLabel {
|
||||
switch (priority) {
|
||||
case 0:
|
||||
return '普通';
|
||||
case 1:
|
||||
return '重要';
|
||||
case 2:
|
||||
return '紧急';
|
||||
default:
|
||||
return '普通';
|
||||
}
|
||||
}
|
||||
|
||||
/// 格式化时间
|
||||
String get timeAgo {
|
||||
final now = DateTime.now();
|
||||
final difference = now.difference(createdAt);
|
||||
|
||||
if (difference.inDays > 0) {
|
||||
return '${difference.inDays}天前';
|
||||
} else if (difference.inHours > 0) {
|
||||
return '${difference.inHours}小时前';
|
||||
} else if (difference.inMinutes > 0) {
|
||||
return '${difference.inMinutes}分钟前';
|
||||
} else {
|
||||
return '刚刚';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user