diff --git a/src/store/slices/stockSlice.js b/src/store/slices/stockSlice.js index 0aba0392..b49bd9d4 100644 --- a/src/store/slices/stockSlice.js +++ b/src/store/slices/stockSlice.js @@ -58,11 +58,25 @@ const saveWatchlistToCache = (data) => { /** * 获取事件相关股票(Redux 缓存) + * @param {Object} params + * @param {string} params.eventId - 事件ID + * @param {boolean} params.forceRefresh - 是否强制刷新 + * @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景) */ export const fetchEventStocks = createAsyncThunk( 'stock/fetchEventStocks', - async ({ eventId, forceRefresh = false }, { getState }) => { - logger.debug('stockSlice', 'fetchEventStocks', { eventId, forceRefresh }); + async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => { + logger.debug('stockSlice', 'fetchEventStocks', { eventId, forceRefresh, skipIfNoAccess }); + + // 检查订阅状态,如果会员过期则跳过请求 + if (skipIfNoAccess) { + const subscriptionInfo = getState().subscription?.info; + const isExpired = subscriptionInfo?.type !== 'free' && !subscriptionInfo?.is_active; + if (isExpired) { + logger.debug('stockSlice', '会员已过期,跳过 fetchEventStocks 请求', { eventId }); + return { eventId, stocks: [], skipped: true }; + } + } // Redux 状态缓存 if (!forceRefresh) { @@ -132,11 +146,25 @@ export const fetchEventDetail = createAsyncThunk( /** * 获取历史事件对比(Redux 缓存) + * @param {Object} params + * @param {string} params.eventId - 事件ID + * @param {boolean} params.forceRefresh - 是否强制刷新 + * @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景) */ export const fetchHistoricalEvents = createAsyncThunk( 'stock/fetchHistoricalEvents', - async ({ eventId, forceRefresh = false }, { getState }) => { - logger.debug('stockSlice', 'fetchHistoricalEvents', { eventId }); + async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => { + logger.debug('stockSlice', 'fetchHistoricalEvents', { eventId, skipIfNoAccess }); + + // 检查订阅状态,如果会员过期则跳过请求 + if (skipIfNoAccess) { + const subscriptionInfo = getState().subscription?.info; + const isExpired = subscriptionInfo?.type !== 'free' && !subscriptionInfo?.is_active; + if (isExpired) { + logger.debug('stockSlice', '会员已过期,跳过 fetchHistoricalEvents 请求', { eventId }); + return { eventId, events: [], skipped: true }; + } + } // Redux 缓存 if (!forceRefresh) { @@ -158,11 +186,25 @@ export const fetchHistoricalEvents = createAsyncThunk( /** * 获取传导链分析(Redux 缓存) + * @param {Object} params + * @param {string} params.eventId - 事件ID + * @param {boolean} params.forceRefresh - 是否强制刷新 + * @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景) */ export const fetchChainAnalysis = createAsyncThunk( 'stock/fetchChainAnalysis', - async ({ eventId, forceRefresh = false }, { getState }) => { - logger.debug('stockSlice', 'fetchChainAnalysis', { eventId }); + async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => { + logger.debug('stockSlice', 'fetchChainAnalysis', { eventId, skipIfNoAccess }); + + // 检查订阅状态,如果会员过期则跳过请求 + if (skipIfNoAccess) { + const subscriptionInfo = getState().subscription?.info; + const isExpired = subscriptionInfo?.type !== 'free' && !subscriptionInfo?.is_active; + if (isExpired) { + logger.debug('stockSlice', '会员已过期,跳过 fetchChainAnalysis 请求', { eventId }); + return { eventId, analysis: null, skipped: true }; + } + } // Redux 缓存 if (!forceRefresh) {