提交 23a38b15 authored 作者: yueweilu's avatar yueweilu

用户退出登录 删除数据库和缓存数据

上级 59b05681
......@@ -162,6 +162,7 @@ class _UserSetPageState extends State<UserSetPage> {
// Toast.show('退出成功');
CustomToast.loading();
await UserStore.to.logout();
await Tools.clearData();
CustomToast.dismiss();
if (context.mounted) {
context.goNamed(Routes.splash);
......
......@@ -270,6 +270,7 @@ class _RequestInterceptor extends Interceptor {
} else {
UserStore.to.logout();
await Tools.clearData();
CustomToast.fail('该账号已在其他设备登录,请重新登录');
Console.log('-------------------access_token-------------------------${UserStore.to.accessToken}--------------------');
......
......@@ -71,14 +71,14 @@ class SqlManager {
Map<String, dynamic> returnMap = {};
// 划线
List<Map<String, dynamic>>? lineResult = await db?.query(
'members_book_notes',
kNoteTable,
columns: ['types', 'chapter_id','positioning','content','color','id'],
where: 'book_id = ? and chapter_id = ? and types = ? and del = ?',
whereArgs: [bookId, chapterId,1,0],
);
// 高亮
List<Map<String, dynamic>>? colorResult = await db?.query(
'members_book_notes',
kNoteTable,
columns: ['types', 'chapter_id','positioning','content','color','id'],
where: 'book_id = ? and chapter_id = ? and types = ? and del = ?',
whereArgs: [bookId, chapterId,2,0],
......@@ -93,7 +93,7 @@ class SqlManager {
static Future<int> addLocalNote(Map<String, dynamic> data) async {
Database? db = await SqlManager.getCurrentDatabase();
final result = await db?.insert(
'members_book_notes',
kNoteTable,
data,
conflictAlgorithm: ConflictAlgorithm.replace,
);
......@@ -105,7 +105,7 @@ class SqlManager {
Database? db = await SqlManager.getCurrentDatabase();
if(noteId == 0){
final result = await db?.update(
'members_book_notes',
kNoteTable,
{'del': 1},
where: 'id = ?',
whereArgs: [id],
......@@ -114,7 +114,7 @@ class SqlManager {
}
else{
final result = await db?.update(
'members_book_notes',
kNoteTable,
{'del': 1},
where: 'notes_id = ?',
whereArgs: [noteId],
......@@ -129,7 +129,7 @@ class SqlManager {
Database? db = await SqlManager.getCurrentDatabase();
if(notesId ==0){
final result = await db?.update(
'members_book_notes',
kNoteTable,
data,
where: 'id = ?',
whereArgs: [id],
......@@ -138,7 +138,7 @@ class SqlManager {
}
else{
final result = await db?.update(
'members_book_notes',
kNoteTable,
data,
where: 'notes_id = ?',
whereArgs: [notesId],
......@@ -152,7 +152,7 @@ class SqlManager {
static Future<List<Map<String, dynamic>>> queryNoUploadData() async {
Database? db = await SqlManager.getCurrentDatabase();
List<Map<String, dynamic>>? results = await db?.query(
'members_book_notes',
kNoteTable,
where: 'upload = ? and del = ?',
whereArgs: [0,0],
);
......@@ -163,11 +163,12 @@ class SqlManager {
// );
return results ??[];
}
// 将所有 upload 为 0 的数据的 upload 字段值更新为 1
static Future<void> updateUploadStatus() async {
Database? db = await SqlManager.getCurrentDatabase();
final result = await db?.update(
'members_book_notes',
kNoteTable,
{'upload': 1},
where: 'upload = ?',
whereArgs: [0],
......@@ -199,6 +200,11 @@ class SqlManager {
await db?.execute(sql);
}
static Future<void> clear() async {
Database? db = await SqlManager.getCurrentDatabase();
db?.delete(kNoteTable);
db?.delete(kReadTable);
}
// 根据 book_id 查询当前读到的 章节
static Future<String> queryReadHistoryByBookId(int bookId) async {
try {
......@@ -207,7 +213,7 @@ class SqlManager {
await init();
}
List<Map<String, dynamic>>? results = await db?.query(
'read_history',
kReadTable,
where: 'book_id = ?',
whereArgs: [bookId],
);
......
......@@ -38,7 +38,7 @@ abstract class Tools {
static Future<String> getDirectory() async {
// getTemporaryDirectory
final directory = await getExternalStorageDirectory();
final directory = await getTemporaryDirectory();
return directory!.path;
}
......@@ -49,6 +49,12 @@ abstract class Tools {
return 'voice_$formattedDate.mp4';
}
static Future<void> clearData() async {
await SqlManager.clear();
ClearCache().clearApplicationCache();
Console.log('-------------清除数据-------------------');
}
// 判断当前网络状态
static Future<bool> checkCurrentNetStatus() async {
final connectivityResult = await (Connectivity().checkConnectivity());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论