流式输出
This commit is contained in:
@@ -34,23 +34,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- ===== ai正在思考弹窗(仅本设备发起时显示) ===== -->
|
|
||||||
<view v-if="isThinking && isSelfSent" class="ncd-overlay" @click.stop>
|
|
||||||
<view class="ncd-card ai-card">
|
|
||||||
<view class="thinking-content">
|
|
||||||
<view class="loading-dots">
|
|
||||||
<view class="dot"></view>
|
|
||||||
<view class="dot"></view>
|
|
||||||
<view class="dot"></view>
|
|
||||||
</view>
|
|
||||||
<text class="thinking-text">AI 正在思考中...</text>
|
|
||||||
<view class="stop-thinking-btn" @click="stopConversation">
|
|
||||||
<text>⏹ 中断对话</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- ===== 消息详情弹窗 ===== -->
|
<!-- ===== 消息详情弹窗 ===== -->
|
||||||
<view v-if="showMessageModal" class="ncd-overlay" @click="closeMessageDetail">
|
<view v-if="showMessageModal" class="ncd-overlay" @click="closeMessageDetail">
|
||||||
<view class="ncd-card message-detail-card" @click.stop>
|
<view class="ncd-card message-detail-card" @click.stop>
|
||||||
@@ -97,51 +80,60 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="main-chat">
|
<view class="main-chat">
|
||||||
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
|
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
|
||||||
:upper-threshold="0" :scroll-with-animation="true"
|
:upper-threshold="0" :scroll-with-animation="true" @scroll="onScroll">
|
||||||
@scroll="onScroll">
|
<!-- 与AI的对话内容展示 -->
|
||||||
<!-- 与AI的对话内容展示 -->
|
<template v-for="(message, index) in currentMessages" :key="index">
|
||||||
<template v-for="(message, index) in currentMessages" :key="index">
|
<view v-if="ChatType === 0 && message.role !== 'tool'" class="chat-message" :id="'msg-' + index"
|
||||||
<view v-if="ChatType === 0 && message.role !== 'tool'" class="chat-message"
|
:class="{'message-user':message.role==='user'}">
|
||||||
:id="'msg-' + index" :class="{'message-user':message.role==='user'}">
|
<!-- <view class="chat-avatar" :class="{'chat-avatar-user':message.role==='user'}">
|
||||||
<!-- <view class="chat-avatar" :class="{'chat-avatar-user':message.role==='user'}">
|
|
||||||
<image v-if="message.role === 'user' && UserData?.avatar" :src="UserData.avatar"
|
<image v-if="message.role === 'user' && UserData?.avatar" :src="UserData.avatar"
|
||||||
class="friend-avatar" mode="aspectFill"></image>
|
class="friend-avatar" mode="aspectFill"></image>
|
||||||
<view v-else-if="message.role === 'assistant'" class="iconfont icon-Robot"></view>
|
<view v-else-if="message.role === 'assistant'" class="iconfont icon-Robot"></view>
|
||||||
<view v-else class="iconfont icon-yonghuziliao"></view>
|
<view v-else class="iconfont icon-yonghuziliao"></view>
|
||||||
</view> -->
|
</view> -->
|
||||||
<view v-if="message.role ==='user'" class="chat-avatar"
|
<view v-if="message.role ==='user'" class="chat-avatar"
|
||||||
:class="{'chat-avatar-user':message.role==='user'}">
|
:class="{'chat-avatar-user':message.role==='user'}">
|
||||||
<image v-if="message.role === 'user' && UserData?.avatar" :src="UserData.avatar"
|
<image v-if="message.role === 'user' && UserData?.avatar" :src="UserData.avatar"
|
||||||
class="friend-avatar" mode="aspectFill"></image>
|
class="friend-avatar" mode="aspectFill"></image>
|
||||||
<view v-else class="iconfont icon-yonghuziliao"></view>
|
<view v-else class="iconfont icon-yonghuziliao"></view>
|
||||||
<!-- <view v-if="message.role ==='assistant'" class="iconfont icon-Robot"></view> -->
|
<!-- <view v-if="message.role ==='assistant'" class="iconfont icon-Robot"></view> -->
|
||||||
<!-- <view v-if="message.role ==='user'" class="iconfont icon-yonghuziliao"></view> -->
|
<!-- <view v-if="message.role ==='user'" class="iconfont icon-yonghuziliao"></view> -->
|
||||||
</view>
|
</view>
|
||||||
<view class="chat-content" :class="{'chat-content-user':message.role==='user', 'chat-content-assistant':message.role==='assistant'}"
|
<view class="chat-content"
|
||||||
@click="showMessageDetail(message)"
|
:class="{'chat-content-user':message.role==='user', 'chat-content-assistant':message.role==='assistant'}"
|
||||||
v-if="message.content && String(message.content).trim() !== ''">
|
@click="showMessageDetail(message)"
|
||||||
<!-- 文本内容 -->
|
v-if="(message.content && String(message.content).trim() !== '') || message._streaming">
|
||||||
<view v-if="parseFileInfo(message.content).textContent"
|
<!-- 流式加载中:显示跳动的点 -->
|
||||||
v-html="pareseMarkdown(parseFileInfo(message.content).textContent)"></view>
|
<view
|
||||||
<!-- 文件卡片列表 -->
|
v-if="message._streaming && (!message.content || String(message.content).trim() === '')"
|
||||||
<view v-if="parseFileInfo(message.content).files.length > 0" class="message-file-list">
|
class="bubble-loading-dots">
|
||||||
<view v-for="(file, idx) in parseFileInfo(message.content).files" :key="idx" class="file-item">
|
<view class="bubble-dot"></view>
|
||||||
<!-- 图片:jpg/png/gif/webp 等 -->
|
<view class="bubble-dot"></view>
|
||||||
<image
|
<view class="bubble-dot"></view>
|
||||||
v-if="['jpg','jpeg','png','gif','webp','bmp'].includes(file.extendName.toLowerCase())"
|
</view>
|
||||||
:src="file.url" mode="widthFix" class="message-image"
|
<!-- 文本内容 -->
|
||||||
@click="previewImage(file.url)"></image>
|
<view v-if="parseFileInfo(message.content).textContent"
|
||||||
<!-- 普通文件:doc/xlsx/zip/pdf 等 -->
|
v-html="pareseMarkdown(parseFileInfo(message.content).textContent)"></view>
|
||||||
<view v-else class="message-file" @click="openFile(file.url)">
|
<!-- 文件卡片列表 -->
|
||||||
<view class="file-icon">📄</view>
|
<view v-if="parseFileInfo(message.content).files.length > 0" class="message-file-list">
|
||||||
<view class="file-name">{{ file.name }}</view>
|
<view v-for="(file, idx) in parseFileInfo(message.content).files" :key="idx"
|
||||||
<view class="file-size">{{ formatFileSize(file.fileSize) }}</view>
|
class="file-item">
|
||||||
|
<!-- 图片:jpg/png/gif/webp 等 -->
|
||||||
|
<image
|
||||||
|
v-if="['jpg','jpeg','png','gif','webp','bmp'].includes(file.extendName.toLowerCase())"
|
||||||
|
:src="file.url" mode="widthFix" class="message-image"
|
||||||
|
@click="previewImage(file.url)"></image>
|
||||||
|
<!-- 普通文件:doc/xlsx/zip/pdf 等 -->
|
||||||
|
<view v-else class="message-file" @click="openFile(file.url)">
|
||||||
|
<view class="file-icon">📄</view>
|
||||||
|
<view class="file-name">{{ file.name }}</view>
|
||||||
|
<view class="file-size">{{ formatFileSize(file.fileSize) }}</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</template>
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
<!-- 与好友的对话内容展示 -->
|
<!-- 与好友的对话内容展示 -->
|
||||||
<view v-if="ChatType === 1" class="chat-message" v-for="(message, index) in currentMessages"
|
<view v-if="ChatType === 1" class="chat-message" v-for="(message, index) in currentMessages"
|
||||||
:key="index" :id="'msg-' + index" :class="{'message-user':message.sender === UserId}">
|
:key="index" :id="'msg-' + index" :class="{'message-user':message.sender === UserId}">
|
||||||
@@ -218,11 +210,16 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- 底部锚点:两个交替切换,确保流式时每次都能触发滚动到底部 -->
|
||||||
|
<view id="chat-bottom-a" style="height: 1rpx;"></view>
|
||||||
|
<view id="chat-bottom-b" style="height: 1rpx;"></view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
<view class="chat-interactive-container" :class="{ 'interactive-disabled': isThinking }">
|
<view class="chat-interactive-container" :class="{ 'interactive-disabled': isThinking }">
|
||||||
<view class="chat-interactive-group">
|
<view class="chat-interactive-group">
|
||||||
<view class="chat-interactive-btn" :class="{ disabled: isThinking }" @click="!isThinking && uploadPhoto()">拍照上传</view>
|
<view class="chat-interactive-btn" :class="{ disabled: isThinking }"
|
||||||
<view class="chat-interactive-btn" :class="{ disabled: isThinking }" @click="!isThinking && uploadFile()">上传文件</view>
|
@click="!isThinking && uploadPhoto()">拍照上传</view>
|
||||||
|
<view class="chat-interactive-btn" :class="{ disabled: isThinking }"
|
||||||
|
@click="!isThinking && uploadFile()">上传文件</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="image-list" v-if="previewFileArray.length > 0">
|
<view class="image-list" v-if="previewFileArray.length > 0">
|
||||||
<view class="image-tags">
|
<view class="image-tags">
|
||||||
@@ -233,14 +230,15 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="chat-input-container" :class="{ 'input-disabled': isThinking }">
|
<view class="chat-input-container" :class="{ 'input-disabled': isThinking }">
|
||||||
<textarea class="message-input" :placeholder="isThinking ? (isSelfSent ? 'AI 正在回复中...' : '电脑正在运行,请稍后') : '输入消息...'" :disabled="isThinking"
|
<textarea class="message-input"
|
||||||
v-model="textMessage" auto-height></textarea>
|
:placeholder="isThinking ? (isSelfSent ? 'AI 正在回复中...' : '电脑正在运行,请稍后') : '输入消息...'"
|
||||||
<view v-if="isThinking && !isSelfSent" class="input-btn-group stop-message-btn" @click="stopConversation">
|
:disabled="isThinking" v-model="textMessage" auto-height></textarea>
|
||||||
<view class="iconfont icon-tingzhi"></view>
|
<view v-if="isThinking" class="input-btn-group stop-message-btn" @click="stopConversation">
|
||||||
</view>
|
<view class="iconfont icon-tingzhi"></view>
|
||||||
<view v-else class="input-btn-group send-message-btn" :class="{ disabled: isThinking }" @click="!isThinking && sendMessage()">
|
</view>
|
||||||
<view class="iconfont icon-fasong"></view>
|
<view v-else class="input-btn-group send-message-btn" @click="sendMessage()">
|
||||||
</view>
|
<view class="iconfont icon-fasong"></view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -381,7 +379,8 @@
|
|||||||
html += '<tr>'
|
html += '<tr>'
|
||||||
cells.forEach((cell, ci) => {
|
cells.forEach((cell, ci) => {
|
||||||
const align = alignments[ci] ? ` style="text-align:${alignments[ci]}"` : ''
|
const align = alignments[ci] ? ` style="text-align:${alignments[ci]}"` : ''
|
||||||
html += `<${tag}${align} style="padding:6px 10px;border:1px solid #ddd">${cell.trim()}</${tag}>`
|
html +=
|
||||||
|
`<${tag}${align} style="padding:6px 10px;border:1px solid #ddd">${cell.trim()}</${tag}>`
|
||||||
})
|
})
|
||||||
html += '</tr>'
|
html += '</tr>'
|
||||||
})
|
})
|
||||||
@@ -465,16 +464,28 @@
|
|||||||
// 从消息 content 中提取文件信息
|
// 从消息 content 中提取文件信息
|
||||||
// 格式: [文件信息:[{...}]]
|
// 格式: [文件信息:[{...}]]
|
||||||
const parseFileInfo = (content) => {
|
const parseFileInfo = (content) => {
|
||||||
if (!content || typeof content !== 'string') return { textContent: content || '', files: [] }
|
if (!content || typeof content !== 'string') return {
|
||||||
|
textContent: content || '',
|
||||||
|
files: []
|
||||||
|
}
|
||||||
const match = content.match(/\[文件信息:(\[.*?\])\]/)
|
const match = content.match(/\[文件信息:(\[.*?\])\]/)
|
||||||
if (!match) return { textContent: content, files: [] }
|
if (!match) return {
|
||||||
|
textContent: content,
|
||||||
|
files: []
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const files = JSON.parse(match[1])
|
const files = JSON.parse(match[1])
|
||||||
const textContent = content.replace(match[0], '').trim()
|
const textContent = content.replace(match[0], '').trim()
|
||||||
return { textContent, files }
|
return {
|
||||||
|
textContent,
|
||||||
|
files
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('解析文件信息失败:', e)
|
console.error('解析文件信息失败:', e)
|
||||||
return { textContent: content, files: [] }
|
return {
|
||||||
|
textContent: content,
|
||||||
|
files: []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,6 +666,7 @@
|
|||||||
const isSelfSent = ref(false) // 是否当前设备发起的 AI 对话(用于区分弹窗/仅锁输入)
|
const isSelfSent = ref(false) // 是否当前设备发起的 AI 对话(用于区分弹窗/仅锁输入)
|
||||||
const isUploading = ref(false)
|
const isUploading = ref(false)
|
||||||
const uploadedFiles = ref([])
|
const uploadedFiles = ref([])
|
||||||
|
const streamingMessageId = ref(null) // 流式消息的临时 ID,用于实时更新 AI 回复
|
||||||
|
|
||||||
// 消息详情弹窗
|
// 消息详情弹窗
|
||||||
const showMessageModal = ref(false)
|
const showMessageModal = ref(false)
|
||||||
@@ -830,18 +842,23 @@
|
|||||||
}
|
}
|
||||||
socketStore.send(data)
|
socketStore.send(data)
|
||||||
isThinking.value = true
|
isThinking.value = true
|
||||||
isSelfSent.value = true // 标记为当前设备发起
|
isSelfSent.value = true
|
||||||
// // 10分钟超时
|
// 立即添加用户消息到列表(使用完整的 messageContent,包含文件信息)
|
||||||
// aiResponseTimer = setTimeout(() => {
|
allmessages.value = [...allmessages.value, {
|
||||||
// uni.showToast({
|
role: 'user',
|
||||||
// title: 'AI回复超时,请重试',
|
content: messageContent
|
||||||
// icon: 'none'
|
}]
|
||||||
// })
|
// 添加流式消息气泡(加载中状态)
|
||||||
// isThinking.value = false
|
streamingMessageId.value = 'streaming-' + Date.now()
|
||||||
// isSelfSent.value = false
|
allmessages.value = [...allmessages.value, {
|
||||||
// textMessage.value = ''
|
role: 'assistant',
|
||||||
// uploadedFiles.value = []
|
content: '',
|
||||||
// }, 600000)
|
_streaming: true,
|
||||||
|
_id: streamingMessageId.value
|
||||||
|
}]
|
||||||
|
textMessage.value = ''
|
||||||
|
uploadedFiles.value = []
|
||||||
|
scrollToBottom()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
isThinking.value = false
|
isThinking.value = false
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -863,6 +880,11 @@
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('中断指令发送失败:', err)
|
console.error('中断指令发送失败:', err)
|
||||||
}
|
}
|
||||||
|
// 移除流式消息占位
|
||||||
|
if (streamingMessageId.value) {
|
||||||
|
allmessages.value = allmessages.value.filter(m => m._id !== streamingMessageId.value)
|
||||||
|
streamingMessageId.value = null
|
||||||
|
}
|
||||||
// 立即关闭弹窗,清除超时
|
// 立即关闭弹窗,清除超时
|
||||||
// clearTimeout(aiResponseTimer)
|
// clearTimeout(aiResponseTimer)
|
||||||
isThinking.value = false
|
isThinking.value = false
|
||||||
@@ -871,22 +893,40 @@
|
|||||||
textMessage.value = ''
|
textMessage.value = ''
|
||||||
uploadedFiles.value = []
|
uploadedFiles.value = []
|
||||||
// takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage)
|
// takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage)
|
||||||
uni.showToast({ title: '已中断', icon: 'none', duration: 1500 })
|
uni.showToast({
|
||||||
|
title: '已中断',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1500
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局监听 socketStore.isThinking:跨设备同步思考状态,锁/解锁输入框
|
// 全局监听 socketStore.isThinking:跨设备同步思考状态,锁/解锁输入框
|
||||||
watch(() => socketStore.isThinking, (newVal, oldVal) => {
|
watch(() => socketStore.isThinking, (newVal, oldVal) => {
|
||||||
console.log("isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
|
console.log("isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
|
||||||
// false → true:后端开始回复(当前设备或其他设备触发),锁定输入框
|
// false → true:后端开始回复,锁定输入框
|
||||||
if (!oldVal && newVal) {
|
if (!oldVal && newVal) {
|
||||||
console.log('AI开始回复(跨设备同步),锁定输入框');
|
console.log('AI开始回复(跨设备同步),锁定输入框');
|
||||||
isThinking.value = true
|
isThinking.value = true
|
||||||
|
// 非本设备发起时,也需要添加流式气泡
|
||||||
|
if (!streamingMessageId.value) {
|
||||||
|
streamingMessageId.value = 'streaming-' + Date.now()
|
||||||
|
allmessages.value = [...allmessages.value, {
|
||||||
|
role: 'assistant',
|
||||||
|
content: '',
|
||||||
|
_streaming: true,
|
||||||
|
_id: streamingMessageId.value
|
||||||
|
}]
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// true → false:AI 回复结束或中断,解锁输入框并刷新消息列表
|
// true → false:AI 回复结束或中断,解锁输入框并刷新消息列表
|
||||||
if (oldVal && !newVal) {
|
if (oldVal && !newVal) {
|
||||||
// clearTimeout(aiResponseTimer)
|
|
||||||
console.log('AI回复结束(正常/中断),解锁并刷新消息列表');
|
console.log('AI回复结束(正常/中断),解锁并刷新消息列表');
|
||||||
|
// 移除流式消息气泡,从服务器加载完整消息
|
||||||
|
if (streamingMessageId.value) {
|
||||||
|
allmessages.value = allmessages.value.filter(m => m._id !== streamingMessageId.value)
|
||||||
|
streamingMessageId.value = null
|
||||||
|
}
|
||||||
takeConversationMessages()
|
takeConversationMessages()
|
||||||
isThinking.value = false
|
isThinking.value = false
|
||||||
isSelfSent.value = false
|
isSelfSent.value = false
|
||||||
@@ -911,6 +951,22 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 监听流式消息内容,实时更新 AI 回复(流式输出核心)
|
||||||
|
watch(() => socketStore.messageString, (newContent) => {
|
||||||
|
if (!streamingMessageId.value || !socketStore.isThinking) return
|
||||||
|
|
||||||
|
const idx = allmessages.value.findIndex(m => m._id === streamingMessageId.value)
|
||||||
|
if (idx >= 0) {
|
||||||
|
// 使用 splice 保证 Vue 响应式更新
|
||||||
|
const updated = {
|
||||||
|
...allmessages.value[idx],
|
||||||
|
content: newContent
|
||||||
|
}
|
||||||
|
allmessages.value.splice(idx, 1, updated)
|
||||||
|
scrollToBottom()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const textMessage = ref('')
|
const textMessage = ref('')
|
||||||
|
|
||||||
// 获取用户历史会话列表
|
// 获取用户历史会话列表
|
||||||
@@ -1071,6 +1127,7 @@
|
|||||||
// const pageInfoNumber = 10;
|
// const pageInfoNumber = 10;
|
||||||
|
|
||||||
const scrollToView = ref('')
|
const scrollToView = ref('')
|
||||||
|
const bottomToggle = ref(false)
|
||||||
// 加载状态和分页相关变量
|
// 加载状态和分页相关变量
|
||||||
const isLoadingMore = ref(false) // 是否正在加载更多
|
const isLoadingMore = ref(false) // 是否正在加载更多
|
||||||
const currentPage = ref(1) // 当前页码(如果后端支持分页)
|
const currentPage = ref(1) // 当前页码(如果后端支持分页)
|
||||||
@@ -1155,7 +1212,9 @@
|
|||||||
const scrollToBottom = async () => {
|
const scrollToBottom = async () => {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
if (currentMessages.value.length > 0) {
|
if (currentMessages.value.length > 0) {
|
||||||
scrollToView.value = 'msg-' + (currentMessages.value.length - 1);
|
// 两个锚点交替切换,确保每次调用都能触发滚动
|
||||||
|
bottomToggle.value = !bottomToggle.value
|
||||||
|
scrollToView.value = bottomToggle.value ? 'chat-bottom-a' : 'chat-bottom-b'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1262,19 +1321,79 @@
|
|||||||
|
|
||||||
<!-- v-html 渲染的 markdown 内容无法被 scoped 样式命中,需非 scoped 样式块 -->
|
<!-- v-html 渲染的 markdown 内容无法被 scoped 样式命中,需非 scoped 样式块 -->
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.chat-content {
|
.chat-content {
|
||||||
h1 { font-size: 42rpx; line-height: 1.4; margin: 16rpx 0 10rpx; }
|
h1 {
|
||||||
h2 { font-size: 38rpx; line-height: 1.4; margin: 14rpx 0 8rpx; }
|
font-size: 42rpx;
|
||||||
h3 { font-size: 36rpx; line-height: 1.4; margin: 12rpx 0 8rpx; }
|
line-height: 1.4;
|
||||||
h4, h5, h6 { font-size: 34rpx; line-height: 1.5; margin: 10rpx 0 6rpx; }
|
margin: 16rpx 0 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
/* 普通正文 */
|
h2 {
|
||||||
p,
|
font-size: 38rpx;
|
||||||
text,
|
line-height: 1.4;
|
||||||
span {
|
margin: 14rpx 0 8rpx;
|
||||||
font-size: 38rpx !important;
|
}
|
||||||
line-height: 1.6;
|
|
||||||
margin: 8rpx 0;
|
h3 {
|
||||||
|
font-size: 36rpx;
|
||||||
|
line-height: 1.4;
|
||||||
|
margin: 12rpx 0 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
font-size: 34rpx;
|
||||||
|
line-height: 1.5;
|
||||||
|
margin: 10rpx 0 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 普通正文 */
|
||||||
|
p,
|
||||||
|
text,
|
||||||
|
span {
|
||||||
|
font-size: 38rpx !important;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin: 8rpx 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 流式气泡中的加载动画 */
|
||||||
|
.bubble-loading-dots {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
padding: 10rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bubble-dot {
|
||||||
|
width: 12rpx;
|
||||||
|
height: 12rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #a0a0b8;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
animation: bubbleDotBlink 1.2s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bubble-dot:nth-child(2) {
|
||||||
|
animation-delay: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bubble-dot:nth-child(3) {
|
||||||
|
animation-delay: 0.6s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes bubbleDotBlink {
|
||||||
|
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 0.25;
|
||||||
|
transform: scale(0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
240
unpackage/dist/dev/app-plus/app-service.js
vendored
240
unpackage/dist/dev/app-plus/app-service.js
vendored
@@ -5597,7 +5597,7 @@ This will fail in production.`);
|
|||||||
if (friendSocketStore.isConnected)
|
if (friendSocketStore.isConnected)
|
||||||
return;
|
return;
|
||||||
if (!userToken.value || !UserId.value) {
|
if (!userToken.value || !UserId.value) {
|
||||||
formatAppLog("warn", "at pages/Chat/Chat.vue:310", "Token或UserId未准备好");
|
formatAppLog("warn", "at pages/Chat/Chat.vue:308", "Token或UserId未准备好");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
friendSocketStore.connect({
|
friendSocketStore.connect({
|
||||||
@@ -5668,7 +5668,7 @@ This will fail in production.`);
|
|||||||
const html = t(content);
|
const html = t(content);
|
||||||
return html;
|
return html;
|
||||||
} catch (e2) {
|
} catch (e2) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:408", "解析失败", e2);
|
formatAppLog("error", "at pages/Chat/Chat.vue:407", "解析失败", e2);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -5709,17 +5709,29 @@ This will fail in production.`);
|
|||||||
};
|
};
|
||||||
const parseFileInfo = (content) => {
|
const parseFileInfo = (content) => {
|
||||||
if (!content || typeof content !== "string")
|
if (!content || typeof content !== "string")
|
||||||
return { textContent: content || "", files: [] };
|
return {
|
||||||
|
textContent: content || "",
|
||||||
|
files: []
|
||||||
|
};
|
||||||
const match = content.match(/\[文件信息:(\[.*?\])\]/);
|
const match = content.match(/\[文件信息:(\[.*?\])\]/);
|
||||||
if (!match)
|
if (!match)
|
||||||
return { textContent: content, files: [] };
|
return {
|
||||||
|
textContent: content,
|
||||||
|
files: []
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const files = JSON.parse(match[1]);
|
const files = JSON.parse(match[1]);
|
||||||
const textContent = content.replace(match[0], "").trim();
|
const textContent = content.replace(match[0], "").trim();
|
||||||
return { textContent, files };
|
return {
|
||||||
|
textContent,
|
||||||
|
files
|
||||||
|
};
|
||||||
} catch (e2) {
|
} catch (e2) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:476", "解析文件信息失败:", e2);
|
formatAppLog("error", "at pages/Chat/Chat.vue:484", "解析文件信息失败:", e2);
|
||||||
return { textContent: content, files: [] };
|
return {
|
||||||
|
textContent: content,
|
||||||
|
files: []
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const selectNormalChat = async () => {
|
const selectNormalChat = async () => {
|
||||||
@@ -5752,7 +5764,7 @@ This will fail in production.`);
|
|||||||
}
|
}
|
||||||
takeUserConversations();
|
takeUserConversations();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:518", "新建普通会话失败:", error);
|
formatAppLog("error", "at pages/Chat/Chat.vue:529", "新建普通会话失败:", error);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "创建会话失败,请重试",
|
title: "创建会话失败,请重试",
|
||||||
icon: "none"
|
icon: "none"
|
||||||
@@ -5790,7 +5802,7 @@ This will fail in production.`);
|
|||||||
};
|
};
|
||||||
const previewFileArray = vue.ref([]);
|
const previewFileArray = vue.ref([]);
|
||||||
const uploadPhoto = () => {
|
const uploadPhoto = () => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:567", "点击了拍照上传");
|
formatAppLog("log", "at pages/Chat/Chat.vue:578", "点击了拍照上传");
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
count: 1,
|
count: 1,
|
||||||
sourceType: ["camera", "album"],
|
sourceType: ["camera", "album"],
|
||||||
@@ -5813,7 +5825,7 @@ This will fail in production.`);
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:585", "选择图片失败", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:596", "选择图片失败", err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -5822,12 +5834,12 @@ This will fail in production.`);
|
|||||||
};
|
};
|
||||||
const fileList = vue.ref([]);
|
const fileList = vue.ref([]);
|
||||||
const uploadFile = () => {
|
const uploadFile = () => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:596", "点击了上传文件");
|
formatAppLog("log", "at pages/Chat/Chat.vue:607", "点击了上传文件");
|
||||||
chooseFile({
|
chooseFile({
|
||||||
count: 5,
|
count: 5,
|
||||||
type: "all",
|
type: "all",
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:601", "成功了");
|
formatAppLog("log", "at pages/Chat/Chat.vue:612", "成功了");
|
||||||
fileList.value = res.tempFiles;
|
fileList.value = res.tempFiles;
|
||||||
previewFileArray.value.push(...res.tempFiles);
|
previewFileArray.value.push(...res.tempFiles);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -5836,7 +5848,7 @@ This will fail in production.`);
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:612", "选择失败:", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:623", "选择失败:", err);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "选择失败",
|
title: "选择失败",
|
||||||
icon: "error"
|
icon: "error"
|
||||||
@@ -5871,6 +5883,7 @@ This will fail in production.`);
|
|||||||
const isSelfSent = vue.ref(false);
|
const isSelfSent = vue.ref(false);
|
||||||
const isUploading = vue.ref(false);
|
const isUploading = vue.ref(false);
|
||||||
const uploadedFiles = vue.ref([]);
|
const uploadedFiles = vue.ref([]);
|
||||||
|
const streamingMessageId = vue.ref(null);
|
||||||
const showMessageModal = vue.ref(false);
|
const showMessageModal = vue.ref(false);
|
||||||
const detailMessageContent = vue.ref("");
|
const detailMessageContent = vue.ref("");
|
||||||
const showMessageDetail = (message) => {
|
const showMessageDetail = (message) => {
|
||||||
@@ -5901,7 +5914,7 @@ This will fail in production.`);
|
|||||||
previewFileArray.value = [];
|
previewFileArray.value = [];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:692", "文件上传失败:", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:704", "文件上传失败:", err);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "文件上传失败,请重试",
|
title: "文件上传失败,请重试",
|
||||||
icon: "error"
|
icon: "error"
|
||||||
@@ -6012,6 +6025,20 @@ This will fail in production.`);
|
|||||||
socketStore.send(data);
|
socketStore.send(data);
|
||||||
isThinking.value = true;
|
isThinking.value = true;
|
||||||
isSelfSent.value = true;
|
isSelfSent.value = true;
|
||||||
|
allmessages.value = [...allmessages.value, {
|
||||||
|
role: "user",
|
||||||
|
content: messageContent
|
||||||
|
}];
|
||||||
|
streamingMessageId.value = "streaming-" + Date.now();
|
||||||
|
allmessages.value = [...allmessages.value, {
|
||||||
|
role: "assistant",
|
||||||
|
content: "",
|
||||||
|
_streaming: true,
|
||||||
|
_id: streamingMessageId.value
|
||||||
|
}];
|
||||||
|
textMessage.value = "";
|
||||||
|
uploadedFiles.value = [];
|
||||||
|
scrollToBottom();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
isThinking.value = false;
|
isThinking.value = false;
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -6021,32 +6048,53 @@ This will fail in production.`);
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const stopConversation = async () => {
|
const stopConversation = async () => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:856", "中断对话 - 当前会话ID:", currentSessionId.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:873", "中断对话 - 当前会话ID:", currentSessionId.value);
|
||||||
try {
|
try {
|
||||||
await socketStore.send({
|
await socketStore.send({
|
||||||
type: "stop",
|
type: "stop",
|
||||||
conversation_id: currentSessionId.value
|
conversation_id: currentSessionId.value
|
||||||
});
|
});
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:862", "中断指令已发送成功");
|
formatAppLog("log", "at pages/Chat/Chat.vue:879", "中断指令已发送成功");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:864", "中断指令发送失败:", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:881", "中断指令发送失败:", err);
|
||||||
|
}
|
||||||
|
if (streamingMessageId.value) {
|
||||||
|
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
|
||||||
|
streamingMessageId.value = null;
|
||||||
}
|
}
|
||||||
isThinking.value = false;
|
isThinking.value = false;
|
||||||
socketStore.isThinking = false;
|
socketStore.isThinking = false;
|
||||||
isSelfSent.value = false;
|
isSelfSent.value = false;
|
||||||
textMessage.value = "";
|
textMessage.value = "";
|
||||||
uploadedFiles.value = [];
|
uploadedFiles.value = [];
|
||||||
uni.showToast({ title: "已中断", icon: "none", duration: 1500 });
|
uni.showToast({
|
||||||
|
title: "已中断",
|
||||||
|
icon: "none",
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
};
|
};
|
||||||
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => {
|
vue.watch(() => socketStore.isThinking, (newVal, oldVal) => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:879", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
|
formatAppLog("log", "at pages/Chat/Chat.vue:905", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
|
||||||
if (!oldVal && newVal) {
|
if (!oldVal && newVal) {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:882", "AI开始回复(跨设备同步),锁定输入框");
|
formatAppLog("log", "at pages/Chat/Chat.vue:908", "AI开始回复(跨设备同步),锁定输入框");
|
||||||
isThinking.value = true;
|
isThinking.value = true;
|
||||||
|
if (!streamingMessageId.value) {
|
||||||
|
streamingMessageId.value = "streaming-" + Date.now();
|
||||||
|
allmessages.value = [...allmessages.value, {
|
||||||
|
role: "assistant",
|
||||||
|
content: "",
|
||||||
|
_streaming: true,
|
||||||
|
_id: streamingMessageId.value
|
||||||
|
}];
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (oldVal && !newVal) {
|
if (oldVal && !newVal) {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:889", "AI回复结束(正常/中断),解锁并刷新消息列表");
|
formatAppLog("log", "at pages/Chat/Chat.vue:924", "AI回复结束(正常/中断),解锁并刷新消息列表");
|
||||||
|
if (streamingMessageId.value) {
|
||||||
|
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
|
||||||
|
streamingMessageId.value = null;
|
||||||
|
}
|
||||||
takeConversationMessages();
|
takeConversationMessages();
|
||||||
isThinking.value = false;
|
isThinking.value = false;
|
||||||
isSelfSent.value = false;
|
isSelfSent.value = false;
|
||||||
@@ -6068,6 +6116,19 @@ This will fail in production.`);
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
vue.watch(() => socketStore.messageString, (newContent) => {
|
||||||
|
if (!streamingMessageId.value || !socketStore.isThinking)
|
||||||
|
return;
|
||||||
|
const idx = allmessages.value.findIndex((m) => m._id === streamingMessageId.value);
|
||||||
|
if (idx >= 0) {
|
||||||
|
const updated = {
|
||||||
|
...allmessages.value[idx],
|
||||||
|
content: newContent
|
||||||
|
};
|
||||||
|
allmessages.value.splice(idx, 1, updated);
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
});
|
||||||
const textMessage = vue.ref("");
|
const textMessage = vue.ref("");
|
||||||
const UserConversations = vue.ref([]);
|
const UserConversations = vue.ref([]);
|
||||||
const currentSessionId = vue.ref("");
|
const currentSessionId = vue.ref("");
|
||||||
@@ -6081,15 +6142,15 @@ This will fail in production.`);
|
|||||||
UserData.value = await getUserInfo(userToken.value);
|
UserData.value = await getUserInfo(userToken.value);
|
||||||
UserId.value = UserData.value._id;
|
UserId.value = UserData.value._id;
|
||||||
UserAvatar.value = UserData.value.avatar || "";
|
UserAvatar.value = UserData.value.avatar || "";
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:932", "用户信息已加载:", UserId.value, UserAvatar.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:988", "用户信息已加载:", UserId.value, UserAvatar.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:934", "获取用户信息失败:", error);
|
formatAppLog("error", "at pages/Chat/Chat.vue:990", "获取用户信息失败:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const takeUserConversations = async () => {
|
const takeUserConversations = async () => {
|
||||||
try {
|
try {
|
||||||
userToken.value = getToken();
|
userToken.value = getToken();
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:942", "token:", userToken.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:998", "token:", userToken.value);
|
||||||
UserConversations.value = await getUserConversations(userToken.value) || [];
|
UserConversations.value = await getUserConversations(userToken.value) || [];
|
||||||
const savedSessionId = getCurrentSessionId();
|
const savedSessionId = getCurrentSessionId();
|
||||||
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
|
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
|
||||||
@@ -6099,7 +6160,7 @@ This will fail in production.`);
|
|||||||
} else {
|
} else {
|
||||||
currentSessionId.value = "";
|
currentSessionId.value = "";
|
||||||
}
|
}
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:954", "保存会话id:", currentSessionId.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1010", "保存会话id:", currentSessionId.value);
|
||||||
uni.setStorageSync("currentSessionId", currentSessionId.value);
|
uni.setStorageSync("currentSessionId", currentSessionId.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -6111,17 +6172,17 @@ This will fail in production.`);
|
|||||||
const FriendInfoList = vue.ref([]);
|
const FriendInfoList = vue.ref([]);
|
||||||
const takeFriendList = async () => {
|
const takeFriendList = async () => {
|
||||||
try {
|
try {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:969", "开始获取好友列表");
|
formatAppLog("log", "at pages/Chat/Chat.vue:1025", "开始获取好友列表");
|
||||||
const friendList = await getChatFriend(UserId.value);
|
const friendList = await getChatFriend(UserId.value);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:972", "friendList:", friendList);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1028", "friendList:", friendList);
|
||||||
if (friendList && friendList.length) {
|
if (friendList && friendList.length) {
|
||||||
FriendInfoList.value = await takeUserAvatar(friendList);
|
FriendInfoList.value = await takeUserAvatar(friendList);
|
||||||
} else {
|
} else {
|
||||||
FriendInfoList.value = [];
|
FriendInfoList.value = [];
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:977", "好友列表为空");
|
formatAppLog("log", "at pages/Chat/Chat.vue:1033", "好友列表为空");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:980", "获取好友列表失败:", error);
|
formatAppLog("error", "at pages/Chat/Chat.vue:1036", "获取好友列表失败:", error);
|
||||||
FriendInfoList.value = [];
|
FriendInfoList.value = [];
|
||||||
} finally {
|
} finally {
|
||||||
UserConversations.value = FriendInfoList.value;
|
UserConversations.value = FriendInfoList.value;
|
||||||
@@ -6148,17 +6209,17 @@ This will fail in production.`);
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:1010", "获取好友头像失败", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:1066", "获取好友头像失败", err);
|
||||||
return friendList;
|
return friendList;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const GroupList = vue.ref([]);
|
const GroupList = vue.ref([]);
|
||||||
const takeGroupList = async () => {
|
const takeGroupList = async () => {
|
||||||
try {
|
try {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1020", "开始获取群聊列表");
|
formatAppLog("log", "at pages/Chat/Chat.vue:1076", "开始获取群聊列表");
|
||||||
GroupList.value = await getGroup(UserId.value);
|
GroupList.value = await getGroup(UserId.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:1025", "获取群聊列表失败:", error);
|
formatAppLog("error", "at pages/Chat/Chat.vue:1081", "获取群聊列表失败:", error);
|
||||||
GroupList.value = [];
|
GroupList.value = [];
|
||||||
} finally {
|
} finally {
|
||||||
UserConversations.value = GroupList.value;
|
UserConversations.value = GroupList.value;
|
||||||
@@ -6170,22 +6231,22 @@ This will fail in production.`);
|
|||||||
return [];
|
return [];
|
||||||
try {
|
try {
|
||||||
const memberIds = memberList.map((item) => item.groupContactId);
|
const memberIds = memberList.map((item) => item.groupContactId);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1039", "请求头像的ID列表:", memberIds);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1095", "请求头像的ID列表:", memberIds);
|
||||||
const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
|
const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1041", "头像接口返回数据:", memberAvatarList);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1097", "头像接口返回数据:", memberAvatarList);
|
||||||
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
|
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1044", "userMap的keys:", Array.from(userMap.keys()));
|
formatAppLog("log", "at pages/Chat/Chat.vue:1100", "userMap的keys:", Array.from(userMap.keys()));
|
||||||
return memberList.map((member) => {
|
return memberList.map((member) => {
|
||||||
const memberId = member.groupContactId;
|
const memberId = member.groupContactId;
|
||||||
const userInfo = userMap.get(memberId);
|
const userInfo = userMap.get(memberId);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1049", `查找 ${memberId} 的头像:`, userInfo);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1105", `查找 ${memberId} 的头像:`, userInfo);
|
||||||
return {
|
return {
|
||||||
...member,
|
...member,
|
||||||
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
|
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
formatAppLog("error", "at pages/Chat/Chat.vue:1056", "获取群成员头像失败", err);
|
formatAppLog("error", "at pages/Chat/Chat.vue:1112", "获取群成员头像失败", err);
|
||||||
return memberList;
|
return memberList;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -6197,6 +6258,7 @@ This will fail in production.`);
|
|||||||
};
|
};
|
||||||
const allmessages = vue.ref([]);
|
const allmessages = vue.ref([]);
|
||||||
const scrollToView = vue.ref("");
|
const scrollToView = vue.ref("");
|
||||||
|
const bottomToggle = vue.ref(false);
|
||||||
const isLoadingMore = vue.ref(false);
|
const isLoadingMore = vue.ref(false);
|
||||||
const currentPage = vue.ref(1);
|
const currentPage = vue.ref(1);
|
||||||
const currentMessages = vue.computed(() => {
|
const currentMessages = vue.computed(() => {
|
||||||
@@ -6216,7 +6278,7 @@ This will fail in production.`);
|
|||||||
const takeFriendMessages = async () => {
|
const takeFriendMessages = async () => {
|
||||||
try {
|
try {
|
||||||
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
|
allmessages.value = await getFriendMessages(currentSessionId.value) || [];
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1102", "好友消息:", JSON.stringify(allmessages.value));
|
formatAppLog("log", "at pages/Chat/Chat.vue:1159", "好友消息:", JSON.stringify(allmessages.value));
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -6228,12 +6290,12 @@ This will fail in production.`);
|
|||||||
const takeGroupMessages = async () => {
|
const takeGroupMessages = async () => {
|
||||||
try {
|
try {
|
||||||
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
|
allmessages.value = await getGroupMessages(currentSessionId.value) || [];
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1115", "群聊消息:", allmessages.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1172", "群聊消息:", allmessages.value);
|
||||||
const memberList = await getGroupMemberList(currentSessionId.value);
|
const memberList = await getGroupMemberList(currentSessionId.value);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1118", "获取到的群成员列表:", memberList);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1175", "获取到的群成员列表:", memberList);
|
||||||
if (memberList && memberList.length) {
|
if (memberList && memberList.length) {
|
||||||
groupMemberList.value = await takeGroupMemberAvatar(memberList);
|
groupMemberList.value = await takeGroupMemberAvatar(memberList);
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1121", "群成员列表(带头像):", groupMemberList.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1178", "群成员列表(带头像):", groupMemberList.value);
|
||||||
} else {
|
} else {
|
||||||
groupMemberList.value = [];
|
groupMemberList.value = [];
|
||||||
}
|
}
|
||||||
@@ -6250,13 +6312,14 @@ This will fail in production.`);
|
|||||||
const scrollToBottom = async () => {
|
const scrollToBottom = async () => {
|
||||||
await vue.nextTick();
|
await vue.nextTick();
|
||||||
if (currentMessages.value.length > 0) {
|
if (currentMessages.value.length > 0) {
|
||||||
scrollToView.value = "msg-" + (currentMessages.value.length - 1);
|
bottomToggle.value = !bottomToggle.value;
|
||||||
|
scrollToView.value = bottomToggle.value ? "chat-bottom-a" : "chat-bottom-b";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
|
vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1164", "收到了好友消息");
|
formatAppLog("log", "at pages/Chat/Chat.vue:1223", "收到了好友消息");
|
||||||
if (newId) {
|
if (newId) {
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1166", "ChatType:", ChatType.value);
|
formatAppLog("log", "at pages/Chat/Chat.vue:1225", "ChatType:", ChatType.value);
|
||||||
switch (ChatType.value) {
|
switch (ChatType.value) {
|
||||||
case 0:
|
case 0:
|
||||||
takeConversationMessages();
|
takeConversationMessages();
|
||||||
@@ -6271,7 +6334,7 @@ This will fail in production.`);
|
|||||||
friendSocketStore.MessageReceived = false;
|
friendSocketStore.MessageReceived = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
formatAppLog("log", "at pages/Chat/Chat.vue:1182", "default 分支");
|
formatAppLog("log", "at pages/Chat/Chat.vue:1241", "default 分支");
|
||||||
friendSocketStore.MessageReceived = false;
|
friendSocketStore.MessageReceived = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6333,7 +6396,7 @@ This will fail in production.`);
|
|||||||
onUnload(() => {
|
onUnload(() => {
|
||||||
socketStore.disconnect();
|
socketStore.disconnect();
|
||||||
});
|
});
|
||||||
const __returned__ = { friendSocketStore, handleFriendConnect, socketStore, ChatType, convertMarkdownTable, renderTable, pareseMarkdown, sanitizeContent, previewImage, openFile, formatFileSize, parseFileInfo, selectNormalChat, showNewChatModal, closeNewChatModal, isChatSidebar, handleChatSidebar, goWorkSpace, goCloudDatabase, logOut, previewFileArray, uploadPhoto, deleteImage, fileList, uploadFile, handleConnect, isThinking, isSelfSent, isUploading, uploadedFiles, showMessageModal, detailMessageContent, showMessageDetail, closeMessageDetail, sendMessage, sendFriendMessage, sendGroupMessage, sendAIMessage, stopConversation, textMessage, UserConversations, currentSessionId, userToken, UserId, UserAvatar, UserData, takeUserInfo, takeUserConversations, FriendInfoList, takeFriendList, takeTalkUserAvatar, takeUserAvatar, GroupList, takeGroupList, groupMemberList, takeGroupMemberAvatar, getGroupMemberAvatarById, allmessages, scrollToView, isLoadingMore, currentPage, currentMessages, takeConversationMessages, takeFriendMessages, takeGroupMessages, onScroll, scrollToBottom, computed: vue.computed, getCurrentInstance: vue.getCurrentInstance, nextTick: vue.nextTick, onMounted: vue.onMounted, ref: vue.ref, watch: vue.watch, get onShow() {
|
const __returned__ = { friendSocketStore, handleFriendConnect, socketStore, ChatType, convertMarkdownTable, renderTable, pareseMarkdown, sanitizeContent, previewImage, openFile, formatFileSize, parseFileInfo, selectNormalChat, showNewChatModal, closeNewChatModal, isChatSidebar, handleChatSidebar, goWorkSpace, goCloudDatabase, logOut, previewFileArray, uploadPhoto, deleteImage, fileList, uploadFile, handleConnect, isThinking, isSelfSent, isUploading, uploadedFiles, streamingMessageId, showMessageModal, detailMessageContent, showMessageDetail, closeMessageDetail, sendMessage, sendFriendMessage, sendGroupMessage, sendAIMessage, stopConversation, textMessage, UserConversations, currentSessionId, userToken, UserId, UserAvatar, UserData, takeUserInfo, takeUserConversations, FriendInfoList, takeFriendList, takeTalkUserAvatar, takeUserAvatar, GroupList, takeGroupList, groupMemberList, takeGroupMemberAvatar, getGroupMemberAvatarById, allmessages, scrollToView, bottomToggle, isLoadingMore, currentPage, currentMessages, takeConversationMessages, takeFriendMessages, takeGroupMessages, onScroll, scrollToBottom, computed: vue.computed, getCurrentInstance: vue.getCurrentInstance, nextTick: vue.nextTick, onMounted: vue.onMounted, ref: vue.ref, watch: vue.watch, get onShow() {
|
||||||
return onShow;
|
return onShow;
|
||||||
}, get onUnload() {
|
}, get onUnload() {
|
||||||
return onUnload;
|
return onUnload;
|
||||||
@@ -6459,37 +6522,14 @@ This will fail in production.`);
|
|||||||
])
|
])
|
||||||
])
|
])
|
||||||
])) : vue.createCommentVNode("v-if", true),
|
])) : vue.createCommentVNode("v-if", true),
|
||||||
$setup.isThinking && $setup.isSelfSent ? (vue.openBlock(), vue.createElementBlock("view", {
|
|
||||||
key: 1,
|
|
||||||
class: "ncd-overlay",
|
|
||||||
onClick: _cache[1] || (_cache[1] = vue.withModifiers(() => {
|
|
||||||
}, ["stop"]))
|
|
||||||
}, [
|
|
||||||
vue.createElementVNode("view", { class: "ncd-card ai-card" }, [
|
|
||||||
vue.createElementVNode("view", { class: "thinking-content" }, [
|
|
||||||
vue.createElementVNode("view", { class: "loading-dots" }, [
|
|
||||||
vue.createElementVNode("view", { class: "dot" }),
|
|
||||||
vue.createElementVNode("view", { class: "dot" }),
|
|
||||||
vue.createElementVNode("view", { class: "dot" })
|
|
||||||
]),
|
|
||||||
vue.createElementVNode("text", { class: "thinking-text" }, "AI 正在思考中..."),
|
|
||||||
vue.createElementVNode("view", {
|
|
||||||
class: "stop-thinking-btn",
|
|
||||||
onClick: $setup.stopConversation
|
|
||||||
}, [
|
|
||||||
vue.createElementVNode("text", null, "⏹ 中断对话")
|
|
||||||
])
|
|
||||||
])
|
|
||||||
])
|
|
||||||
])) : vue.createCommentVNode("v-if", true),
|
|
||||||
$setup.showMessageModal ? (vue.openBlock(), vue.createElementBlock("view", {
|
$setup.showMessageModal ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
key: 2,
|
key: 1,
|
||||||
class: "ncd-overlay",
|
class: "ncd-overlay",
|
||||||
onClick: $setup.closeMessageDetail
|
onClick: $setup.closeMessageDetail
|
||||||
}, [
|
}, [
|
||||||
vue.createElementVNode("view", {
|
vue.createElementVNode("view", {
|
||||||
class: "ncd-card message-detail-card",
|
class: "ncd-card message-detail-card",
|
||||||
onClick: _cache[2] || (_cache[2] = vue.withModifiers(() => {
|
onClick: _cache[1] || (_cache[1] = vue.withModifiers(() => {
|
||||||
}, ["stop"]))
|
}, ["stop"]))
|
||||||
}, [
|
}, [
|
||||||
vue.createElementVNode("view", { class: "ncd-header" }, [
|
vue.createElementVNode("view", { class: "ncd-header" }, [
|
||||||
@@ -6530,11 +6570,11 @@ This will fail in production.`);
|
|||||||
vue.createVNode($setup["ChatSidebar"], {
|
vue.createVNode($setup["ChatSidebar"], {
|
||||||
chatList: $setup.UserConversations,
|
chatList: $setup.UserConversations,
|
||||||
showNewChatModal: $setup.showNewChatModal,
|
showNewChatModal: $setup.showNewChatModal,
|
||||||
"onUpdate:showNewChatModal": _cache[3] || (_cache[3] = ($event) => $setup.showNewChatModal = $event),
|
"onUpdate:showNewChatModal": _cache[2] || (_cache[2] = ($event) => $setup.showNewChatModal = $event),
|
||||||
currentSessionId: $setup.currentSessionId,
|
currentSessionId: $setup.currentSessionId,
|
||||||
"onUpdate:currentSessionId": _cache[4] || (_cache[4] = ($event) => $setup.currentSessionId = $event),
|
"onUpdate:currentSessionId": _cache[3] || (_cache[3] = ($event) => $setup.currentSessionId = $event),
|
||||||
chatType: $setup.ChatType,
|
chatType: $setup.ChatType,
|
||||||
"onUpdate:chatType": _cache[5] || (_cache[5] = ($event) => $setup.ChatType = $event),
|
"onUpdate:chatType": _cache[4] || (_cache[4] = ($event) => $setup.ChatType = $event),
|
||||||
onRefreshConversations: $setup.takeUserConversations
|
onRefreshConversations: $setup.takeUserConversations
|
||||||
}, null, 8, ["chatList", "showNewChatModal", "currentSessionId", "chatType"])
|
}, null, 8, ["chatList", "showNewChatModal", "currentSessionId", "chatType"])
|
||||||
],
|
],
|
||||||
@@ -6614,17 +6654,25 @@ This will fail in production.`);
|
|||||||
2
|
2
|
||||||
/* CLASS */
|
/* CLASS */
|
||||||
)) : vue.createCommentVNode("v-if", true),
|
)) : vue.createCommentVNode("v-if", true),
|
||||||
message.content && String(message.content).trim() !== "" ? (vue.openBlock(), vue.createElementBlock("view", {
|
message.content && String(message.content).trim() !== "" || message._streaming ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
key: 1,
|
key: 1,
|
||||||
class: vue.normalizeClass(["chat-content", { "chat-content-user": message.role === "user", "chat-content-assistant": message.role === "assistant" }]),
|
class: vue.normalizeClass(["chat-content", { "chat-content-user": message.role === "user", "chat-content-assistant": message.role === "assistant" }]),
|
||||||
onClick: ($event) => $setup.showMessageDetail(message)
|
onClick: ($event) => $setup.showMessageDetail(message)
|
||||||
}, [
|
}, [
|
||||||
$setup.parseFileInfo(message.content).textContent ? (vue.openBlock(), vue.createElementBlock("view", {
|
message._streaming && (!message.content || String(message.content).trim() === "") ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
key: 0,
|
key: 0,
|
||||||
|
class: "bubble-loading-dots"
|
||||||
|
}, [
|
||||||
|
vue.createElementVNode("view", { class: "bubble-dot" }),
|
||||||
|
vue.createElementVNode("view", { class: "bubble-dot" }),
|
||||||
|
vue.createElementVNode("view", { class: "bubble-dot" })
|
||||||
|
])) : vue.createCommentVNode("v-if", true),
|
||||||
|
$setup.parseFileInfo(message.content).textContent ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
|
key: 1,
|
||||||
innerHTML: $setup.pareseMarkdown($setup.parseFileInfo(message.content).textContent)
|
innerHTML: $setup.pareseMarkdown($setup.parseFileInfo(message.content).textContent)
|
||||||
}, null, 8, ["innerHTML"])) : vue.createCommentVNode("v-if", true),
|
}, null, 8, ["innerHTML"])) : vue.createCommentVNode("v-if", true),
|
||||||
$setup.parseFileInfo(message.content).files.length > 0 ? (vue.openBlock(), vue.createElementBlock("view", {
|
$setup.parseFileInfo(message.content).files.length > 0 ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
key: 1,
|
key: 2,
|
||||||
class: "message-file-list"
|
class: "message-file-list"
|
||||||
}, [
|
}, [
|
||||||
(vue.openBlock(true), vue.createElementBlock(
|
(vue.openBlock(true), vue.createElementBlock(
|
||||||
@@ -6873,7 +6921,15 @@ This will fail in production.`);
|
|||||||
}),
|
}),
|
||||||
128
|
128
|
||||||
/* KEYED_FRAGMENT */
|
/* KEYED_FRAGMENT */
|
||||||
)) : vue.createCommentVNode("v-if", true)
|
)) : vue.createCommentVNode("v-if", true),
|
||||||
|
vue.createElementVNode("view", {
|
||||||
|
id: "chat-bottom-a",
|
||||||
|
style: { "height": "1rpx" }
|
||||||
|
}),
|
||||||
|
vue.createElementVNode("view", {
|
||||||
|
id: "chat-bottom-b",
|
||||||
|
style: { "height": "1rpx" }
|
||||||
|
})
|
||||||
], 40, ["scroll-into-view"]),
|
], 40, ["scroll-into-view"]),
|
||||||
vue.createElementVNode(
|
vue.createElementVNode(
|
||||||
"view",
|
"view",
|
||||||
@@ -6886,7 +6942,7 @@ This will fail in production.`);
|
|||||||
"view",
|
"view",
|
||||||
{
|
{
|
||||||
class: vue.normalizeClass(["chat-interactive-btn", { disabled: $setup.isThinking }]),
|
class: vue.normalizeClass(["chat-interactive-btn", { disabled: $setup.isThinking }]),
|
||||||
onClick: _cache[6] || (_cache[6] = ($event) => !$setup.isThinking && $setup.uploadPhoto())
|
onClick: _cache[5] || (_cache[5] = ($event) => !$setup.isThinking && $setup.uploadPhoto())
|
||||||
},
|
},
|
||||||
"拍照上传",
|
"拍照上传",
|
||||||
2
|
2
|
||||||
@@ -6896,7 +6952,7 @@ This will fail in production.`);
|
|||||||
"view",
|
"view",
|
||||||
{
|
{
|
||||||
class: vue.normalizeClass(["chat-interactive-btn", { disabled: $setup.isThinking }]),
|
class: vue.normalizeClass(["chat-interactive-btn", { disabled: $setup.isThinking }]),
|
||||||
onClick: _cache[7] || (_cache[7] = ($event) => !$setup.isThinking && $setup.uploadFile())
|
onClick: _cache[6] || (_cache[6] = ($event) => !$setup.isThinking && $setup.uploadFile())
|
||||||
},
|
},
|
||||||
"上传文件",
|
"上传文件",
|
||||||
2
|
2
|
||||||
@@ -6944,30 +7000,24 @@ This will fail in production.`);
|
|||||||
class: "message-input",
|
class: "message-input",
|
||||||
placeholder: $setup.isThinking ? $setup.isSelfSent ? "AI 正在回复中..." : "电脑正在运行,请稍后" : "输入消息...",
|
placeholder: $setup.isThinking ? $setup.isSelfSent ? "AI 正在回复中..." : "电脑正在运行,请稍后" : "输入消息...",
|
||||||
disabled: $setup.isThinking,
|
disabled: $setup.isThinking,
|
||||||
"onUpdate:modelValue": _cache[8] || (_cache[8] = ($event) => $setup.textMessage = $event),
|
"onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => $setup.textMessage = $event),
|
||||||
"auto-height": ""
|
"auto-height": ""
|
||||||
}, null, 8, ["placeholder", "disabled"]), [
|
}, null, 8, ["placeholder", "disabled"]), [
|
||||||
[vue.vModelText, $setup.textMessage]
|
[vue.vModelText, $setup.textMessage]
|
||||||
]),
|
]),
|
||||||
$setup.isThinking && !$setup.isSelfSent ? (vue.openBlock(), vue.createElementBlock("view", {
|
$setup.isThinking ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
key: 0,
|
key: 0,
|
||||||
class: "input-btn-group stop-message-btn",
|
class: "input-btn-group stop-message-btn",
|
||||||
onClick: $setup.stopConversation
|
onClick: $setup.stopConversation
|
||||||
}, [
|
}, [
|
||||||
vue.createElementVNode("view", { class: "iconfont icon-tingzhi" })
|
vue.createElementVNode("view", { class: "iconfont icon-tingzhi" })
|
||||||
])) : (vue.openBlock(), vue.createElementBlock(
|
])) : (vue.openBlock(), vue.createElementBlock("view", {
|
||||||
"view",
|
key: 1,
|
||||||
{
|
class: "input-btn-group send-message-btn",
|
||||||
key: 1,
|
onClick: _cache[8] || (_cache[8] = ($event) => $setup.sendMessage())
|
||||||
class: vue.normalizeClass(["input-btn-group send-message-btn", { disabled: $setup.isThinking }]),
|
}, [
|
||||||
onClick: _cache[9] || (_cache[9] = ($event) => !$setup.isThinking && $setup.sendMessage())
|
vue.createElementVNode("view", { class: "iconfont icon-fasong" })
|
||||||
},
|
]))
|
||||||
[
|
|
||||||
vue.createElementVNode("view", { class: "iconfont icon-fasong" })
|
|
||||||
],
|
|
||||||
2
|
|
||||||
/* CLASS */
|
|
||||||
))
|
|
||||||
],
|
],
|
||||||
2
|
2
|
||||||
/* CLASS */
|
/* CLASS */
|
||||||
|
|||||||
36
unpackage/dist/dev/app-plus/pages/Chat/Chat.css
vendored
36
unpackage/dist/dev/app-plus/pages/Chat/Chat.css
vendored
@@ -1671,7 +1671,9 @@ to { opacity: 1; transform: translateY(0);
|
|||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
margin: 0.375rem 0 0.25rem;
|
margin: 0.375rem 0 0.25rem;
|
||||||
}
|
}
|
||||||
.chat-content h4, .chat-content h5, .chat-content h6 {
|
.chat-content h4,
|
||||||
|
.chat-content h5,
|
||||||
|
.chat-content h6 {
|
||||||
font-size: 1.0625rem;
|
font-size: 1.0625rem;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
margin: 0.3125rem 0 0.1875rem;
|
margin: 0.3125rem 0 0.1875rem;
|
||||||
@@ -1683,3 +1685,35 @@ to { opacity: 1; transform: translateY(0);
|
|||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
margin: 0.25rem 0;
|
margin: 0.25rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 流式气泡中的加载动画 */
|
||||||
|
.bubble-loading-dots {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
padding: 0.3125rem 0;
|
||||||
|
}
|
||||||
|
.bubble-dot {
|
||||||
|
width: 0.375rem;
|
||||||
|
height: 0.375rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #a0a0b8;
|
||||||
|
margin-right: 0.3125rem;
|
||||||
|
animation: bubbleDotBlink 1.2s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
.bubble-dot:nth-child(2) {
|
||||||
|
animation-delay: 0.3s;
|
||||||
|
}
|
||||||
|
.bubble-dot:nth-child(3) {
|
||||||
|
animation-delay: 0.6s;
|
||||||
|
}
|
||||||
|
@keyframes bubbleDotBlink {
|
||||||
|
0%, 100% {
|
||||||
|
opacity: 0.25;
|
||||||
|
transform: scale(0.7);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user