From fc8c573994df6411ffd6574c50c847a3b4c7be20 Mon Sep 17 00:00:00 2001 From: "wangmingyong@163.com" Date: Fri, 31 Jul 2026 18:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E6=B3=95=E9=A2=84=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/enforcement/notice.js | 3 + .../enforcement/enforce/enforcementChat.vue | 6 +- .../src/api/enterprise/planNotice.js | 5 + .../enforcement/enforcementChat.vue | 111 +++++++++++------- .../enterprise/message/messageCenter.vue | 30 ++++- .../vite-env/.env.enterprise-dev-wmy | 2 +- 6 files changed, 108 insertions(+), 49 deletions(-) diff --git a/zdxt-web-client/zdxt-efcode-enforcement-app/src/api/enforcement/notice.js b/zdxt-web-client/zdxt-efcode-enforcement-app/src/api/enforcement/notice.js index a1d848a2..2d06d782 100644 --- a/zdxt-web-client/zdxt-efcode-enforcement-app/src/api/enforcement/notice.js +++ b/zdxt-web-client/zdxt-efcode-enforcement-app/src/api/enforcement/notice.js @@ -30,4 +30,7 @@ export const getNoticeMessages = (noticeId, success, error) => _get(noticeBaseUr // 新增留言 export const addNoticeMessage = (params, success, error) => _post(noticeBaseUrl + "/message", params, success, error); +// 标记留言已读 +export const messageRead = (noticeId, success, error) => _get(noticeBaseUrl + "/messageRead", { noticeId }, success, error); + // endregion diff --git a/zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/enforce/enforcementChat.vue b/zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/enforce/enforcementChat.vue index 57fb910c..0268731c 100644 --- a/zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/enforce/enforcementChat.vue +++ b/zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/enforce/enforcementChat.vue @@ -126,7 +126,7 @@ import { ref, nextTick, onMounted } from 'vue'; import { useRouter, useRoute } from 'vue-router'; import { showToast } from 'vant'; import 'vant/es/toast/style'; -import { getNoticeMessages, addNoticeMessage } from '@/api/enforcement/notice'; +import { getNoticeMessages, addNoticeMessage, messageRead } from '@/api/enforcement/notice'; const router = useRouter(); const route = useRoute(); @@ -147,6 +147,7 @@ const loadMessageList = () => { if (!noticeId) return; getNoticeMessages(noticeId, (res) => { if (res && res.code === 200 && res.data) { + const lastItem = res.data[res.data.length - 1]; messageList.value = res.data.map(item => ({ id: item.id, sender: item.userName == useCommon.userName ? 'self' : 'other', @@ -156,6 +157,9 @@ const loadMessageList = () => { isRecalled: item.isRecalled || false, })); nextTick(() => scrollToBottom()); + if (lastItem && lastItem.id) { + messageRead(lastItem.id, () => {}, () => {}); + } } }, () => { showToast('加载消息失败'); diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/src/api/enterprise/planNotice.js b/zdxt-web-client/zdxt-efcode-enterprise-app/src/api/enterprise/planNotice.js index d16abd24..34745f04 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/src/api/enterprise/planNotice.js +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/src/api/enterprise/planNotice.js @@ -14,6 +14,11 @@ export const getPlanNoticeMessageList = (params, success, error) => _get(enterpr //执法预告消息列表(lawNotice) export const getLawNoticeMessageList = (params, success, error) => _get(enterpriseAppBaseUrl +"/enterprise/lawNotice/message/list",params,success,error); +//执法预告发送消息 +export const sendLawNoticeMessage = (params, success, error) => _post(enterpriseAppBaseUrl +"/enterprise/lawNotice/message",params,success,error); +//执法预告发送消息已读未读 +export const sendLawNoticeMessageViewed = (params, success, error) => _get(enterpriseAppBaseUrl +"/enterprise/lawNotice/messageRead",params,success,error); + //执法预告新增留言 export const addPlanNoticeMessage = (params, success, error) => _post(enterpriseAppBaseUrl +"/planNotice/message",params,success,error); diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue index 4901b5d8..020bf236 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue @@ -77,7 +77,7 @@ - - + -->
@@ -125,10 +125,11 @@ import { ref, nextTick, onMounted } from 'vue'; import { showToast } from 'vant'; import 'vant/es/toast/style'; -import { getLawNoticeMessageList } from '@/api/enterprise/planNotice'; +import { getLawNoticeMessageList, sendLawNoticeMessage, sendLawNoticeMessageViewed } from '@/api/enterprise/planNotice'; const router = useRouter(); const route = useRoute(); +const { useCommon } = $globalStore; // ========== 从路由参数获取信息 ========== const noticeId = ref(route.query.id || ''); @@ -154,14 +155,35 @@ const fetchMessageList = () => { (res) => { if (res.code === 200) { const rows = res.rows || res.data?.rows || res.data?.list || res.data || []; - messageList.value = rows.map(item => ({ - id: item.id || item.messageId, - sender: item.sender === 'self' || item.senderType === 1 || item.isSelf ? 'self' : 'other', - content: item.content || item.message || item.messageContent, - time: item.time || item.createTime || item.sendMessageTime || '', - avatar: item.sender === 'self' || item.senderType === 1 || item.isSelf ? selfAvatar : otherAvatar, - isRecalled: item.isRecalled || item.recallStatus || false, - })); + const currentUserName = useCommon.enterpriseName || ''; + messageList.value = rows.map(item => { + const isSelf = item.userName == currentUserName; + return { + id: item.id, + sender: isSelf ? 'self' : 'other', + content: item.message, + time:item.createTime|| '', + avatar: isSelf ? selfAvatar : otherAvatar, + isRecalled: item.isRecalled || false, + }; + }); + + // 取最后一条数据的id,调用已读接口 + if (rows.length > 0) { + const lastMessageId = rows[rows.length - 1].id; + sendLawNoticeMessageViewed( + { noticeId: lastMessageId }, + (viewRes) => { + if (viewRes.code !== 200) { + console.warn('标记已读失败:', viewRes.msg); + } + }, + () => { + console.warn('标记已读网络请求失败'); + } + ); + } + nextTick(() => { scrollToBottom(); }); @@ -332,39 +354,38 @@ const sendMessage = () => { return; } - const now = new Date(); - const timeStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; - - messageList.value.push({ - id: Date.now(), - sender: 'self', - content: text, - time: timeStr, - avatar: selfAvatar, - isRecalled: false, - }); - - inputMessage.value = ''; - - // 滚动到底部 - nextTick(() => { - scrollToBottom(); + // 调用接口发送消息 + const params = { + noticeId: noticeId.value, + userId: String(useCommon.userId || ''), + userName: useCommon.enterpriseName || '企业', + message: text, + }; + sendLawNoticeMessage(params, (res) => { + if (res.code === 200) { + const now = new Date(); + const timeStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; + messageList.value.push({ + id: res.data?.id || Date.now(), + sender: 'self', + content: text, + time: timeStr, + avatar: selfAvatar, + isRecalled: false, + }); + + inputMessage.value = ''; + + // 滚动到底部 + nextTick(() => { + scrollToBottom(); + }); + } else { + showToast(res.msg || '发送失败'); + } + }, () => { + showToast('网络请求失败'); }); - - // 模拟对方回复 - // setTimeout(() => { - // messageList.value.push({ - // id: Date.now() + 1, - // sender: 'other', - // content: '收到,我们会尽快安排并与您确认具体时间。', - // time: timeStr, - // avatar: otherAvatar, - // isRecalled: false, - // }); - // nextTick(() => { - // scrollToBottom(); - // }); - // }, 1500); }; // ========== 滚动到底部 ========== diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/message/messageCenter.vue b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/message/messageCenter.vue index 98b6d108..b8545336 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/message/messageCenter.vue +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/message/messageCenter.vue @@ -18,7 +18,11 @@
- + + - + + messageList.value.reduce((sum, item) => sum + (item.unreadCount || 0), 0)); +const todoBadge = computed(() => todoList.value.reduce((sum, item) => sum + (item.unreadCount || 0), 0)); + // ========== 消息统计数据 ========== const messageStats = ref({ pffwCount: 0, // 涉企普法未读数量 @@ -437,6 +449,20 @@ onMounted(() => { border-radius: 2px; } +.tab-badge { + display: inline-block; + min-width: 16px; + height: 16px; + padding: 0 4px; + margin-left: 4px; + background: #f44336; + border-radius: 8px; + color: #fff; + font-size: 10px; + line-height: 14px; + text-align: center; + +} :deep(.message-tabs .van-tabs__content) { background: #fbfdff; padding: 12px 16px; diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/vite-env/.env.enterprise-dev-wmy b/zdxt-web-client/zdxt-efcode-enterprise-app/vite-env/.env.enterprise-dev-wmy index 6f05ff16..dd42223f 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/vite-env/.env.enterprise-dev-wmy +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/vite-env/.env.enterprise-dev-wmy @@ -1,7 +1,7 @@ # 企业端开发环境 VITE_PORT = 12001 # VITE_PROXY_TARGET = 'http://139.186.148.21:8080' -# VITE_PROXY_TARGET = 'http://172.16.21.213:8080' +VITE_PROXY_TARGET = 'http://172.16.21.213:8080' VITE_BASE_URL = '/efcode20-ent-app/api' VITE_CONTEXT_PATH = '/efcode20-ent-app/' VITE_DEFAULT_LOGIN = '/enterprise/loginByPassword'