fix: 会员过期时跳过事件相关 API 请求

- fetchEventStocks: 新增 skipIfNoAccess 参数
  - fetchHistoricalEvents: 新增 skipIfNoAccess 参数
  - fetchChainAnalysis: 新增 skipIfNoAccess 参数
  - 通过检查 subscription 状态判断是否跳过请求
This commit is contained in:
zdl
2025-12-24 15:31:39 +08:00
parent c529626ce2
commit a395d49158

View File

@@ -58,11 +58,25 @@ const saveWatchlistToCache = (data) => {
/** /**
* 获取事件相关股票Redux 缓存) * 获取事件相关股票Redux 缓存)
* @param {Object} params
* @param {string} params.eventId - 事件ID
* @param {boolean} params.forceRefresh - 是否强制刷新
* @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景)
*/ */
export const fetchEventStocks = createAsyncThunk( export const fetchEventStocks = createAsyncThunk(
'stock/fetchEventStocks', 'stock/fetchEventStocks',
async ({ eventId, forceRefresh = false }, { getState }) => { async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => {
logger.debug('stockSlice', 'fetchEventStocks', { eventId, forceRefresh }); 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 状态缓存 // Redux 状态缓存
if (!forceRefresh) { if (!forceRefresh) {
@@ -132,11 +146,25 @@ export const fetchEventDetail = createAsyncThunk(
/** /**
* 获取历史事件对比Redux 缓存) * 获取历史事件对比Redux 缓存)
* @param {Object} params
* @param {string} params.eventId - 事件ID
* @param {boolean} params.forceRefresh - 是否强制刷新
* @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景)
*/ */
export const fetchHistoricalEvents = createAsyncThunk( export const fetchHistoricalEvents = createAsyncThunk(
'stock/fetchHistoricalEvents', 'stock/fetchHistoricalEvents',
async ({ eventId, forceRefresh = false }, { getState }) => { async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => {
logger.debug('stockSlice', 'fetchHistoricalEvents', { eventId }); 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 缓存 // Redux 缓存
if (!forceRefresh) { if (!forceRefresh) {
@@ -158,11 +186,25 @@ export const fetchHistoricalEvents = createAsyncThunk(
/** /**
* 获取传导链分析Redux 缓存) * 获取传导链分析Redux 缓存)
* @param {Object} params
* @param {string} params.eventId - 事件ID
* @param {boolean} params.forceRefresh - 是否强制刷新
* @param {boolean} params.skipIfNoAccess - 如果无权限则跳过请求(会员过期场景)
*/ */
export const fetchChainAnalysis = createAsyncThunk( export const fetchChainAnalysis = createAsyncThunk(
'stock/fetchChainAnalysis', 'stock/fetchChainAnalysis',
async ({ eventId, forceRefresh = false }, { getState }) => { async ({ eventId, forceRefresh = false, skipIfNoAccess = false }, { getState }) => {
logger.debug('stockSlice', 'fetchChainAnalysis', { eventId }); 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 缓存 // Redux 缓存
if (!forceRefresh) { if (!forceRefresh) {