release
This commit is contained in:
@@ -166,4 +166,57 @@ class CookingNoteController extends GetxController {
|
||||
List<CookingNoteModel> getNotesByTag(String tag) {
|
||||
return _notes.where((note) => note.tags.contains(tag)).toList();
|
||||
}
|
||||
|
||||
String exportToJson() {
|
||||
final data = _notes.map((e) => e.toJson()).toList();
|
||||
return const JsonEncoder.withIndent(' ').convert(data);
|
||||
}
|
||||
|
||||
String exportToCsv() {
|
||||
final buffer = StringBuffer();
|
||||
buffer.writeln('ID,菜谱ID,标题,内容,标签,创建时间');
|
||||
for (final note in _notes) {
|
||||
buffer.writeln(
|
||||
[
|
||||
note.id,
|
||||
note.recipeId,
|
||||
'"${(note.title ?? '').replaceAll('"', '""')}"',
|
||||
'"${note.content.replaceAll('"', '""').replaceAll('\n', ' ')}"',
|
||||
'"${note.tags.join('; ')}"',
|
||||
note.createdAt,
|
||||
].join(','),
|
||||
);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String exportToMarkdown() {
|
||||
final buffer = StringBuffer();
|
||||
buffer.writeln('# 📝 烹饪笔记');
|
||||
buffer.writeln();
|
||||
for (final note in _notes) {
|
||||
buffer.writeln('## ${note.displayTitle}');
|
||||
if (note.hasTags) {
|
||||
buffer.writeln('标签: ${note.tags.map((t) => '`$t`').join(' ')}');
|
||||
}
|
||||
buffer.writeln();
|
||||
buffer.writeln(note.content);
|
||||
buffer.writeln();
|
||||
buffer.writeln('*${note.displayDate}*');
|
||||
buffer.writeln('---');
|
||||
buffer.writeln();
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
void importFromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
final note = CookingNoteModel.fromJson(json);
|
||||
if (!_notes.any((n) => n.id == note.id)) {
|
||||
addNote(note);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('CookingNoteController: importFromJson failed: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user