From c910876f279696b4e8c8268bd028bc7233bcb31f Mon Sep 17 00:00:00 2001 From: BianLzhaoMin <11485688+bianliangzhaomin123@user.noreply.gitee.com> Date: Wed, 7 Jan 2026 15:28:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../own/message-notification/detail/index.vue | 83 ++++++++++++++++--- src/pages/own/message-notification/index.vue | 7 +- .../realName/own/message-notification.js | 8 ++ 3 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/pages/own/message-notification/detail/index.vue b/src/pages/own/message-notification/detail/index.vue index 951067c..17d879c 100644 --- a/src/pages/own/message-notification/detail/index.vue +++ b/src/pages/own/message-notification/detail/index.vue @@ -72,7 +72,10 @@ import { ref, computed, onMounted, onUnmounted } from 'vue' import NavBarModal from '@/components/NavBarModal/index.vue' import { getContentStyle, getSafeAreaInfo } from '@/utils/safeArea' +import { useMemberStore } from '@/stores' +import { confirmMessageAPI } from '@/services/realName/own/message-notification' +const memberStore = useMemberStore() const contentStyle = computed(() => { return getContentStyle({ includeNavBar: true, @@ -85,6 +88,8 @@ const countdown = ref(5) let countdownTimer = null const canConfirm = ref(false) const messageDetail = ref({}) +const isConfirmed = ref(false) +const isAlreadyRead = ref(false) const photoList = computed(() => { if (!messageDetail.value.photoFilePath) { @@ -103,6 +108,11 @@ const photoList = computed(() => { }) const confirmButtonText = computed(() => { + // 已读:始终显示“点击确认” + if (isAlreadyRead.value) { + return '点击确认' + } + // 未读:进入时有倒计时 if (countdown.value > 0) { return `${countdown.value}秒` } @@ -204,23 +214,66 @@ const handleDownload = () => { }) } -const handleConfirm = () => { +const handleConfirm = async () => { if (!canConfirm.value) { return } - uni.showToast({ - title: '已确认', - icon: 'success', - }) - - setTimeout(() => { + // 已读消息:不再调用接口,直接返回 + if (isAlreadyRead.value) { uni.navigateBack() - }, 1500) + return + } + + try { + uni.showLoading({ + title: '确认中...', + }) + + const res = await confirmMessageAPI({ + workerId: memberStore.realNameUserInfo.workerId, + notifyId: messageDetail.value.notifyId, + }) + + uni.hideLoading() + if (res && res.res === 1) { + isConfirmed.value = true + uni.showToast({ + title: '已确认', + icon: 'success', + }) + uni.$emit('refreshMessageNotificationList') + setTimeout(() => { + uni.navigateBack() + }, 500) + } else { + uni.showToast({ + title: res?.msg || '确认失败', + icon: 'none', + }) + } + } catch (error) { + uni.hideLoading() + console.error('确认消息失败:', error) + uni.showToast({ + title: '确认失败', + icon: 'none', + }) + } } const handleBack = () => { - uni.navigateBack() + // 已读或已确认:直接返回 + if (isConfirmed.value || isAlreadyRead.value) { + uni.navigateBack() + return + } + + uni.showModal({ + title: '提示', + content: '请先确认消息', + showCancel: false, + }) } onMounted(() => { @@ -231,13 +284,21 @@ onMounted(() => { const messageParam = options.message if (messageParam) { - messageDetail.value = JSON.parse(decodeURIComponent(messageParam)) + const detail = JSON.parse(decodeURIComponent(messageParam)) + messageDetail.value = detail + // isRead === 'No' 表示未读,其它情况视为已读 + isAlreadyRead.value = detail.isRead && detail.isRead !== 'No' } } catch (error) { console.error('获取页面参数失败:', error) } - startCountdown() + // 未读才启用倒计时,已读则立即可确认且不再调用接口 + if (!isAlreadyRead.value) { + startCountdown() + } else { + canConfirm.value = true + } }) onUnmounted(() => { diff --git a/src/pages/own/message-notification/index.vue b/src/pages/own/message-notification/index.vue index 62688cc..091aa8e 100644 --- a/src/pages/own/message-notification/index.vue +++ b/src/pages/own/message-notification/index.vue @@ -35,7 +35,7 @@ diff --git a/src/services/realName/own/message-notification.js b/src/services/realName/own/message-notification.js index af47457..7b9f82f 100644 --- a/src/services/realName/own/message-notification.js +++ b/src/services/realName/own/message-notification.js @@ -9,3 +9,11 @@ export const getMessageNotificationListAPI = (data) => { method: 'POST', }) } + +// 确认消息 +export const confirmMessageAPI = (data) => { + return realNameHttp({ + url: `/notify/addNotifyRecord?${initParams(data)}`, + method: 'POST', + }) +}