fix: 修复 openScriptChat 设置 viewState='result' 导致页面空白的问题
This commit is contained in:
@@ -866,7 +866,8 @@ const keepGenerationAtBottom = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scrollResultToLatest = () => {
|
const scrollResultToLatest = () => {
|
||||||
if (viewState.value !== 'result' && viewState.value !== 'chat') return
|
// 统一对话页:viewState 只有 home/chat(result 已合并到 chat)
|
||||||
|
if (viewState.value !== 'chat') return
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
measureResultViewport()
|
measureResultViewport()
|
||||||
pushResultScrollCommand(1000000)
|
pushResultScrollCommand(1000000)
|
||||||
@@ -889,7 +890,7 @@ const keepResultAtBottom = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scrollResultToTop = () => {
|
const scrollResultToTop = () => {
|
||||||
if (viewState.value !== 'result') return
|
if (viewState.value !== 'chat') return
|
||||||
resultScrollTop.value = 0
|
resultScrollTop.value = 0
|
||||||
resultCommandScrollTop.value = 1
|
resultCommandScrollTop.value = 1
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -908,7 +909,7 @@ watch(generationStatus, () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch(viewState, (state) => {
|
watch(viewState, (state) => {
|
||||||
if (state !== 'result') return
|
if (state !== 'chat') return
|
||||||
measureResultViewport()
|
measureResultViewport()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1105,9 +1106,9 @@ const endVoicePress = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleVoiceRecognizeSuccess = (text, durationMs) => {
|
const handleVoiceRecognizeSuccess = (text, durationMs) => {
|
||||||
if (viewState.value === 'result') {
|
// 统一对话页:在 chat 视图填充底部输入栏,在 home 视图填充心愿输入框
|
||||||
resultChatInput.value = text
|
if (viewState.value === 'chat') {
|
||||||
resultInputFocused.value = true
|
chatInput.value = text
|
||||||
} else {
|
} else {
|
||||||
wishText.value = text
|
wishText.value = text
|
||||||
homeInputFocused.value = true
|
homeInputFocused.value = true
|
||||||
@@ -1117,7 +1118,7 @@ const handleVoiceRecognizeSuccess = (text, durationMs) => {
|
|||||||
text_length: text.length,
|
text_length: text.length,
|
||||||
duration_ms: durationMs || 0
|
duration_ms: durationMs || 0
|
||||||
}, { eventType: 'script', pagePath })
|
}, { eventType: 'script', pagePath })
|
||||||
uni.showToast({ title: viewState.value === 'result' ? '识别成功,可继续修改建议' : '识别成功,可修改后发送', icon: 'none' })
|
uni.showToast({ title: viewState.value === 'chat' ? '识别成功,可继续修改建议' : '识别成功,可修改后发送', icon: 'none' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleVoiceRecognizeFail = (reason, message = '语音识别失败,请重试') => {
|
const handleVoiceRecognizeFail = (reason, message = '语音识别失败,请重试') => {
|
||||||
@@ -1430,10 +1431,65 @@ const openScriptChat = async (payload = {}) => {
|
|||||||
currentMessageTime.value = formatMessageTime()
|
currentMessageTime.value = formatMessageTime()
|
||||||
currentResultTime.value = script.updateTime || script.updatedAt || script.createTime || script.createdAt || formatMessageTime()
|
currentResultTime.value = script.updateTime || script.updatedAt || script.createTime || script.createdAt || formatMessageTime()
|
||||||
viewMode.value = 'chat'
|
viewMode.value = 'chat'
|
||||||
viewState.value = 'result'
|
// 切换到统一对话页(result 视图已合并到 chat)
|
||||||
|
viewState.value = 'chat'
|
||||||
|
generationPhase.value = 'done'
|
||||||
|
// 清空旧的统一对话消息,准备从历史记录重建
|
||||||
|
resultMessages.value = []
|
||||||
|
|
||||||
if (conversationId.value) {
|
if (conversationId.value) {
|
||||||
await loadMessages()
|
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', {
|
analytics.track('script_chat_open_from_library', {
|
||||||
script_id: script.id,
|
script_id: script.id,
|
||||||
has_history: messages.value.length > 0
|
has_history: messages.value.length > 0
|
||||||
@@ -1795,6 +1851,7 @@ const returnToEdit = () => {
|
|||||||
const closeResult = () => {
|
const closeResult = () => {
|
||||||
clearGenerationFeedbackTimers()
|
clearGenerationFeedbackTimers()
|
||||||
generationStatus.value = 'idle'
|
generationStatus.value = 'idle'
|
||||||
|
generationPhase.value = 'idle'
|
||||||
viewState.value = 'home'
|
viewState.value = 'home'
|
||||||
currentResult.value = null
|
currentResult.value = null
|
||||||
currentConversationId.value = ''
|
currentConversationId.value = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user