From f3e3ee3c71df71b145be62f49e550281176c9574 Mon Sep 17 00:00:00 2001 From: selfrelease Date: Mon, 31 Aug 2026 17:25:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8D=A2=E4=B8=80=E6=89=B9=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E9=83=BD=E8=B0=83AI=E6=B3=A8=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=94=BB=E5=83=8F=E7=94=9F=E6=88=90,=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=BF=BD=E5=8A=A0=E5=88=B0=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web2/src/components/common/ChatPanel.tsx | 25 ++++++------------------ 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/web2/src/components/common/ChatPanel.tsx b/web2/src/components/common/ChatPanel.tsx index 9442859..7f93557 100644 --- a/web2/src/components/common/ChatPanel.tsx +++ b/web2/src/components/common/ChatPanel.tsx @@ -285,9 +285,8 @@ export function ChatPanel({ const [loading, setLoading] = useState(false) const [dynamicSamples, setDynamicSamples] = useState(samples) const [refreshing, setRefreshing] = useState(false) - /** 当天热点问题池(从后端加载的全部问题)和当前批次起始索引 */ - const [dailyPool, setDailyPool] = useState([]) - const [poolIndex, setPoolIndex] = useState(0) + /** 当天热点问题池(从后端加载 + AI 追加),用 ref 避免闭包旧值 */ + const dailyPoolRef = useRef([]) const BATCH_SIZE = 12 // ===== 2.0 新增:案卡状态 ===== @@ -411,8 +410,7 @@ export function ChatPanel({ api.getDailyTopics(scene) .then((res) => { if (res.questions?.length > 0) { - setDailyPool(res.questions) - setPoolIndex(0) + dailyPoolRef.current = res.questions setDynamicSamples(res.questions.slice(0, BATCH_SIZE)) } }) @@ -551,26 +549,15 @@ export function ChatPanel({ }, answers.length > 0 ? answers : undefined) } - /** 换一批:优先从当天热点池轮换,池用完再调 AI 生成(注入用户画像) */ + /** 换一批:每次都调 AI 生成(注入用户画像),新问题追加到池中 */ const handleRefreshSamples = async () => { - // 池里还有未展示的,直接取下一批 - const nextIndex = poolIndex + BATCH_SIZE - if (nextIndex < dailyPool.length) { - setPoolIndex(nextIndex) - setDynamicSamples(dailyPool.slice(nextIndex, nextIndex + BATCH_SIZE)) - return - } - // 池用完,调 AI 生成新问题 setRefreshing(true) try { const phone = getPhone() || undefined const res = await api.generateSamples(scene, topic, dynamicSamples, phone) if (res.samples?.length > 0) { - // AI 生成的新问题加入池并显示 - const newPool = [...dailyPool, ...res.samples] - const newIndex = dailyPool.length - setDailyPool(newPool) - setPoolIndex(newIndex) + // 新问题追加到池末尾并显示 + dailyPoolRef.current = [...dailyPoolRef.current, ...res.samples] setDynamicSamples(res.samples) } } catch {