fix: 搜索功能空值检查修复

This commit is contained in:
yuantao
2025-10-17 09:09:32 +08:00
parent 5858c6c163
commit f2f3756cc0
2 changed files with 314 additions and 157 deletions

File diff suppressed because one or more lines are too long

View File

@@ -97,11 +97,13 @@ const trashNotesCount = computed(() => {
// 根据当前文件夹过滤便签
const filteredNotes = computed(() => {
// 预处理搜索查询,提高性能
const lowerCaseQuery = searchQuery.value.toLowerCase().trim()
const lowerCaseQuery = searchQuery.value?.toLowerCase().trim() || ''
return store.notes.filter(note => {
// 先检查搜索条件
const matchesSearch = !lowerCaseQuery || note.title.toLowerCase().includes(lowerCaseQuery) || note.content.toLowerCase().includes(lowerCaseQuery)
const matchesSearch = !lowerCaseQuery ||
(note.title && note.title.toLowerCase().includes(lowerCaseQuery)) ||
(note.content && note.content.toLowerCase().includes(lowerCaseQuery))
if (!matchesSearch) return false