fix: 换一批改为先从热点池轮换,用完再调AI生成
This commit is contained in:
@@ -285,6 +285,10 @@ export function ChatPanel({
|
|||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [dynamicSamples, setDynamicSamples] = useState<string[]>(samples)
|
const [dynamicSamples, setDynamicSamples] = useState<string[]>(samples)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
/** 当天热点问题池(从后端加载的全部问题)和当前批次起始索引 */
|
||||||
|
const [dailyPool, setDailyPool] = useState<string[]>([])
|
||||||
|
const [poolIndex, setPoolIndex] = useState(0)
|
||||||
|
const BATCH_SIZE = 12
|
||||||
|
|
||||||
// ===== 2.0 新增:案卡状态 =====
|
// ===== 2.0 新增:案卡状态 =====
|
||||||
const [matterId, setMatterId] = useState<number | null>(null)
|
const [matterId, setMatterId] = useState<number | null>(null)
|
||||||
@@ -402,12 +406,14 @@ export function ChatPanel({
|
|||||||
setDynamicSamples(samples)
|
setDynamicSamples(samples)
|
||||||
}, [samples])
|
}, [samples])
|
||||||
|
|
||||||
/** 挂载时取当天热点问题,有则覆盖兜底示例 */
|
/** 挂载时取当天热点问题,有则存入池并显示首批 */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api.getDailyTopics(scene)
|
api.getDailyTopics(scene)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.questions?.length > 0) {
|
if (res.questions?.length > 0) {
|
||||||
setDynamicSamples(res.questions)
|
setDailyPool(res.questions)
|
||||||
|
setPoolIndex(0)
|
||||||
|
setDynamicSamples(res.questions.slice(0, BATCH_SIZE))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {/* 用兜底示例 */})
|
.catch(() => {/* 用兜底示例 */})
|
||||||
@@ -545,13 +551,26 @@ export function ChatPanel({
|
|||||||
}, answers.length > 0 ? answers : undefined)
|
}, answers.length > 0 ? answers : undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** AI 换一批示例问题(注入用户画像,个性化推荐) */
|
/** 换一批:优先从当天热点池轮换,池用完再调 AI 生成(注入用户画像) */
|
||||||
const handleRefreshSamples = async () => {
|
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)
|
setRefreshing(true)
|
||||||
try {
|
try {
|
||||||
const phone = getPhone() || undefined
|
const phone = getPhone() || undefined
|
||||||
const res = await api.generateSamples(scene, topic, dynamicSamples, phone)
|
const res = await api.generateSamples(scene, topic, dynamicSamples, phone)
|
||||||
|
if (res.samples?.length > 0) {
|
||||||
setDynamicSamples(res.samples)
|
setDynamicSamples(res.samples)
|
||||||
|
// AI 生成的新问题加入池,重置索引
|
||||||
|
setDailyPool(prev => [...prev, ...res.samples])
|
||||||
|
setPoolIndex(dailyPool.length)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
toast.error('换一批失败,请稍后重试')
|
toast.error('换一批失败,请稍后重试')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user