docs(changelog): add code refactoring entry for useCollectOperation
Document the extraction of duplicate collection logic into a reusable composable. - Created useCollectOperation composable with optimistic UI updates - Refactored index and material-list pages (removed 89 lines of duplicate code) - Fixed runtime module resolution issue - Net reduction: 82 lines of code
Showing
1 changed file
with
27 additions
and
0 deletions
| ... | @@ -5,6 +5,33 @@ | ... | @@ -5,6 +5,33 @@ |
| 5 | 5 | ||
| 6 | --- | 6 | --- |
| 7 | 7 | ||
| 8 | +## [2026-02-05] - 代码重构:收藏操作逻辑抽取 | ||
| 9 | + | ||
| 10 | +### 重构 | ||
| 11 | +- **收藏操作 Composable** (`src/composables/useCollectOperation.js`) | ||
| 12 | + - 提取重复的收藏/取消收藏逻辑为可复用的 Composable | ||
| 13 | + - 实现乐观更新模式,UI 立即响应,API 失败时自动回滚 | ||
| 14 | + - 统一错误处理和用户反馈 (Toast 提示) | ||
| 15 | + - 支持 `meta_id` 和 `id` 两种字段格式 | ||
| 16 | + - 完整的 JSDoc 注释和使用示例 | ||
| 17 | + - 修复运行时模块解析问题 (使用相对路径导入) | ||
| 18 | + | ||
| 19 | +### 代码质量提升 | ||
| 20 | +- **首页** (`src/pages/index/index.vue`) | ||
| 21 | + - 移除 44 行重复的收藏操作代码 | ||
| 22 | + - 使用 `useCollectOperation` Composable 替代 | ||
| 23 | +- **资料列表页** (`src/pages/material-list/index.vue`) | ||
| 24 | + - 移除 45 行重复的收藏操作代码 | ||
| 25 | + - 使用 `useCollectOperation` Composable 替代 | ||
| 26 | + | ||
| 27 | +### 影响 | ||
| 28 | +- **代码量**: 净减少 82 行代码 (91 行删除, 7 行新增, 1 个新文件) | ||
| 29 | +- **可维护性**: 遵循 DRY 原则,消除代码重复 | ||
| 30 | +- **可复用性**: 统一的收藏逻辑可在多页面复用 | ||
| 31 | +- **一致性**: 所有收藏操作使用相同的错误处理和用户反馈 | ||
| 32 | + | ||
| 33 | +--- | ||
| 34 | + | ||
| 8 | ## [2026-02-05] - 文档模块接口联调完成 | 35 | ## [2026-02-05] - 文档模块接口联调完成 |
| 9 | 36 | ||
| 10 | ### 新增 | 37 | ### 新增 | ... | ... |
-
Please register or login to post a comment