diff --git a/src/store/slices/stockSlice.js b/src/store/slices/stockSlice.js index 37622694..9c7b0bf1 100644 --- a/src/store/slices/stockSlice.js +++ b/src/store/slices/stockSlice.js @@ -340,6 +340,26 @@ const stockSlice = createSlice({ delete state.historicalEventsCache[eventId]; delete state.chainAnalysisCache[eventId]; delete state.expectationScores[eventId]; + }, + + /** + * 乐观更新:添加自选股(同步) + */ + optimisticAddWatchlist: (state, action) => { + const { stockCode, stockName } = action.payload; + // 避免重复添加 + const exists = state.watchlist.some(item => item.stock_code === stockCode); + if (!exists) { + state.watchlist.push({ stock_code: stockCode, stock_name: stockName || '' }); + } + }, + + /** + * 乐观更新:移除自选股(同步) + */ + optimisticRemoveWatchlist: (state, action) => { + const { stockCode } = action.payload; + state.watchlist = state.watchlist.filter(item => item.stock_code !== stockCode); } }, extraReducers: (builder) => { @@ -461,7 +481,9 @@ export const { updateQuote, updateQuotes, clearQuotes, - clearEventCache + clearEventCache, + optimisticAddWatchlist, + optimisticRemoveWatchlist } = stockSlice.actions; export default stockSlice.reducer;