app1消息功能修改 #129

Merged
hnu202326010125 merged 1 commits from luoyuehang_branch into develop 2 weeks ago

@ -31,7 +31,7 @@
<div
v-for="notification in notifications"
:key="notification.id"
:class="['notification-item', { 'unread': !notification.isRead }]"
:class="['notification-item', { 'unread': !getNotificationReadStatus(notification) }]"
@click="viewNotification(notification)"
>
<div class="notification-content">
@ -42,12 +42,12 @@
<div class="notification-body">
<div class="notification-text">{{ notification.content }}</div>
<div class="notification-status">
<span v-if="!notification.isRead" class="unread-dot"></span>
<span class="status-text">{{ notification.isRead ? '已读' : '未读' }}</span>
<span v-if="!getNotificationReadStatus(notification)" class="unread-dot"></span>
<span class="status-text">{{ getNotificationReadStatus(notification) ? '已读' : '未读' }}</span>
</div>
</div>
</div>
<div class="notification-actions" v-if="!notification.isRead">
<div class="notification-actions" v-if="!getNotificationReadStatus(notification)">
<button class="mark-read-btn" @click.stop="markAsRead(notification.id)">
标记已读
</button>
@ -80,6 +80,7 @@ const notifications = ref([])
const loading = ref(true)
//
// loadNotifications
const loadNotifications = async () => {
try {
const repairmanId = authStore.getRepairmanId
@ -92,7 +93,8 @@ const loadNotifications = async () => {
if (response.code === 200) {
notifications.value = response.data.map(notification => ({
...notification,
isRead: notification.isRead || false
// 'read' 'isRead'
isRead: notification.read !== undefined ? notification.read : notification.isRead || false
}))
} else {
console.error('获取通知失败:', response.message)
@ -105,25 +107,44 @@ const loadNotifications = async () => {
}
}
//
// markAsRead
const markAsRead = async (notificationId) => {
try {
await notificationService.markNotificationAsRead(notificationId)
//
const notification = notifications.value.find(n => n.id === notificationId)
if (notification) {
notification.isRead = true
const response = await notificationService.markNotificationAsRead(notificationId);
if (response.code === 200) {
console.log('标记已读成功');
//
await loadNotifications();
}
} catch (error) {
console.error('标记已读失败:', error)
alert('标记已读失败: ' + (error.message || '未知错误'))
console.error('标记已读失败:', error);
}
}
};
//
//
const getNotificationReadStatus = (notification) => {
return notification.read !== undefined ? notification.read : notification.isRead || false;
};
// markAsReadAndRefresh
const markAsReadAndRefresh = async (notificationId) => {
try {
await notificationService.markNotificationAsRead(notificationId); //
//
await loadNotifications();
} catch (error) {
console.error('操作失败:', error);
}
};
// markAllAsRead 使
const markAllAsRead = async () => {
try {
const unreadNotifications = notifications.value.filter(n => !n.isRead)
const unreadNotifications = notifications.value.filter(n => !n.isRead) // 使
if (unreadNotifications.length === 0) {
alert('没有未读通知')
return
@ -131,9 +152,12 @@ const markAllAsRead = async () => {
for (const notification of unreadNotifications) {
await notificationService.markNotificationAsRead(notification.id)
notification.isRead = true
notification.isRead = true // 使
}
//
await loadNotifications();
alert('已标记所有通知为已读')
} catch (error) {
console.error('标记所有已读失败:', error)
@ -141,6 +165,8 @@ const markAllAsRead = async () => {
}
}
//
const getNotificationTitle = (notification) => {
switch (notification.type) {
@ -174,16 +200,18 @@ const formatTime = (timeStr) => {
//
const viewNotification = (notification) => {
const isRead = getNotificationReadStatus(notification);
//
if (notification.type === 'ORDER_ASSIGNED' && notification.orderId) {
router.push(`/work-orders/${notification.orderId}`)
//
if (!notification.isRead) {
if (!isRead) {
markAsRead(notification.id)
}
} else {
//
if (!notification.isRead) {
if (!isRead) {
markAsRead(notification.id)
}
//

Loading…
Cancel
Save