fix:调整用户心愿消息到聊天流首位
问题:DB 中 messageOrder 顺序导致用户心愿(order=8)显示在澄清卡片(order=2,4)之后, 但逻辑上用户心愿应该是第一条消息。 修复: - 在 rebuildResultMessages 完成后,检测 user 类型的 chat 消息位置 - 如果不在首位(index > 0),移动到 resultMessages 数组开头 - ScriptView.vue 和 ScriptDetailView.vue 保持一致 显示顺序现在为: 1. 用户心愿(第一条) 2. 澄清卡片 1 + 答案 3. 澄清卡片 2 + 答案 4. 大纲 5. 正文
This commit is contained in:
@@ -209,7 +209,14 @@ const rebuildResultMessages = (scriptData, messages) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 4. 如果 messages 中没有 script 类型消息,fallback 到 plotJson.fullContent
|
// 调整顺序:用户心愿应该在最前面(DB 中 messageOrder 可能靠后,但逻辑上是第一条)
|
||||||
|
const userWishIndex = result.findIndex(m => m.role === 'user' && m.kind === 'text')
|
||||||
|
if (userWishIndex > 0) {
|
||||||
|
const [userWish] = result.splice(userWishIndex, 1)
|
||||||
|
result.unshift(userWish)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 如果 messages 中没有 script 类型消息,fallback 到 plotJson.fullContent
|
||||||
const hasNovel = result.some(m => m.kind === 'novel')
|
const hasNovel = result.some(m => m.kind === 'novel')
|
||||||
if (!hasNovel && scriptData?.plotJson?.fullContent) {
|
if (!hasNovel && scriptData?.plotJson?.fullContent) {
|
||||||
result.push({
|
result.push({
|
||||||
|
|||||||
@@ -1591,6 +1591,13 @@ const openScriptChat = async (payload = {}) => {
|
|||||||
// 跳过 system 类型(不展示)
|
// 跳过 system 类型(不展示)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 调整顺序:用户心愿应该在最前面(DB 中 messageOrder 可能靠后,但逻辑上是第一条)
|
||||||
|
const userWishIndex = resultMessages.value.findIndex(m => m.role === 'user' && m.kind === 'text')
|
||||||
|
if (userWishIndex > 0) {
|
||||||
|
const [userWish] = resultMessages.value.splice(userWishIndex, 1)
|
||||||
|
resultMessages.value.unshift(userWish)
|
||||||
|
}
|
||||||
|
|
||||||
analytics.track('script_chat_open_from_library', {
|
analytics.track('script_chat_open_from_library', {
|
||||||
script_id: script.id,
|
script_id: script.id,
|
||||||
has_history: messagesList.length > 0
|
has_history: messagesList.length > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user