From 118d20914d3bf06670e0805688bfc0e79e4f0a1f Mon Sep 17 00:00:00 2001 From: Peanut Date: Sun, 19 Jul 2026 19:30:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20openScriptChat=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20viewState=3D'result'=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=A9=BA=E7=99=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mini-program/src/pages/main/ScriptView.vue | 73 +++++++++++++++++++--- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/mini-program/src/pages/main/ScriptView.vue b/mini-program/src/pages/main/ScriptView.vue index 7db3e0e..03f224d 100644 --- a/mini-program/src/pages/main/ScriptView.vue +++ b/mini-program/src/pages/main/ScriptView.vue @@ -866,7 +866,8 @@ const keepGenerationAtBottom = () => { } const scrollResultToLatest = () => { - if (viewState.value !== 'result' && viewState.value !== 'chat') return + // 统一对话页:viewState 只有 home/chat(result 已合并到 chat) + if (viewState.value !== 'chat') return nextTick(() => { measureResultViewport() pushResultScrollCommand(1000000) @@ -889,7 +890,7 @@ const keepResultAtBottom = () => { } const scrollResultToTop = () => { - if (viewState.value !== 'result') return + if (viewState.value !== 'chat') return resultScrollTop.value = 0 resultCommandScrollTop.value = 1 nextTick(() => { @@ -908,7 +909,7 @@ watch(generationStatus, () => { }) watch(viewState, (state) => { - if (state !== 'result') return + if (state !== 'chat') return measureResultViewport() }) @@ -1105,9 +1106,9 @@ const endVoicePress = async () => { } const handleVoiceRecognizeSuccess = (text, durationMs) => { - if (viewState.value === 'result') { - resultChatInput.value = text - resultInputFocused.value = true + // 统一对话页:在 chat 视图填充底部输入栏,在 home 视图填充心愿输入框 + if (viewState.value === 'chat') { + chatInput.value = text } else { wishText.value = text homeInputFocused.value = true @@ -1117,7 +1118,7 @@ const handleVoiceRecognizeSuccess = (text, durationMs) => { text_length: text.length, duration_ms: durationMs || 0 }, { eventType: 'script', pagePath }) - uni.showToast({ title: viewState.value === 'result' ? '识别成功,可继续修改建议' : '识别成功,可修改后发送', icon: 'none' }) + uni.showToast({ title: viewState.value === 'chat' ? '识别成功,可继续修改建议' : '识别成功,可修改后发送', icon: 'none' }) } const handleVoiceRecognizeFail = (reason, message = '语音识别失败,请重试') => { @@ -1430,10 +1431,65 @@ const openScriptChat = async (payload = {}) => { currentMessageTime.value = formatMessageTime() currentResultTime.value = script.updateTime || script.updatedAt || script.createTime || script.createdAt || formatMessageTime() viewMode.value = 'chat' - viewState.value = 'result' + // 切换到统一对话页(result 视图已合并到 chat) + viewState.value = 'chat' + generationPhase.value = 'done' + // 清空旧的统一对话消息,准备从历史记录重建 + resultMessages.value = [] + if (conversationId.value) { await loadMessages() } + + // 将历史剧本数据转换为统一对话消息格式,填充 resultMessages + const novelContent = currentResult.value?.content || currentResult.value?.plotJson?.fullContent || '' + const wishTheme = currentResult.value?.theme || currentResult.value?.title || '' + + // 1. 用户心愿作为首条 user 消息 + if (wishTheme) { + resultMessages.value.push({ + id: `loaded-wish-${Date.now()}`, + role: 'user', + kind: 'text', + content: wishTheme, + pending: false, + time: formatMessageTime(), + submitted: false, + confirmed: false + }) + } + + // 2. 当前小说正文作为 AI novel 消息(已完成态) + if (novelContent) { + resultMessages.value.push({ + id: `loaded-novel-${Date.now()}`, + role: 'assistant', + kind: 'novel', + content: novelContent, + pending: false, + time: formatMessageTime(), + submitted: false, + confirmed: false + }) + } + + // 3. 对话历史中除首条外的其他消息追加到对话流 + // (首条通常是与 wishTheme 重复的用户消息,跳过避免重复) + if (messages.value.length > 0) { + messages.value.slice(1).forEach(m => { + resultMessages.value.push({ + id: m.id || createMessageId(), + role: m.sender === 'user' ? 'user' : 'assistant', + kind: 'text', + content: m.content || '', + pending: false, + time: formatMessageTime(), + submitted: false, + confirmed: false + }) + }) + } + analytics.track('script_chat_open_from_library', { script_id: script.id, has_history: messages.value.length > 0 @@ -1795,6 +1851,7 @@ const returnToEdit = () => { const closeResult = () => { clearGenerationFeedbackTimers() generationStatus.value = 'idle' + generationPhase.value = 'idle' viewState.value = 'home' currentResult.value = null currentConversationId.value = ''