From 371801a7580320d9ed936eb614847456539a4589 Mon Sep 17 00:00:00 2001 From: Jafeng <2998840497@qq.com> Date: Tue, 26 May 2026 19:34:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=B8=B8=E7=94=A8?= =?UTF-8?q?=E8=AF=AD=E5=8F=91=E9=80=81=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=9B=BE=E7=89=87=E5=8F=91=E9=80=81=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=8F=8A=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/message/common-phrases.vue | 54 ++++++++++++------------- pages/message/components/chat-input.vue | 21 ++++++++-- pages/message/index.vue | 42 ++++++++++++++++++- 3 files changed, 84 insertions(+), 33 deletions(-) diff --git a/pages/message/common-phrases.vue b/pages/message/common-phrases.vue index 28dafc7..3453049 100644 --- a/pages/message/common-phrases.vue +++ b/pages/message/common-phrases.vue @@ -452,41 +452,39 @@ const handleCategoryClick = (category) => { currentCategory.value = category.id; }; -const confirmSendImages = (count) => { - return new Promise((resolve) => { - uni.showModal({ - title: "提示", - content: `该常用语包含${count}张图片,是否一并发送?`, - cancelText: "不发送图片", - confirmText: "发送图片", - success: (res) => resolve(Boolean(res.confirm)), - fail: () => resolve(false), - }); - }); -}; - -const sendPhrase = async (phrase) => { +const sendPhrase = (phrase) => { const pages = getCurrentPages(); const prevPage = pages[pages.length - 2]; const files = normalizeFiles(phrase.files); - const shouldSendImages = files.length > 0 ? await confirmSendImages(files.length) : false; + console.log("[common-phrases] sendPhrase click", { + phraseId: phrase?.id, + rawFiles: phrase?.files, + normalizedFiles: files, + pageCount: pages.length, + hasPrevPage: Boolean(prevPage), + hasSendCommonPhrase: Boolean(prevPage?.$vm?.sendCommonPhrase), + }); const phraseToSend = { ...phrase, - files: shouldSendImages ? files : [], + files, }; - if (!phraseToSend.content?.trim() && phraseToSend.files.length === 0) { - return; - } - - if (prevPage) { - const result = prevPage.$vm.sendCommonPhrase(phraseToSend); - if (result && typeof result.then === "function") { - await result; - } - } - - uni.navigateBack(); + uni.navigateBack({ + success: () => { + setTimeout(() => { + if (!prevPage?.$vm?.sendCommonPhrase) return; + console.log("[common-phrases] call prevPage.sendCommonPhrase", phraseToSend); + const result = prevPage.$vm.sendCommonPhrase(phraseToSend); + if (result && typeof result.then === "function") { + result.then(() => { + console.log("[common-phrases] prevPage.sendCommonPhrase done", { + phraseId: phrase?.id, + }); + }); + } + }, 200); + }, + }); }; const showAddPhraseDialog = () => { diff --git a/pages/message/components/chat-input.vue b/pages/message/components/chat-input.vue index 1c55ac3..fbb9005 100644 --- a/pages/message/components/chat-input.vue +++ b/pages/message/components/chat-input.vue @@ -208,7 +208,9 @@ const normalizePhraseImageFile = (file) => { ? file : file?.url || file?.URL || file?.download_url || file?.tempFilePath || file?.path; + console.log("[chat-input] normalizePhraseImageFile start", { file, imageUrl }); if (!imageUrl) { + console.log("[chat-input] normalizePhraseImageFile missing imageUrl", { file }); resolve(null); return; } @@ -229,32 +231,45 @@ const normalizePhraseImageFile = (file) => { }); if (/^https?:\/\//.test(imageUrl)) { + console.log("[chat-input] download phrase image", { imageUrl }); uni.downloadFile({ url: imageUrl, success: (res) => { + console.log("[chat-input] download phrase image success", res); if (res.statusCode === 200 && res.tempFilePath) { - resolve(makeImageFile(res.tempFilePath, file?.size || 0)); + const imageFile = makeImageFile(res.tempFilePath, file?.size || 0); + console.log("[chat-input] normalized downloaded phrase image", imageFile); + resolve(imageFile); } else { resolve(null); } }, - fail: () => resolve(null), + fail: (error) => { + console.log("[chat-input] download phrase image fail", error); + resolve(null); + }, }); return; } - resolve(makeImageFile(imageUrl, file?.size || 0)); + const imageFile = makeImageFile(imageUrl, file?.size || 0); + console.log("[chat-input] normalized local phrase image", imageFile); + resolve(imageFile); }); }; const sendImageMessageFromPhrase = async (file) => { + console.log("[chat-input] sendImageMessageFromPhrase start", { file }); const imageFile = await normalizePhraseImageFile(file); if (!imageFile) { + console.log("[chat-input] sendImageMessageFromPhrase normalize failed", { file }); uni.showToast({ title: "图片发送失败", icon: "none" }); return; } + console.log("[chat-input] sendImageMessageFromPhrase call sendImageMessage", imageFile); await sendImageMessage(imageFile); + console.log("[chat-input] sendImageMessageFromPhrase done", imageFile); }; // 设置输入框文本(覆盖原内容) diff --git a/pages/message/index.vue b/pages/message/index.vue index a006b52..0646971 100644 --- a/pages/message/index.vue +++ b/pages/message/index.vue @@ -993,6 +993,7 @@ onHide(() => { }); const sendCommonPhrase = async (phraseOrContent) => { + console.log("[message-index] sendCommonPhrase start", phraseOrContent); if (!chatInputRef.value) return; const content = @@ -1000,14 +1001,51 @@ const sendCommonPhrase = async (phraseOrContent) => { ? phraseOrContent : phraseOrContent?.content || ""; const files = Array.isArray(phraseOrContent?.files) ? phraseOrContent.files : []; + console.log("[message-index] sendCommonPhrase parsed", { + hasChatInputRef: Boolean(chatInputRef.value), + contentLength: content.length, + files, + fileCount: files.length, + }); if (content.trim()) { - await chatInputRef.value.sendTextMessageFromPhrase(content); + console.log("[message-index] sendCommonPhrase set input text"); + chatInputRef.value.setInputText(content); } - for (const file of files) { + if (files.length === 0) { + console.log("[message-index] sendCommonPhrase done without images"); + return; + } + + const shouldSendImages = await new Promise((resolve) => { + console.log("[message-index] confirm phrase images open", { count: files.length }); + uni.showModal({ + title: "提示", + content: `该常用语包含${files.length}张图片,是否发送图片?`, + cancelText: "不发", + confirmText: "发送", + success: (res) => { + console.log("[message-index] confirm phrase images success", res); + resolve(Boolean(res.confirm)); + }, + fail: (error) => { + console.log("[message-index] confirm phrase images fail", error); + resolve(false); + }, + }); + }); + + if (!shouldSendImages) { + console.log("[message-index] sendCommonPhrase skip images"); + return; + } + + for (const [index, file] of files.entries()) { + console.log("[message-index] sendCommonPhrase send image", { index, file }); await chatInputRef.value.sendImageMessageFromPhrase(file); } + console.log("[message-index] sendCommonPhrase done"); }; // 处理流式文本输入