细节优化

This commit is contained in:
Developer
2026-04-10 06:22:06 +08:00
parent 73036a8856
commit 0d8a5ecbda
40 changed files with 3098 additions and 934 deletions

View File

@@ -388,6 +388,7 @@ class HistoryController {
/// - isPinned: 是否置顶true/false
/// - isLocked: 是否锁定true/false
/// - password: 访问密码(加密存储)
/// - passwordHint: 密码提示(用于找回密码)
/// - category: 分类(可选)
/// 获取所有笔记列表
@@ -462,6 +463,7 @@ class HistoryController {
/// [isPinned] 是否置顶
/// [isLocked] 是否锁定
/// [password] 访问密码
/// [passwordHint] 密码提示
/// [category] 分类
/// [createTime] 创建时间(可选,用于保留原创建时间)
/// 返回笔记ID
@@ -472,6 +474,7 @@ class HistoryController {
bool? isPinned,
bool? isLocked,
String? password,
String? passwordHint,
String? category,
String? createTime,
}) async {
@@ -484,6 +487,7 @@ class HistoryController {
bool pinned = isPinned ?? false;
bool locked = isLocked ?? false;
String? pwd = password;
String? hint = passwordHint;
String? cat = category;
String? ct = createTime;
@@ -501,6 +505,9 @@ class HistoryController {
if (password == null) {
pwd = existingNote['password'];
}
if (passwordHint == null) {
hint = existingNote['passwordHint'];
}
if (category == null) {
cat = existingNote['category'];
}
@@ -525,6 +532,7 @@ class HistoryController {
'isPinned': pinned,
'isLocked': locked,
'password': pwd,
'passwordHint': hint,
'category': cat,
};
@@ -646,6 +654,60 @@ class HistoryController {
}
}
/// 验证密码提示
static Future<bool> verifyNotePasswordHint(String noteId, String hint) async {
try {
final notes = await getNotes();
final note = notes.firstWhere(
(n) => n['id'] == noteId,
orElse: () => <String, dynamic>{},
);
if (note.isEmpty) {
return false;
}
final storedHint = note['passwordHint'] as String?;
if (storedHint == null || storedHint.isEmpty) {
return false;
}
return storedHint == hint;
} catch (e) {
return false;
}
}
/// 通过密码提示重置密码
static Future<bool> resetNotePasswordByHint(
String noteId,
String hint,
) async {
try {
final notes = await getNotes();
final index = notes.indexWhere((n) => n['id'] == noteId);
if (index == -1) {
return false;
}
final storedHint = notes[index]['passwordHint'] as String?;
if (storedHint == null || storedHint.isEmpty || storedHint != hint) {
return false;
}
notes[index]['isLocked'] = false;
notes[index]['password'] = null;
final notesJson = json.encode(notes);
await SharedPreferencesStorageController.setString(_notesKey, notesJson);
return true;
} catch (e) {
return false;
}
}
static Future<int> getNotesCount() async {
try {
final notes = await getNotes();

View File

@@ -1,7 +1,6 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../constants/app_constants.dart';
import '../../services/get/theme_controller.dart';
import '../../models/colors/app_colors.dart';
import '../../views/profile/theme/app-diy.dart';