2026-05-18 09:46:11 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="notifications-page">
|
|
|
|
|
|
<header class="page-header">
|
|
|
|
|
|
<button class="back-btn" type="button" @click="router.back()">‹</button>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h1>消息通知</h1>
|
|
|
|
|
|
<p>{{ unreadCount }} 条未读消息</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<main class="message-list">
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-for="item in messages"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
class="message-item"
|
|
|
|
|
|
:class="{ unread: item.readStatus !== 1 }"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
@click="openMessage(item)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span class="dot"></span>
|
|
|
|
|
|
<span class="message-main">
|
|
|
|
|
|
<strong>{{ item.title }}</strong>
|
|
|
|
|
|
<small>{{ item.publisherName || '系统消息' }} · {{ item.publishTime || item.createTime }}</small>
|
|
|
|
|
|
<em v-if="item.imageUrl">含图片</em>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<a-empty v-if="!loading && messages.length === 0" description="暂无消息" />
|
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
|
|
<a-modal v-model:open="detailVisible" title="消息详情" @ok="detailVisible = false">
|
|
|
|
|
|
<h3>{{ currentMessage?.title }}</h3>
|
|
|
|
|
|
<p class="message-meta">{{ currentMessage?.publisherName || '系统消息' }} · {{ currentMessage?.publishTime }}</p>
|
|
|
|
|
|
<div v-if="currentMessage?.content" class="message-content">{{ currentMessage?.content }}</div>
|
|
|
|
|
|
<img v-if="currentMessage?.imageUrl" class="message-image" :src="currentMessage.imageUrl" alt="消息图片" />
|
|
|
|
|
|
</a-modal>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
/**
|
|
|
|
|
|
* NotificationsView page script.
|
|
|
|
|
|
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
|
|
|
|
|
*/
|
|
|
|
|
|
import { computed, onMounted, ref } from 'vue'
|
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
|
import { userApi, type SystemMessageVO } from '@/api/user'
|
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
/** loading is a reactive state variable used by the template and event handlers. */
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const messages = ref<SystemMessageVO[]>([])
|
|
|
|
|
|
/** detailVisible is a reactive state variable used by the template and event handlers. */
|
|
|
|
|
|
const detailVisible = ref(false)
|
|
|
|
|
|
const currentMessage = ref<SystemMessageVO | null>(null)
|
|
|
|
|
|
/** unreadCount is a reactive state variable used by the template and event handlers. */
|
|
|
|
|
|
const unreadCount = computed(() => messages.value.filter(item => item.readStatus !== 1).length)
|
|
|
|
|
|
|
2026-05-23 15:16:40 +08:00
|
|
|
|
const resolveSystemMessageActionPath = (item: SystemMessageVO) => {
|
|
|
|
|
|
const actionPath = String(item.actionPath || '').trim()
|
|
|
|
|
|
if (!actionPath || !actionPath.startsWith('/') || actionPath.startsWith('//')) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
return actionPath
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const markMessageReadIfNeeded = async (item: SystemMessageVO) => {
|
|
|
|
|
|
if (item.readStatus === 1) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
await userApi.markMessageRead(item.id)
|
|
|
|
|
|
item.readStatus = 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
|
/** loadMessages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
|
|
|
|
const loadMessages = async () => {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
messages.value = await userApi.listMyMessages()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
message.error(error?.message || '消息加载失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** openMessage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
|
|
|
|
const openMessage = async (item: SystemMessageVO) => {
|
2026-05-23 15:16:40 +08:00
|
|
|
|
try {
|
|
|
|
|
|
await markMessageReadIfNeeded(item)
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
message.error(error?.message || '标记已读失败')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const actionPath = resolveSystemMessageActionPath(item)
|
|
|
|
|
|
if (actionPath) {
|
|
|
|
|
|
await router.push(actionPath)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
|
currentMessage.value = item
|
|
|
|
|
|
detailVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(loadMessages)
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.notifications-page {
|
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
|
background: #fff7f8;
|
|
|
|
|
|
padding: 18px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 14px;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-bottom: 18px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header h1 {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header p {
|
|
|
|
|
|
margin: 4px 0 0;
|
|
|
|
|
|
color: #8a7b83;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.back-btn {
|
|
|
|
|
|
width: 40px;
|
|
|
|
|
|
height: 40px;
|
|
|
|
|
|
border: 0;
|
|
|
|
|
|
border-radius: 20px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
font-size: 28px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-list {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
border: 0;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
text-align: left;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-item .dot {
|
|
|
|
|
|
width: 8px;
|
|
|
|
|
|
height: 8px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
background: #d7c9cf;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-item.unread .dot {
|
|
|
|
|
|
background: #ff5c8a;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-main {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-main em {
|
|
|
|
|
|
width: fit-content;
|
|
|
|
|
|
padding: 2px 8px;
|
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
|
background: #fff0f4;
|
|
|
|
|
|
color: #d74270;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
font-style: normal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-main small,
|
|
|
|
|
|
.message-meta {
|
|
|
|
|
|
color: #8a7b83;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-content {
|
|
|
|
|
|
white-space: pre-wrap;
|
|
|
|
|
|
line-height: 1.8;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-image {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
max-height: 420px;
|
|
|
|
|
|
margin-top: 14px;
|
|
|
|
|
|
object-fit: contain;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
background: #fff7f8;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|