| | |
| | | </el-icon> |
| | | </div> |
| | | <div class="notification-content-wrapper"> |
| | | <div class="notification-title">{{ item.title }}</div> |
| | | <div class="notification-detail">{{ item.content }}</div> |
| | | <div class="notification-title">{{ item.noticeTitle }}</div> |
| | | <div class="notification-detail">{{ item.noticeContent }}</div> |
| | | <div class="notification-time">{{ item.createTime }}</div> |
| | | </div> |
| | | <div class="notification-action"> |
| | | <el-button type="primary" size="small" @click="handleConfirm(item.id)"> |
| | | <el-button type="primary" size="small" @click="handleConfirm(item)"> |
| | | 确认 |
| | | </el-button> |
| | | </div> |
| | |
| | | </el-icon> |
| | | </div> |
| | | <div class="notification-content-wrapper"> |
| | | <div class="notification-title">{{ item.title }}</div> |
| | | <div class="notification-detail">{{ item.content }}</div> |
| | | <div class="notification-title">{{ item.noticeTitle }}</div> |
| | | <div class="notification-detail">{{ item.noticeContent }}</div> |
| | | <div class="notification-time">{{ item.createTime }}</div> |
| | | </div> |
| | | </div> |
| | |
| | | import { Bell } from '@element-plus/icons-vue' |
| | | import { listMessage, markAsRead, markAllAsRead, confirmMessage, getUnreadCount } from '@/api/system/message' |
| | | import { ElMessage } from 'element-plus' |
| | | import useUserStore from '@/store/modules/user' |
| | | import { useRouter } from 'vue-router' |
| | | |
| | | const userStore = useUserStore() |
| | | const router = useRouter() |
| | | const emit = defineEmits(['unreadCountChange']) |
| | | |
| | | const activeTab = ref('unread') |
| | |
| | | // 加载消息列表 |
| | | const loadMessages = async () => { |
| | | try { |
| | | const consigneeId = userStore.id |
| | | if (!consigneeId) { |
| | | console.warn('未获取到当前登录用户ID') |
| | | return |
| | | } |
| | | const params = { |
| | | consigneeId: consigneeId, |
| | | pageNum: pageNum.value, |
| | | pageSize: pageSize.value, |
| | | isRead: activeTab.value === 'read' ? 1 : 0 |
| | | status: activeTab.value === 'read' ? 1 : 0 |
| | | } |
| | | const res = await listMessage(params) |
| | | if (res.code === 200) { |
| | | if (activeTab.value === 'unread') { |
| | | unreadList.value = res.rows || [] |
| | | unreadList.value = res.data.records || [] |
| | | } else { |
| | | readList.value = res.rows || [] |
| | | readList.value = res.data.records || [] |
| | | } |
| | | total.value = res.total || 0 |
| | | total.value = res.data.total || 0 |
| | | } |
| | | } catch (error) { |
| | | console.error('加载消息列表失败:', error) |
| | |
| | | // 加载未读数量 |
| | | const loadUnreadCount = async () => { |
| | | try { |
| | | const res = await getUnreadCount() |
| | | const consigneeId = userStore.id |
| | | if (!consigneeId) { |
| | | console.warn('未获取到当前登录用户ID') |
| | | return |
| | | } |
| | | const res = await getUnreadCount(consigneeId) |
| | | if (res.code === 200) { |
| | | unreadCount.value = res.data || 0 |
| | | emit('unreadCountChange', unreadCount.value) |
| | |
| | | } |
| | | |
| | | // 确认消息 |
| | | const handleConfirm = async (messageId) => { |
| | | const handleConfirm = async (item) => { |
| | | try { |
| | | const res = await confirmMessage(messageId) |
| | | console.log('item', item) |
| | | const res = await confirmMessage(item.noticeId, 1) |
| | | if (res.code === 200) { |
| | | ElMessage.success('确认成功') |
| | | // 标记为已读 |
| | | await markAsRead(messageId) |
| | | // 重新加载数据 |
| | | loadMessages() |
| | | loadUnreadCount() |
| | | |
| | | // 根据 jumpPath 进行页面跳转 |
| | | if (item.jumpPath) { |
| | | try { |
| | | // 解析 jumpPath,分离路径和查询参数 |
| | | const [path, queryString] = item.jumpPath.split('?') |
| | | let query = {} |
| | | |
| | | if (queryString) { |
| | | // 解析查询参数 |
| | | queryString.split('&').forEach(param => { |
| | | const [key, value] = param.split('=') |
| | | if (key && value) { |
| | | query[key] = decodeURIComponent(value) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 跳转到指定页面 |
| | | router.push({ |
| | | path: path, |
| | | query: query |
| | | }) |
| | | } catch (error) { |
| | | console.error('页面跳转失败:', error) |
| | | } |
| | | } |
| | | } |
| | | } catch (error) { |
| | | console.error('确认消息失败:', error) |