feat: 人生事件和剧本收藏从 localStorage 切换为真实 API
- 后端:新增 t_event_favorite 表(UNIQUE KEY + MyBatis-Plus Entity) - 后端:LifeEventController 新增 /favorite/toggle、/favorite/page、/favorite/check 三个真实端点 - 后端:EventFavoriteService 完整 CRUD,含 toggle/分页/批量查询/状态检查 - 后端:删除旧的 favorite-placeholder mock 端点 - 前端:life-event/detail.vue 从 localStorage 假收藏切换为真实 API + localStorage 缓存防闪烁 - 前端:ScriptLibraryView.vue 从 localFavorites 切换为 checkFavoriteScript 真实 API - 前端:stores/app.js 新增 toggleEventFavorite / checkEventFavorite 方法 - 修复:审核发现的 UNIQUE 约束缺失、未使用 watch 导入、Controller 参数注解遗漏、Controller 委托 Service 构造 Response Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,8 +64,28 @@ export const shareEvent = async (eventData = {}) => {
|
||||
return post('/lifeEvent/share-placeholder', eventData)
|
||||
}
|
||||
|
||||
export const favoriteEvent = async ({ id, favorite }) => {
|
||||
return post('/lifeEvent/favorite-placeholder', { id, favorite })
|
||||
/**
|
||||
* 切换人生事件收藏状态(收藏/取消收藏)
|
||||
* @param {string} eventId 事件ID
|
||||
* @returns {Promise<{success: boolean, isFavorited: boolean}>}
|
||||
*/
|
||||
export const toggleFavoriteEvent = async (eventId) => {
|
||||
const res = await post('/lifeEvent/favorite/toggle', { eventId })
|
||||
return {
|
||||
success: true,
|
||||
isFavorited: res.data?.isFavorited ?? false,
|
||||
favoriteTime: res.data?.favoriteTime ?? null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查人生事件是否已收藏
|
||||
* @param {string} eventId 事件ID
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export const checkFavoriteEvent = async (eventId) => {
|
||||
const res = await get('/lifeEvent/favorite/check', { eventId })
|
||||
return res.data?.isFavorited ?? false
|
||||
}
|
||||
|
||||
const transformToBackendFormat = (frontendData) => {
|
||||
@@ -153,7 +173,8 @@ export default {
|
||||
assistEventWriting,
|
||||
chatAboutEvent,
|
||||
shareEvent,
|
||||
favoriteEvent,
|
||||
toggleFavoriteEvent,
|
||||
checkFavoriteEvent,
|
||||
transformToFrontendFormat,
|
||||
transformListToFrontend
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user