From 7f5d3ce5a6b5a04e4145f26f4b87b33be0970764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Fri, 15 Aug 2025 16:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=83=85=E7=BB=AA=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=AF=B9=E8=AF=9D=E6=95=B0=E9=99=90=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E6=9F=A5=E8=AF=A2=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E5=8F=AA=E8=82=A1=E7=A5=A8=E4=B8=8D=E5=86=8D=E5=8E=BB=E9=87=8D?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/emotion.ts | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/store/emotion.ts b/src/store/emotion.ts index 6ab6192..1e4bbaf 100644 --- a/src/store/emotion.ts +++ b/src/store/emotion.ts @@ -6,9 +6,7 @@ export const useEmotionStore = defineStore('emotion', { history: [] as HistoryItem[], // 历史记录数组 stockList: [] as StockData[], // 当前显示的股票列表 activeStockIndex: 0, // 当前激活的股票索引 - maxStocks: 10, // 最大股票数量限制 conversations: [] as ConversationMessage[], // 对话消息数组 - maxConversations: 100, // 最大对话数量限制 }), persist: { key: 'emotion-store', @@ -22,12 +20,8 @@ export const useEmotionStore = defineStore('emotion', { }, // 获取股票数量 stockCount: (state) => state.stockList.length, - // 是否达到最大股票数量 - isMaxStocks: (state) => state.stockList.length >= state.maxStocks, // 获取对话数量 conversationCount: (state) => state.conversations.length, - // 是否达到最大对话数量 - isMaxConversations: (state) => state.conversations.length >= state.maxConversations, // 获取最近的对话消息 recentConversations: (state) => { return state.conversations.slice(-20); // 返回最近20条对话 @@ -44,28 +38,9 @@ export const useEmotionStore = defineStore('emotion', { }, // 添加新股票 addStock(stockData: StockData) { - // 检查是否已存在相同的股票 - const existingIndex = this.stockList.findIndex( - stock => stock.stockInfo.code === stockData.stockInfo.code && - stock.stockInfo.market === stockData.stockInfo.market - ); - - if (existingIndex !== -1) { - // 如果股票已存在,更新数据并切换到该股票 - this.stockList[existingIndex] = stockData; - this.activeStockIndex = existingIndex; - } else { - // 如果达到最大数量,移除最旧的股票 - if (this.stockList.length >= this.maxStocks) { - this.stockList.shift(); - if (this.activeStockIndex > 0) { - this.activeStockIndex--; - } - } - // 添加新股票并设为当前激活 - this.stockList.push(stockData); - this.activeStockIndex = this.stockList.length - 1; - } + // 添加新股票并设为当前激活 + this.stockList.push(stockData); + this.activeStockIndex = this.stockList.length - 1; // 同时添加到历史记录 // this.addHistory({ @@ -130,10 +105,6 @@ export const useEmotionStore = defineStore('emotion', { }, // 添加对话消息 addConversation(message: ConversationMessage) { - // 如果达到最大数量,移除最旧的消息 - if (this.conversations.length >= this.maxConversations) { - this.conversations.shift(); - } // 添加新消息到数组末尾 this.conversations.push({ ...message,