完善图片生成状态管理和显示

This commit is contained in:
Your Name 2025-12-19 01:54:20 +08:00
parent 9058f4a7f1
commit b3da726b2d
3 changed files with 40 additions and 15 deletions

View File

@ -300,26 +300,31 @@ export function Chat({
});
// 调试:监控聊天状态变化 & 持久化生成状态
// 使用 ref 来访问最新的 modelsData,避免依赖数组问题
const modelsDataRef = useRef(modelsData);
useEffect(() => {
console.log(`[Chat] Status: ${status}`);
modelsDataRef.current = modelsData;
}, [modelsData]);
useEffect(() => {
console.log(`[Chat] Status changed: ${status}`);
// 🆕 当状态变为 submitted 时,记录生成任务
if (status === "submitted") {
// 判断模型类型
let modelType: PendingGeneration["modelType"] = "other";
if (currentModel?.providerType === "gemini") {
modelType = "gemini";
} else if (currentModel?.providerType === "volcano-vision") {
modelType = "volcano-vision";
} else if (currentModel?.providerType === "volcano-video") {
modelType = "volcano-video";
} else if (currentModel?.providerType === "qianwen-video") {
modelType = "qianwen-video";
}
// 判断模型类型 - 使用 ref 获取最新的 modelsData
const models = modelsDataRef.current?.models;
const model = models?.find((m: any) => m.id === currentModelId);
let modelType: PendingGeneration["modelType"] = "other";
if (model?.providerType === "gemini") modelType = "gemini";
else if (model?.providerType === "volcano-vision") modelType = "volcano-vision";
else if (model?.providerType === "volcano-video") modelType = "volcano-video";
else if (model?.providerType === "qianwen-video") modelType = "qianwen-video";
console.log(`[Chat] 🚀 记录生成任务: modelType=${modelType}, modelId=${currentModelId}`);
startGeneration(currentModelId, modelType);
}
}, [status, currentModelId, currentModel?.providerType, startGeneration]);
}, [status, currentModelId, startGeneration]);
const searchParams = useSearchParams();
const query = searchParams.get("query");

View File

@ -231,10 +231,25 @@ function PureMessages({
// 恢复的待处理状态:有 pendingGeneration 且最后一条是用户消息
const hasRestoredPending = pendingGeneration && isWaitingForResponse;
// 🔍 调试日志
console.log("[Messages] 占位图状态检查:", {
pendingGeneration,
lastMessageRole: lastMessage?.role,
isWaitingForResponse,
hasRestoredPending,
showThinkingWithDelay,
messagesCount: messages.length,
});
// 显示条件:正常等待动画 或 恢复的待处理状态
const shouldShow = showThinkingWithDelay || hasRestoredPending;
if (!shouldShow) return null;
if (!shouldShow) {
console.log("[Messages] 不显示占位图: shouldShow=false");
return null;
}
console.log("[Messages] ✅ 显示占位图!");
// 优先使用恢复的状态,否则使用当前模型类型
const modelType = pendingGeneration?.modelType;

View File

@ -55,10 +55,15 @@ export function usePendingGeneration(chatId: string) {
// 初始化:检查是否有当前 chatId 的未完成任务
useEffect(() => {
const generations = getPendingGenerations();
console.log("[PendingGeneration] 初始化检查, chatId:", chatId);
console.log("[PendingGeneration] localStorage 中的所有任务:", generations);
const found = generations.find((g) => g.chatId === chatId);
if (found) {
setPendingGeneration(found);
console.log("[PendingGeneration] 恢复处理中状态:", found);
console.log("[PendingGeneration] ✅ 恢复处理中状态:", found);
} else {
console.log("[PendingGeneration] ❌ 未找到匹配的任务");
}
}, [chatId]);