fix: 会员过期时跳过事件相关 API 请求
- fetchEventStocks: 新增 skipIfNoAccess 参数 - fetchHistoricalEvents: 新增 skipIfNoAccess 参数 - fetchChainAnalysis: 新增 skipIfNoAccess 参数 - 通过检查 subscription 状态判断是否跳过请求
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user