From e510393eb8539b0e9c498439587772555b2e73e4 Mon Sep 17 00:00:00 2001 From: selfrelease Date: Mon, 31 Aug 2026 17:20:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8D=A2=E4=B8=80=E6=89=B9=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=85=88=E4=BB=8E=E7=83=AD=E7=82=B9=E6=B1=A0=E8=BD=AE?= =?UTF-8?q?=E6=8D=A2,=E7=94=A8=E5=AE=8C=E5=86=8D=E8=B0=83AI=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web2/src/components/common/ChatPanel.tsx | 27 ++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/web2/src/components/common/ChatPanel.tsx b/web2/src/components/common/ChatPanel.tsx index 23e0562..f11b16f 100644 --- a/web2/src/components/common/ChatPanel.tsx +++ b/web2/src/components/common/ChatPanel.tsx @@ -285,6 +285,10 @@ 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) + const BATCH_SIZE = 12 // ===== 2.0 新增:案卡状态 ===== const [matterId, setMatterId] = useState(null) @@ -402,12 +406,14 @@ export function ChatPanel({ setDynamicSamples(samples) }, [samples]) - /** 挂载时取当天热点问题,有则覆盖兜底示例 */ + /** 挂载时取当天热点问题,有则存入池并显示首批 */ useEffect(() => { api.getDailyTopics(scene) .then((res) => { if (res.questions?.length > 0) { - setDynamicSamples(res.questions) + setDailyPool(res.questions) + setPoolIndex(0) + setDynamicSamples(res.questions.slice(0, BATCH_SIZE)) } }) .catch(() => {/* 用兜底示例 */}) @@ -545,13 +551,26 @@ export function ChatPanel({ }, answers.length > 0 ? answers : undefined) } - /** AI 换一批示例问题(注入用户画像,个性化推荐) */ + /** 换一批:优先从当天热点池轮换,池用完再调 AI 生成(注入用户画像) */ const handleRefreshSamples = async () => { + // 池里还有未展示的,直接取下一批 + const nextIndex = poolIndex + BATCH_SIZE + if (dailyPool.length > 0 && 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) - setDynamicSamples(res.samples) + if (res.samples?.length > 0) { + setDynamicSamples(res.samples) + // AI 生成的新问题加入池,重置索引 + setDailyPool(prev => [...prev, ...res.samples]) + setPoolIndex(dailyPool.length) + } } catch { toast.error('换一批失败,请稍后重试') } finally {