From 90391729bbf4fead50287b45a80faba6e2effc25 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Tue, 9 Dec 2025 15:15:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E8=87=AA=E9=80=89?= =?UTF-8?q?=E8=82=A1=E4=B9=90=E8=A7=82=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/slices/stockSlice.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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;