generated from dellevin/template
优化打包体积
This commit is contained in:
@@ -10,8 +10,6 @@ import '../pages/movies/movie_detail_page.dart';
|
||||
import '../pages/book/book_detail_page.dart';
|
||||
import '../pages/note/note_detail_page.dart';
|
||||
import '../pages/movies/douban_webview_page.dart';
|
||||
import '../pages/note_plus/note_plus_form_page.dart';
|
||||
import '../pages/note_plus/note_plus_detail_page.dart';
|
||||
|
||||
/// 路由生成器
|
||||
class AppRouter {
|
||||
@@ -73,20 +71,6 @@ class AppRouter {
|
||||
}
|
||||
return SlideUpPageRoute(page: DoubanWebViewPage(url: url));
|
||||
|
||||
case '/note-plus-form':
|
||||
final id = settings.arguments is String ? settings.arguments as String : null;
|
||||
if (id == null) {
|
||||
return _buildUnknownRoute(settings.name);
|
||||
}
|
||||
return SlideUpPageRoute(page: NotePlusFormPage(documentId: id));
|
||||
|
||||
case '/note-plus-detail':
|
||||
final id = settings.arguments is String ? settings.arguments as String : null;
|
||||
if (id == null) {
|
||||
return _buildUnknownRoute(settings.name);
|
||||
}
|
||||
return SlideUpPageRoute(page: NotePlusDetailPage(documentId: id));
|
||||
|
||||
default:
|
||||
return _buildUnknownRoute(settings.name);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class DatabaseHelper {
|
||||
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 27,
|
||||
version: 28,
|
||||
onCreate: _createDB,
|
||||
onUpgrade: _onUpgrade,
|
||||
);
|
||||
@@ -174,10 +174,10 @@ class DatabaseHelper {
|
||||
await db.execute('ALTER TABLE tags ADD COLUMN is_hidden INTEGER NOT NULL DEFAULT 0');
|
||||
}
|
||||
if (oldVersion < 18) {
|
||||
await _createNotePlusTable(db);
|
||||
// note_plus table creation removed (feature dropped in v28)
|
||||
}
|
||||
if (oldVersion < 19) {
|
||||
await _createNotePlusTable(db);
|
||||
// note_plus table creation removed (feature dropped in v28)
|
||||
}
|
||||
if (oldVersion < 20) {
|
||||
// 确保 note_plus 表有 parent_id 列(从旧版 folder 迁移)
|
||||
@@ -251,6 +251,10 @@ class DatabaseHelper {
|
||||
if (oldVersion < 27) {
|
||||
await _upgradeBooksTableV27(db);
|
||||
}
|
||||
if (oldVersion < 28) {
|
||||
// 移除 Note Plus 功能,删除 note_plus 表
|
||||
await db.execute('DROP TABLE IF EXISTS note_plus');
|
||||
}
|
||||
}
|
||||
|
||||
/// 升级books表到V27(添加阅读始末日期字段)
|
||||
@@ -765,9 +769,6 @@ class DatabaseHelper {
|
||||
)
|
||||
''');
|
||||
|
||||
// Note Plus 块编辑器文档表
|
||||
await _createNotePlusTable(db);
|
||||
|
||||
// EPUB 阅读器书籍表
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS reader_books (
|
||||
@@ -804,24 +805,6 @@ class DatabaseHelper {
|
||||
''');
|
||||
}
|
||||
|
||||
/// 创建 Note Plus 文档表
|
||||
Future<void> _createNotePlusTable(Database db) async {
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS note_plus (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT DEFAULT '',
|
||||
parent_id TEXT DEFAULT '',
|
||||
sort_index INTEGER DEFAULT 0,
|
||||
blocks_json TEXT NOT NULL,
|
||||
tags TEXT,
|
||||
images TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
is_deleted INTEGER DEFAULT 0
|
||||
)
|
||||
''');
|
||||
}
|
||||
|
||||
// 关闭数据库
|
||||
Future close() async {
|
||||
if (_database != null) {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../models/note_plus_models.dart';
|
||||
import '../database_helper.dart';
|
||||
|
||||
/// Note Plus 块文档数据访问对象
|
||||
class NotePlusDao {
|
||||
final DatabaseHelper _dbHelper = DatabaseHelper.instance;
|
||||
|
||||
Future<T> _wrap<T>(String op, Future<T> Function() fn) async {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (e) {
|
||||
debugPrint('[NotePlusDao] $op error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有未删除的文档
|
||||
Future<List<NotePlusDocument>> getAll() => _wrap('getAll', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'note_plus',
|
||||
where: 'is_deleted = ?',
|
||||
whereArgs: [0],
|
||||
orderBy: 'sort_index ASC, updated_at DESC',
|
||||
);
|
||||
return List.generate(maps.length, (i) => NotePlusDocument.fromJson(maps[i]));
|
||||
});
|
||||
|
||||
// 分页查询
|
||||
Future<List<NotePlusDocument>> getPaged({int limit = 20, int offset = 0}) =>
|
||||
_wrap('getPaged', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final maps = await db.query('note_plus', where: 'is_deleted = 0',
|
||||
orderBy: 'sort_index ASC, updated_at DESC', limit: limit, offset: offset);
|
||||
return List.generate(maps.length, (i) => NotePlusDocument.fromJson(maps[i]));
|
||||
});
|
||||
|
||||
// 根据ID获取
|
||||
Future<NotePlusDocument?> getById(String id) => _wrap('getById', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'note_plus',
|
||||
where: 'id = ? AND is_deleted = ?',
|
||||
whereArgs: [id, 0],
|
||||
);
|
||||
if (maps.isEmpty) return null;
|
||||
return NotePlusDocument.fromJson(maps.first);
|
||||
});
|
||||
|
||||
// 插入
|
||||
Future<int> insert(NotePlusDocument doc) => _wrap('insert', () async {
|
||||
final db = await _dbHelper.database;
|
||||
return await db.insert('note_plus', doc.toJson());
|
||||
});
|
||||
|
||||
// 更新
|
||||
Future<int> update(NotePlusDocument doc) => _wrap('update', () async {
|
||||
final db = await _dbHelper.database;
|
||||
return await db.update(
|
||||
'note_plus',
|
||||
doc.toJson(),
|
||||
where: 'id = ?',
|
||||
whereArgs: [doc.id],
|
||||
);
|
||||
});
|
||||
|
||||
// 软删除
|
||||
Future<int> delete(String id) => _wrap('delete', () async {
|
||||
final db = await _dbHelper.database;
|
||||
return await db.update(
|
||||
'note_plus',
|
||||
{'is_deleted': 1, 'updated_at': DateTime.now().toIso8601String()},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
});
|
||||
|
||||
// ========== 回收站 ==========
|
||||
|
||||
Future<List<NotePlusDocument>> getDeleted() => _wrap('getDeleted', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'note_plus',
|
||||
where: 'is_deleted = ?',
|
||||
whereArgs: [1],
|
||||
orderBy: 'sort_index ASC, updated_at DESC',
|
||||
);
|
||||
return List.generate(maps.length, (i) => NotePlusDocument.fromJson(maps[i]));
|
||||
});
|
||||
|
||||
Future<int> restore(String id) => _wrap('restore', () async {
|
||||
final db = await _dbHelper.database;
|
||||
return await db.update(
|
||||
'note_plus',
|
||||
{'is_deleted': 0, 'updated_at': DateTime.now().toIso8601String()},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
});
|
||||
|
||||
Future<int> permanentDelete(String id) => _wrap('permanentDelete', () async {
|
||||
final db = await _dbHelper.database;
|
||||
return await db.delete(
|
||||
'note_plus',
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
});
|
||||
|
||||
// 搜索
|
||||
Future<List<NotePlusDocument>> search(String query) => _wrap('search', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'note_plus',
|
||||
where: '(title LIKE ? OR blocks_json LIKE ? OR tags LIKE ?) AND is_deleted = ?',
|
||||
whereArgs: ['%$query%', '%$query%', '%$query%', 0],
|
||||
orderBy: 'sort_index ASC, updated_at DESC',
|
||||
);
|
||||
return List.generate(maps.length, (i) => NotePlusDocument.fromJson(maps[i]));
|
||||
});
|
||||
|
||||
// 根据标签筛选
|
||||
Future<List<NotePlusDocument>> getByTag(String tag) => _wrap('getByTag', () async {
|
||||
final db = await _dbHelper.database;
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'note_plus',
|
||||
where: 'tags LIKE ? AND is_deleted = ?',
|
||||
whereArgs: ['%$tag%', 0],
|
||||
orderBy: 'sort_index ASC, updated_at DESC',
|
||||
);
|
||||
return List.generate(maps.length, (i) => NotePlusDocument.fromJson(maps[i]));
|
||||
});
|
||||
}
|
||||
@@ -33,7 +33,6 @@ class BackupService {
|
||||
final tags = await db.query('tags');
|
||||
final readerBooks = await db.query('reader_books');
|
||||
final bookAnnotations = await db.query('book_annotations');
|
||||
final notePlus = await db.query('note_plus');
|
||||
|
||||
// 收集图片路径
|
||||
final imagePaths = <String>{};
|
||||
@@ -92,7 +91,6 @@ class BackupService {
|
||||
'tags': tags,
|
||||
'reader_books': readerBooks,
|
||||
'book_annotations': bookAnnotations,
|
||||
'note_plus': notePlus,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -317,7 +315,6 @@ class BackupService {
|
||||
final tagsCols = await _getTableColumns(db, 'tags');
|
||||
final readerBooksCols = await _getTableColumns(db, 'reader_books');
|
||||
final bookAnnotationsCols = await _getTableColumns(db, 'book_annotations');
|
||||
final notePlusCols = await _getTableColumns(db, 'note_plus');
|
||||
|
||||
await db.transaction((txn) async {
|
||||
await txn.delete('movie_reviews');
|
||||
@@ -329,7 +326,6 @@ class BackupService {
|
||||
await txn.delete('books');
|
||||
await txn.delete('notes');
|
||||
await txn.delete('reader_books');
|
||||
await txn.delete('note_plus');
|
||||
await txn.delete('tags');
|
||||
|
||||
if (data.containsKey('movies')) {
|
||||
@@ -379,11 +375,6 @@ class BackupService {
|
||||
await txn.insert('book_annotations', _convertToDbMapSafe(a, bookAnnotationsCols));
|
||||
}
|
||||
}
|
||||
if (data.containsKey('note_plus')) {
|
||||
for (final np in data['note_plus'] as List) {
|
||||
await txn.insert('note_plus', _convertToDbMapSafe(np, notePlusCols));
|
||||
}
|
||||
}
|
||||
if (data.containsKey('tags')) {
|
||||
for (final t in data['tags'] as List) {
|
||||
final map = _convertToDbMapSafe(t, tagsCols);
|
||||
@@ -459,7 +450,6 @@ class BackupService {
|
||||
final tagsCols = await _getTableColumns(db, 'tags');
|
||||
final readerBooksCols = await _getTableColumns(db, 'reader_books');
|
||||
final bookAnnotationsCols = await _getTableColumns(db, 'book_annotations');
|
||||
final notePlusCols = await _getTableColumns(db, 'note_plus');
|
||||
|
||||
await db.transaction((txn) async {
|
||||
await txn.delete('movie_reviews');
|
||||
@@ -471,7 +461,6 @@ class BackupService {
|
||||
await txn.delete('books');
|
||||
await txn.delete('notes');
|
||||
await txn.delete('reader_books');
|
||||
await txn.delete('note_plus');
|
||||
await txn.delete('tags'); // 修复: 之前漏删 tags 表
|
||||
|
||||
if (data.containsKey('movies')) {
|
||||
@@ -521,11 +510,6 @@ class BackupService {
|
||||
await txn.insert('book_annotations', _convertToDbMapSafe(a, bookAnnotationsCols));
|
||||
}
|
||||
}
|
||||
if (data.containsKey('note_plus')) {
|
||||
for (final np in data['note_plus'] as List) {
|
||||
await txn.insert('note_plus', _convertToDbMapSafe(np, notePlusCols));
|
||||
}
|
||||
}
|
||||
if (data.containsKey('tags')) {
|
||||
for (final t in data['tags'] as List) {
|
||||
final map = _convertToDbMapSafe(t, tagsCols);
|
||||
@@ -621,7 +605,6 @@ class BackupService {
|
||||
if (data.containsKey('tags')) stats['标签'] = (data['tags'] as List).length;
|
||||
if (data.containsKey('reader_books')) stats['阅读'] = (data['reader_books'] as List).length;
|
||||
if (data.containsKey('book_annotations')) stats['批注'] = (data['book_annotations'] as List).length;
|
||||
if (data.containsKey('note_plus')) stats['高级笔记'] = (data['note_plus'] as List).length;
|
||||
if (imageCount > 0) stats['图片'] = imageCount;
|
||||
return stats;
|
||||
}
|
||||
|
||||
@@ -104,10 +104,6 @@ class UserPrefs {
|
||||
bool get showNoteTab => prefs.getBool('showNoteTab') ?? true;
|
||||
Future<bool> setShowNoteTab(bool value) => prefs.setBool('showNoteTab', value);
|
||||
|
||||
/// 是否显示 Note Plus 标签(默认关闭)
|
||||
bool get showNotePlusTab => prefs.getBool('showNotePlusTab') ?? false;
|
||||
Future<bool> setShowNotePlusTab(bool value) => prefs.setBool('showNotePlusTab', value);
|
||||
|
||||
/// 默认启动标签 (0: 影视, 1: 阅读, 2: 笔记)
|
||||
int get defaultMainTabIndex => prefs.getInt('defaultMainTabIndex') ?? 0;
|
||||
Future<bool> setDefaultMainTabIndex(int value) => prefs.setInt('defaultMainTabIndex', value);
|
||||
|
||||
Reference in New Issue
Block a user