This commit is contained in:
@@ -95,6 +95,9 @@
|
||||
|
||||
<view class="bottom-spacer"></view>
|
||||
|
||||
<NotificationPopup :show="notificationPopupShow" :items="notificationItems"
|
||||
:current="notificationPopupCurrent" @change="onNotificationChange" @close="closeNotificationPopup" />
|
||||
|
||||
<!-- 日期选择器弹窗 -->
|
||||
<up-datetime-picker v-if="!userInfo.isDevice" :show="showStartDatePicker" v-model="startDateTimestamp"
|
||||
mode="date" @confirm="onStartDateConfirm" @cancel="showStartDatePicker=false"
|
||||
@@ -123,6 +126,7 @@
|
||||
import WifiCard from '@/components/WifiCard.vue';
|
||||
import FunctionCard from '@/components/FunctionCard.vue';
|
||||
import FloatingButton from '@/components/FloatingButton.vue';
|
||||
import NotificationPopup from '@/components/NotificationPopup.vue';
|
||||
import {
|
||||
assetApi,
|
||||
deviceApi,
|
||||
@@ -213,6 +217,10 @@
|
||||
let smsCode = ref('');
|
||||
let indexEntryChecking = ref(false);
|
||||
let notificationUnreadCount = ref(0);
|
||||
let notificationPopupShow = ref(false);
|
||||
let notificationItems = ref([]);
|
||||
let notificationPopupCurrent = ref(0);
|
||||
const notificationReadPending = new Set();
|
||||
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return '-';
|
||||
@@ -784,6 +792,47 @@
|
||||
}
|
||||
};
|
||||
|
||||
const markNotificationRead = async (item) => {
|
||||
if (!item || item.is_read || notificationReadPending.has(item.id)) return;
|
||||
notificationReadPending.add(item.id);
|
||||
try {
|
||||
await notificationApi.markRead(item.id);
|
||||
item.is_read = true;
|
||||
item.read_at = new Date().toISOString();
|
||||
notificationUnreadCount.value = Math.max(notificationUnreadCount.value - 1, 0);
|
||||
} catch (error) {
|
||||
console.error('标记首页通知已读失败', error);
|
||||
} finally {
|
||||
notificationReadPending.delete(item.id);
|
||||
}
|
||||
};
|
||||
|
||||
const loadUnreadNotifications = async () => {
|
||||
try {
|
||||
const data = await notificationApi.getList(1, 50, false);
|
||||
const items = (data?.items || []).filter(item => !item.is_read);
|
||||
if (!items.length) return;
|
||||
|
||||
notificationItems.value = items;
|
||||
notificationPopupCurrent.value = 0;
|
||||
notificationPopupShow.value = true;
|
||||
// 弹窗打开即视为用户已看到第一条通知。
|
||||
markNotificationRead(items[0]);
|
||||
} catch (error) {
|
||||
console.error('加载首页未读通知失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
const onNotificationChange = (event) => {
|
||||
const index = Number(event?.detail?.current ?? event?.current ?? 0);
|
||||
notificationPopupCurrent.value = index;
|
||||
markNotificationRead(notificationItems.value[index]);
|
||||
};
|
||||
|
||||
const closeNotificationPopup = () => {
|
||||
notificationPopupShow.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initCurrentMonth();
|
||||
});
|
||||
@@ -791,6 +840,7 @@
|
||||
onShow(() => {
|
||||
handleIndexEntry();
|
||||
loadNotificationUnreadCount();
|
||||
loadUnreadNotifications();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user