Merge branch 'feature_bugfix/251201_vf_h5_ui' into feature_2025/251209_stock_pref
* feature_bugfix/251201_vf_h5_ui: feat: 事件关注功能优化 - Redux 乐观更新 + Mock 数据状态同步 feat: 投资日历自选股功能优化 - Redux 集成 + 乐观更新 fix: 修复投资日历切换月份时自动打开事件弹窗的问题 fix: 修复 CompanyOverview 中 Hooks 顺序错误
This commit is contained in:
@@ -128,6 +128,13 @@ export const mockRealtimeQuotes = [
|
||||
|
||||
// ==================== 关注事件数据 ====================
|
||||
|
||||
// 事件关注内存存储(Set 存储已关注的事件 ID)
|
||||
export const followedEventsSet = new Set();
|
||||
|
||||
// 关注事件完整数据存储(Map: eventId -> eventData)
|
||||
export const followedEventsMap = new Map();
|
||||
|
||||
// 初始关注事件列表(用于初始化)
|
||||
export const mockFollowingEvents = [
|
||||
{
|
||||
id: 101,
|
||||
@@ -231,6 +238,74 @@ export const mockFollowingEvents = [
|
||||
}
|
||||
];
|
||||
|
||||
// 初始化:将 mockFollowingEvents 的数据加入内存存储
|
||||
mockFollowingEvents.forEach(event => {
|
||||
followedEventsSet.add(event.id);
|
||||
followedEventsMap.set(event.id, event);
|
||||
});
|
||||
|
||||
/**
|
||||
* 切换事件关注状态
|
||||
* @param {number} eventId - 事件 ID
|
||||
* @param {Object} eventData - 事件数据(关注时需要)
|
||||
* @returns {{ isFollowing: boolean, followerCount: number }}
|
||||
*/
|
||||
export function toggleEventFollowStatus(eventId, eventData = null) {
|
||||
const wasFollowing = followedEventsSet.has(eventId);
|
||||
|
||||
if (wasFollowing) {
|
||||
// 取消关注
|
||||
followedEventsSet.delete(eventId);
|
||||
followedEventsMap.delete(eventId);
|
||||
} else {
|
||||
// 添加关注
|
||||
followedEventsSet.add(eventId);
|
||||
if (eventData) {
|
||||
followedEventsMap.set(eventId, {
|
||||
...eventData,
|
||||
followed_at: new Date().toISOString()
|
||||
});
|
||||
} else {
|
||||
// 如果没有提供事件数据,创建基础数据
|
||||
followedEventsMap.set(eventId, {
|
||||
id: eventId,
|
||||
title: `事件 ${eventId}`,
|
||||
tags: [],
|
||||
followed_at: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const isFollowing = !wasFollowing;
|
||||
const followerCount = isFollowing ? Math.floor(Math.random() * 500) + 100 : Math.floor(Math.random() * 500) + 50;
|
||||
|
||||
console.log('[Mock Data] 切换事件关注状态:', {
|
||||
eventId,
|
||||
wasFollowing,
|
||||
isFollowing,
|
||||
followedEventsCount: followedEventsSet.size
|
||||
});
|
||||
|
||||
return { isFollowing, followerCount };
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查事件是否已关注
|
||||
* @param {number} eventId - 事件 ID
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isEventFollowed(eventId) {
|
||||
return followedEventsSet.has(eventId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已关注的事件列表
|
||||
* @returns {Array}
|
||||
*/
|
||||
export function getFollowedEvents() {
|
||||
return Array.from(followedEventsMap.values());
|
||||
}
|
||||
|
||||
// ==================== 评论数据 ====================
|
||||
|
||||
export const mockEventComments = [
|
||||
|
||||
Reference in New Issue
Block a user