consumer模块完成度95%,优化安卓端界面和小程序测试2
This commit is contained in:
@@ -58,7 +58,16 @@
|
||||
<view class="message-content-wrapper">
|
||||
<text class="sender-name">{{ headerTitle }}</text>
|
||||
<view class="message-bubble received-bubble">
|
||||
<text class="message-text">{{ message.content }}</text>
|
||||
<!-- 图片消息 -->
|
||||
<image
|
||||
v-if="message.msgType == 'image'"
|
||||
class="message-image"
|
||||
:src="message.content"
|
||||
mode="widthFix"
|
||||
@click="previewImage(message.content)"
|
||||
/>
|
||||
<!-- 文本消息 -->
|
||||
<text v-if="message.msgType != 'image'" class="message-text">{{ message.content }}</text>
|
||||
<text class="message-time">{{ message.time }}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -68,7 +77,16 @@
|
||||
<view v-else class="message-wrapper me">
|
||||
<view class="message-content-wrapper">
|
||||
<view class="message-bubble me">
|
||||
<text class="message-text">{{ message.content }}</text>
|
||||
<!-- 图片消息 -->
|
||||
<image
|
||||
v-if="message.msgType == 'image'"
|
||||
class="message-image"
|
||||
:src="message.content"
|
||||
mode="widthFix"
|
||||
@click="previewImage(message.content)"
|
||||
/>
|
||||
<!-- 文本消息 -->
|
||||
<text v-if="message.msgType != 'image'" class="message-text">{{ message.content }}</text>
|
||||
<text class="message-time">{{ message.time }}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -138,6 +156,7 @@ type UiChatMessage = {
|
||||
type: string
|
||||
content: string
|
||||
time: string
|
||||
msgType: string // 'text' | 'image'
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
@@ -224,6 +243,7 @@ function setupRealtimeSubscription(): void {
|
||||
const receiverId = newMsg.getString('receiver_id') ?? ''
|
||||
const msgId = newMsg.getString('id') ?? ''
|
||||
const content = newMsg.getString('content') ?? ''
|
||||
const msgType = newMsg.getString('msg_type') ?? 'text'
|
||||
|
||||
console.log('=== 消息详情 ===')
|
||||
console.log('消息ID:', msgId)
|
||||
@@ -232,6 +252,7 @@ function setupRealtimeSubscription(): void {
|
||||
console.log('当前用户ID:', currentUserId.value)
|
||||
console.log('商家ID:', merchantId.value)
|
||||
console.log('消息内容:', content)
|
||||
console.log('消息类型 msgType:', msgType)
|
||||
|
||||
// 检查消息是否已经在列表中(避免重复)
|
||||
for (let i = 0; i < messages.value.length; i++) {
|
||||
@@ -271,7 +292,8 @@ function setupRealtimeSubscription(): void {
|
||||
viewId: safeViewId,
|
||||
type: isMyMessage ? 'sent' : 'received',
|
||||
content: content,
|
||||
time: timeStr
|
||||
time: timeStr,
|
||||
msgType: msgType
|
||||
}
|
||||
|
||||
console.log('=== 添加新消息到列表 ===')
|
||||
@@ -326,7 +348,8 @@ async function loadChatHistory(): Promise<void> {
|
||||
viewId: safeViewId,
|
||||
type: msgType,
|
||||
content: m.content ?? '',
|
||||
time: timeStr
|
||||
time: timeStr,
|
||||
msgType: m.msg_type ?? 'text'
|
||||
}
|
||||
uiMessages.push(uiMsg)
|
||||
}
|
||||
@@ -476,17 +499,124 @@ function showEmojiPicker(): void {
|
||||
}
|
||||
}
|
||||
|
||||
// 执行图片上传
|
||||
async function doUploadImage(filePath: string): Promise<void> {
|
||||
console.log('[doUploadImage] 开始上传图片:', filePath)
|
||||
|
||||
// 显示加载提示
|
||||
uni.showLoading({
|
||||
title: '发送中...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
try {
|
||||
// 上传图片
|
||||
const imageUrl = await supabaseService.uploadChatImage(filePath)
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (imageUrl == '') {
|
||||
uni.showToast({
|
||||
title: '图片上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[doUploadImage] 图片上传成功:', imageUrl)
|
||||
|
||||
// 发送图片消息
|
||||
const success = await supabaseService.sendMessage(merchantId.value, imageUrl, 'image')
|
||||
if (!success) {
|
||||
uni.showToast({
|
||||
title: '发送失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
console.error('[doUploadImage] 上传异常:', e)
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 显示图片选择器
|
||||
function showImagePicker(): void {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
console.log('选择图片:', res.tempFilePaths)
|
||||
// 这里可以处理图片上传
|
||||
console.log('选择图片成功:', JSON.stringify(res))
|
||||
|
||||
// 处理 tempFilePaths,兼容不同平台
|
||||
let filePath: string = ''
|
||||
const tempFilePaths = res.tempFilePaths
|
||||
if (tempFilePaths != null) {
|
||||
if (Array.isArray(tempFilePaths)) {
|
||||
const arr = tempFilePaths as string[]
|
||||
if (arr.length > 0) {
|
||||
filePath = arr[0]
|
||||
}
|
||||
} else if (tempFilePaths instanceof UTSJSONObject) {
|
||||
const keys = UTSJSONObject.keys(tempFilePaths as UTSJSONObject)
|
||||
if (keys.length > 0) {
|
||||
filePath = (tempFilePaths as UTSJSONObject).getString(keys[0]) ?? ''
|
||||
}
|
||||
} else if (typeof tempFilePaths === 'string') {
|
||||
filePath = tempFilePaths as string
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试从 tempFiles 获取
|
||||
if (filePath == '' && res.tempFiles != null) {
|
||||
const tempFiles = res.tempFiles
|
||||
if (Array.isArray(tempFiles)) {
|
||||
const files = tempFiles as any[]
|
||||
if (files.length > 0) {
|
||||
const firstFile = files[0]
|
||||
if (firstFile instanceof UTSJSONObject) {
|
||||
filePath = firstFile.getString('path') ?? ''
|
||||
} else if (typeof firstFile === 'object' && firstFile != null) {
|
||||
const fileObj = JSON.parse(JSON.stringify(firstFile)) as UTSJSONObject
|
||||
filePath = fileObj.getString('path') ?? ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[showImagePicker] 文件路径:', filePath)
|
||||
|
||||
if (filePath == '') {
|
||||
uni.showToast({
|
||||
title: '获取图片路径失败',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
doUploadImage(filePath)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('选择图片失败:', err)
|
||||
uni.showToast({
|
||||
title: '选择图片失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 预览图片
|
||||
function previewImage(url: string): void {
|
||||
uni.previewImage({
|
||||
urls: [url],
|
||||
current: url
|
||||
})
|
||||
}
|
||||
|
||||
// 显示更多工具
|
||||
function showMoreTools(): void {
|
||||
uni.showActionSheet({
|
||||
@@ -717,6 +847,13 @@ const goBack = () => {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.message-image {
|
||||
max-width: 200px;
|
||||
min-width: 100px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 11px;
|
||||
color: #999;
|
||||
|
||||
Reference in New Issue
Block a user