diff --git a/miniapp/api/chat.js b/miniapp/api/chat.js index a9d56ec..191d4ac 100644 --- a/miniapp/api/chat.js +++ b/miniapp/api/chat.js @@ -14,7 +14,14 @@ import { getToken } from '../utils/storage' */ export async function getSessions() { const response = await get('/chat/sessions') - return response + // 统一返回格式 + if (response && response.code === 0) { + return { + success: true, + data: Array.isArray(response.data) ? response.data : (response.data?.list || []) + } + } + return { success: false, data: [] } } /** @@ -105,8 +112,11 @@ export async function getUnreadCount() { */ export async function uploadVoice(filePath) { return new Promise((resolve, reject) => { + // 简化 URL 拼接 + const uploadUrl = `${config.API_BASE_URL}/upload/voice` + uni.uploadFile({ - url: config.API_BASE_URL.replace('/api/app', '') + '/api/app/upload/voice', + url: uploadUrl, filePath: filePath, name: 'file', header: { @@ -114,18 +124,22 @@ export async function uploadVoice(filePath) { }, success: (res) => { if (res.statusCode === 200) { - const data = JSON.parse(res.data) - if (data.code === 0) { - resolve(data) - } else { - reject(new Error(data.message || '上传失败')) + try { + const data = JSON.parse(res.data) + if (data.code === 0) { + resolve(data) + } else { + reject(new Error(data.message || '上传失败')) + } + } catch (e) { + reject(new Error('解析响应失败')) } } else { - reject(new Error('上传失败')) + reject(new Error(`上传失败: ${res.statusCode}`)) } }, fail: (err) => { - reject(err) + reject(new Error(err.errMsg || '网络错误')) } }) }) diff --git a/miniapp/config/index.js b/miniapp/config/index.js index 7bceb49..54ca05f 100644 --- a/miniapp/config/index.js +++ b/miniapp/config/index.js @@ -21,7 +21,7 @@ const ENV = { } // 当前环境 - 开发时使用 development,打包时改为 production -const CURRENT_ENV = 'production' +const CURRENT_ENV = 'development' // 导出配置 export const config = { diff --git a/miniapp/pages/chat/index.vue b/miniapp/pages/chat/index.vue index 4234e4c..f52d8bc 100644 --- a/miniapp/pages/chat/index.vue +++ b/miniapp/pages/chat/index.vue @@ -229,7 +229,10 @@ 发送中 - 发送失败 + + 发送失败 + 重试 + @@ -530,6 +533,36 @@ const handleSendMessage = async () => { } } +// 重试发送失败的消息 +const handleRetryMessage = async (message) => { + if (message.status !== MessageStatus.FAILED) return + + message.status = MessageStatus.SENDING + + try { + const res = await sendMessage({ + sessionId: sessionId.value, + receiverId: targetUserId.value, + messageType: message.messageType, + content: message.content + }) + + if (res && res.code === 0) { + message.status = MessageStatus.SENT + if (res.data?.messageId) { + message.id = res.data.messageId + } + uni.showToast({ title: '发送成功', icon: 'success' }) + } else { + message.status = MessageStatus.FAILED + uni.showToast({ title: '发送失败', icon: 'none' }) + } + } catch (error) { + message.status = MessageStatus.FAILED + uni.showToast({ title: '发送失败', icon: 'none' }) + } +} + // 切换输入模式 const handleSwitchInputMode = () => { inputMode.value = inputMode.value === 'text' ? 'voice' : 'text' @@ -1444,6 +1477,18 @@ onUnmounted(() => { color: #ff5252; } } + + .status-failed-wrapper { + display: flex; + align-items: center; + gap: 12rpx; + } + + .retry-btn { + font-size: 22rpx; + color: #1890ff; + text-decoration: underline; + } } } diff --git a/miniapp/pages/index/index.vue b/miniapp/pages/index/index.vue index 751a596..4371d0b 100644 --- a/miniapp/pages/index/index.vue +++ b/miniapp/pages/index/index.vue @@ -215,7 +215,8 @@ if (res && res.code === 0) { configStore.setHomeConfig({ banners: res.data?.banners || [], - kingKongs: res.data?.kingKongs || [] + kingKongs: res.data?.kingKongs || [], + defaultAvatar: res.data?.defaultAvatar || '' }) } } catch (error) { diff --git a/miniapp/pages/login/index.vue b/miniapp/pages/login/index.vue index b06a0ca..812b090 100644 --- a/miniapp/pages/login/index.vue +++ b/miniapp/pages/login/index.vue @@ -122,12 +122,12 @@ export default { // 用户协议 const handleUserAgreement = () => { - uni.showToast({ title: '功能开发中', icon: 'none' }) + uni.navigateTo({ url: '/pages/agreement/index?type=user' }) } // 隐私政策 const handlePrivacyPolicy = () => { - uni.showToast({ title: '功能开发中', icon: 'none' }) + uni.navigateTo({ url: '/pages/agreement/index?type=privacy' }) } onMounted(() => { diff --git a/miniapp/pages/member/index.vue b/miniapp/pages/member/index.vue index 49e75f1..cab62e3 100644 --- a/miniapp/pages/member/index.vue +++ b/miniapp/pages/member/index.vue @@ -93,6 +93,7 @@ import { useUserStore } from '@/store/user.js' import { useConfigStore } from '@/store/config.js' import { getMemberInfo } from '@/api/member.js' import { createOrder } from '@/api/order.js' +import { getFullImageUrl } from '@/utils/image.js' import Loading from '@/components/Loading/index.vue' export default { @@ -181,7 +182,7 @@ export default { const userInfo = computed(() => ({ userId: userStore.userId, nickname: userStore.nickname, - avatar: userStore.avatar, + avatar: getFullImageUrl(userStore.avatar), isMember: userStore.isMember, memberLevel: userStore.memberLevel })) diff --git a/miniapp/pages/message/index.vue b/miniapp/pages/message/index.vue index ccef8a6..5e9c2e0 100644 --- a/miniapp/pages/message/index.vue +++ b/miniapp/pages/message/index.vue @@ -108,7 +108,19 @@ + + + + 登录后查看消息 + + + + + + 暂无聊天记录 + 去首页看看心仪的对象吧 + @@ -273,6 +285,11 @@ export default { }) } + // 跳转登录 + const handleLogin = () => { + uni.navigateTo({ url: '/pages/login/index' }) + } + onMounted(() => { getSystemInfo() initPage() @@ -289,10 +306,12 @@ export default { sessions, interactCounts, defaultAvatar, + userStore, formatTime, navigateTo, handleSessionClick, handleRefresh, + handleLogin, initPage, loadInteractCounts, loadSessions @@ -591,4 +610,47 @@ export default { } } } + +// 空状态 +.empty-state { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 120rpx 40rpx; + + .empty-icon { + width: 200rpx; + height: 200rpx; + margin-bottom: 32rpx; + opacity: 0.6; + } + + .empty-text { + font-size: 32rpx; + color: #666; + margin-bottom: 16rpx; + } + + .empty-tip { + font-size: 26rpx; + color: #999; + } + + .login-btn { + margin-top: 32rpx; + width: 240rpx; + height: 80rpx; + line-height: 80rpx; + background: linear-gradient(135deg, #FFBDC2 0%, #FF8A93 100%); + border-radius: 40rpx; + font-size: 30rpx; + color: #fff; + border: none; + + &::after { + border: none; + } + } +} diff --git a/miniapp/pages/profile/edit.vue b/miniapp/pages/profile/edit.vue index 878953c..a38c703 100644 --- a/miniapp/pages/profile/edit.vue +++ b/miniapp/pages/profile/edit.vue @@ -596,9 +596,19 @@ const getSystemInfo = () => { }) } -// 返回 +// 返回确认 const handleBack = () => { - uni.navigateBack() + uni.showModal({ + title: '提示', + content: '确定要离开吗?已填写的内容将不会保存', + confirmText: '离开', + cancelText: '继续填写', + success: (res) => { + if (res.confirm) { + uni.navigateBack() + } + } + }) } // 步骤配置 @@ -1332,6 +1342,26 @@ onMounted(() => { }) + +