From 95c11465702e7a4b3cd71ee1af2811d171d9116f Mon Sep 17 00:00:00 2001 From: lq Date: Wed, 7 Jan 2026 14:21:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A6=96=E9=A1=B5UI=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 70 ++ .../MessageNotification.vue | 236 ++++++ pages.json | 4 +- pages/Inquiries/Inquiries.vue | 14 +- pages/cate/cate.vue | 6 +- pages/cate/index.vue | 1 + pages/cate/info-detail.vue | 1 + pages/home/home.vue | 68 +- pages/home/index-list.vue | 1 + pages/home/index.vue | 1 + pages/index/doctor-info.vue | 1 + pages/index/index.vue | 29 +- pages/index/order-info.vue | 1 + pages/index/platform-info.vue | 1 + pages/index/system.vue | 1 + pages/login/login.vue | 1 + pages/login/logon.vue | 1 + pages/mine/mine.vue | 1 + request/api/im.js | 9 + request/api/product.js | 9 + store/chat/chat.js | 67 +- subPackages/chat/chat.vue | 400 ++++++--- subPackages/doctor/appraise.vue | 1 + subPackages/doctor/doctor-detail.vue | 5 +- subPackages/doctor/doctor-evaluation.vue | 1 + subPackages/doctor/doctor-info.vue | 1 + subPackages/doctor/doctor-picture.vue | 1 + subPackages/doctor/doctor-userinfo.vue | 44 +- subPackages/doctor/doctor_newsinfo.vue | 1 + subPackages/my/my-drug/drug-info.vue | 1 + subPackages/my/my-drug/drug-list.vue | 1 + subPackages/my/my-drug/to-next.vue | 1 + subPackages/my/myabout.vue | 1 + subPackages/my/myappiont.vue | 1 + subPackages/my/mycollection.vue | 1 + subPackages/my/myinfo-add.vue | 1 + subPackages/my/myinfo-edit.vue | 1 + subPackages/my/myinfo.vue | 1 + subPackages/my/myrecord-detail.vue | 1 + subPackages/my/myrecord.vue | 1 + subPackages/my/myreport.vue | 1 + subPackages/my/mystore.vue | 1 + subPackages/my/record-pay.vue | 1 + subPackages/my/unpaid-order.vue | 1 + subPackages/product/product.vue | 778 ++++++++++-------- subPackages/product/symptoms.vue | 1 + subPackages/register/register-info.vue | 1 + subPackages/register/register-success.vue | 1 + subPackages/register/register.vue | 71 +- subPackages/setup/area-list.vue | 1 + subPackages/setup/choose-area.vue | 1 + subPackages/setup/customer-service.vue | 1 + subPackages/setup/developer.vue | 1 + subPackages/setup/filed.vue | 1 + subPackages/setup/fw-serve.vue | 1 + subPackages/setup/ys-serve.vue | 1 + subPackages/setup/zz-serve.vue | 1 + subPackages/shop/after-sales.vue | 1 + subPackages/shop/logistics.vue | 1 + subPackages/shop/orders-detail.vue | 1 + subPackages/shop/orders.vue | 1 + subPackages/shop/paied-detail.vue | 1 + subPackages/shop/paied.vue | 1 + subPackages/shop/search-home.vue | 1 + subPackages/shop/search-list.vue | 1 + subPackages/shop/shop-cate.vue | 1 + subPackages/shop/shop-pay.vue | 1 + subPackages/shop/written.vue | 1 + 68 files changed, 1292 insertions(+), 571 deletions(-) create mode 100644 components/MessageNotification/MessageNotification.vue diff --git a/App.vue b/App.vue index 19fd7d9..db0586e 100644 --- a/App.vue +++ b/App.vue @@ -3,6 +3,7 @@ getVersion } from './request/api/api' import { webSocketManager } from '@/utils/ws/websocket.js'; + import { ChatManager } from '@/store/chat/chat.js'; import {checkDev} from "@/utils/utils"; import {bindUserApi} from "@/request/api/salesperson"; export default { @@ -151,7 +152,76 @@ methods: { initWebSocket() { webSocketManager.connect(); + + // 注册全局消息处理器 + webSocketManager.addMessageHandler((data) => { + // 只处理聊天消息(包含 room_id 的消息) + if (data.room_id) { + // 获取当前页面路径 + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + const currentPath = currentPage ? currentPage.route : ''; + + // 如果用户在聊天页面,不调用 ChatManager(chat.vue 会自己处理) + // 避免消息重复推送 + if (currentPath && currentPath.includes('chat/chat')) { + return; + } + + ChatManager.handleIncomingMessage(data); + } + }); + + // 监听全局通知事件 + uni.$on('show-global-notification', this.handleShowNotification); + }, + + /** + * 处理显示通知 + * @param {Object} message 消息对象 + */ + handleShowNotification(message) { + // 获取当前页面路径 + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + const currentPath = currentPage ? currentPage.route : ''; + + // 如果在聊天页面,不显示顶部通知 + if (currentPath && currentPath.includes('chat/chat')) { + return; + } + + // 获取消息预览文本 + const messagePreview = ChatManager.getMessagePreview(message); + + // 从消息中提取发送者信息 + let senderName = '新消息'; + let senderAvatar = '/static/xx/ysxx.png'; + + // 尝试解析发送者ID获取更多信息 + const senderId = message.sender_user_id || ''; + if (senderId.startsWith('doctor-')) { + senderName = '医生消息'; + } + + // 触发通知组件显示 + uni.$emit('show-message-notification', { + avatar: senderAvatar, + title: senderName, + message: messagePreview, + roomId: message.room_id, + roomData: { + nick_name: senderName, + user_id: senderId, + avatar: senderAvatar + } + }); } + }, + + onUnload() { + // 移除全局通知事件监听 + uni.$off('show-global-notification', this.handleShowNotification); } } diff --git a/components/MessageNotification/MessageNotification.vue b/components/MessageNotification/MessageNotification.vue new file mode 100644 index 0000000..6850026 --- /dev/null +++ b/components/MessageNotification/MessageNotification.vue @@ -0,0 +1,236 @@ + + + + + + diff --git a/pages.json b/pages.json index a211a95..52fa7b5 100644 --- a/pages.json +++ b/pages.json @@ -3,7 +3,9 @@ // 下载安装方式 // "^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue" // npm安装方式 - "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" + "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue", + // 消息通知组件 + "^MessageNotification": "@/components/MessageNotification/MessageNotification.vue" }, "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages diff --git a/pages/Inquiries/Inquiries.vue b/pages/Inquiries/Inquiries.vue index 1ff888b..2846338 100644 --- a/pages/Inquiries/Inquiries.vue +++ b/pages/Inquiries/Inquiries.vue @@ -1,5 +1,6 @@