(trashIndex)
| 4028 | |
| 4029 | // 从回收站恢复笔记 |
| 4030 | function restoreNoteFromTrash(trashIndex) { |
| 4031 | const trashData = readJSON(LS_KEYS.trash, []); |
| 4032 | if (trashIndex < 0 || trashIndex >= trashData.length) { |
| 4033 | alert('找不到要恢复的笔记'); |
| 4034 | return; |
| 4035 | } |
| 4036 | |
| 4037 | const trashNote = trashData[trashIndex]; |
| 4038 | const { deletedAt, originalCategoryId, originalCategoryName, ...noteData } = trashNote; |
| 4039 | |
| 4040 | // 检查原分类是否还存在 |
| 4041 | const categories = readJSON(LS_KEYS.categories, []); |
| 4042 | const categoryExists = categories.some(c => c.id === originalCategoryId); |
| 4043 | |
| 4044 | let targetCategoryId = originalCategoryId; |
| 4045 | if (!categoryExists) { |
| 4046 | // 原分类不存在,恢复到默认分类 |
| 4047 | targetCategoryId = 'default'; |
| 4048 | alert(`原分类"${originalCategoryName}"已不存在,笔记将恢复到默认分类`); |
| 4049 | } |
| 4050 | |
| 4051 | // 恢复笔记到目标分类 |
| 4052 | const map = readJSON(LS_KEYS.notes, {}); |
| 4053 | if (!map[targetCategoryId]) { |
| 4054 | map[targetCategoryId] = []; |
| 4055 | } |
| 4056 | map[targetCategoryId].unshift(noteData); |
| 4057 | writeJSON(LS_KEYS.notes, map); |
| 4058 | |
| 4059 | // 从回收站移除 |
| 4060 | trashData.splice(trashIndex, 1); |
| 4061 | writeJSON(LS_KEYS.trash, trashData); |
| 4062 | |
| 4063 | // 已成功恢复,不再弹窗打断用户 |
| 4064 | // alert(`笔记"${noteData.title || '未命名'}"已成功恢复`); |
| 4065 | } |
| 4066 | |
| 4067 | // 永久删除笔记 |
| 4068 | function permanentDeleteNote(trashIndex) { |
no test coverage detected