From 107312336064331045bdc9dc53e0715d6228c992 Mon Sep 17 00:00:00 2001 From: Peanut Date: Mon, 29 Jun 2026 23:52:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20createMessage=20=E8=A1=A5=20userId=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=20+=20=E4=BD=BF=E7=94=A8=20senderType/conten?= =?UTF-8?q?tType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mini-program/src/pages/main/ScriptView.vue | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mini-program/src/pages/main/ScriptView.vue b/mini-program/src/pages/main/ScriptView.vue index 73c9cd0..4c93da4 100644 --- a/mini-program/src/pages/main/ScriptView.vue +++ b/mini-program/src/pages/main/ScriptView.vue @@ -694,6 +694,18 @@ const loadMessages = async () => { } } +const getCurrentUserId = () => { + try { + const token = uni.getStorageSync('access_token') + if (!token) return '' + const payload = token.split('.')[1] + const decoded = JSON.parse(decodeURIComponent(Array.from(atob(payload), c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''))) + return decoded.sub || '' + } catch (e) { + return '' + } +} + /** * 历史剧本兼容:基于 plotJson 初始化首条 AI 剧本消息 * 触发条件:loadMessages 返回空列表,且 currentResult.plotJson.fullContent 存在 @@ -703,11 +715,13 @@ const initializeFirstAIMessage = async () => { if (!content) return try { + const userId = getCurrentUserId() // 先保存用户心愿消息(theme) const theme = currentResult.value?.theme || currentResult.value?.title || '' if (theme) { await createMessage({ conversationId: conversationId.value, + userId, content: theme, senderType: 'user', contentType: 'chat' @@ -717,6 +731,7 @@ const initializeFirstAIMessage = async () => { // 再保存 AI 剧本消息 await createMessage({ conversationId: conversationId.value, + userId, content, senderType: 'assistant', contentType: 'script', @@ -796,6 +811,7 @@ const sendChat = async () => { const userMessageRes = await createMessage({ conversationId: conversationId.value, + userId: getCurrentUserId(), content, senderType: 'user', contentType: 'chat' @@ -847,6 +863,7 @@ const rewriteMessage = (msg) => { const sendRewrite = async (targetMessageId, content) => { const userMessageRes = await createMessage({ conversationId: conversationId.value, + userId: getCurrentUserId(), content, senderType: 'user', contentType: 'chat'