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 >
2026-05-29 13:30:56 +08:00
< div v-if = "currentMessageContentHtml" class="message-content" v-html="currentMessageContentHtml" ></ div >
2026-05-18 09:46:11 +08:00
< 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'
2026-05-23 18:44:57 +08:00
/**
* Purpose: SystemMessageVO supports NotificationsView.vue by holding or executing the system message vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-18 09:46:11 +08:00
import { userApi , type SystemMessageVO } from '@/api/user'
2026-05-23 21:56:18 +08:00
import { buildSystemMessageActionPath } from '@/utils/system-message-action'
2026-05-29 13:30:56 +08:00
import { renderRichContent } from '@/utils/rich-content'
2026-05-18 09:46:11 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: router supports NotificationsView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-18 09:46:11 +08:00
const router = useRouter ()
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref ( false )
2026-05-23 18:44:57 +08:00
/**
* Purpose: messages supports NotificationsView.vue by holding or executing the messages page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-18 09:46:11 +08:00
const messages = ref < SystemMessageVO [] >([])
/** detailVisible is a reactive state variable used by the template and event handlers. */
const detailVisible = ref ( false )
2026-05-23 18:44:57 +08:00
/**
* Purpose: currentMessage supports NotificationsView.vue by holding or executing the current message page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-18 09:46:11 +08:00
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-29 13:30:56 +08:00
const currentMessageContentHtml = computed (() => renderRichContent ( currentMessage . value ? . content || '' ))
2026-05-18 09:46:11 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: resolveSystemMessageActionPath supports NotificationsView.vue by holding or executing the resolve system message action path page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 21:56:18 +08:00
const resolveSystemMessageActionPath = ( item : SystemMessageVO ) => buildSystemMessageActionPath ( item )
2026-05-23 15:16:40 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: markMessageReadIfNeeded supports NotificationsView.vue by holding or executing the mark message read if needed page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 15:16:40 +08:00
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 : 100 vh ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - page - bg );
2026-05-18 09:46:11 +08:00
padding : 18 px ;
}
. page - header {
display : flex ;
gap : 14 px ;
align - items : center ;
margin - bottom : 18 px ;
}
. page - header h1 {
margin : 0 ;
2026-05-31 18:36:52 +08:00
font - size : 20 px ;
2026-05-18 09:46:11 +08:00
}
. page - header p {
margin : 4 px 0 0 ;
2026-05-29 13:30:56 +08:00
color : var ( -- text - secondary );
2026-05-18 09:46:11 +08:00
}
. back - btn {
width : 40 px ;
height : 40 px ;
border : 0 ;
border - radius : 20 px ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - card - bg );
2026-05-18 09:46:11 +08:00
font - size : 28 px ;
}
. message - list {
display : grid ;
gap : 10 px ;
}
. message - item {
display : flex ;
align - items : center ;
gap : 12 px ;
width : 100 % ;
padding : 16 px ;
border : 0 ;
border - radius : 8 px ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - card - bg );
border : 1 px solid var ( -- theme - border );
2026-05-18 09:46:11 +08:00
text - align : left ;
}
. message - item . dot {
width : 8 px ;
height : 8 px ;
border - radius : 50 % ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - border );
2026-05-18 09:46:11 +08:00
}
. message - item . unread . dot {
2026-05-29 13:30:56 +08:00
background : var ( -- theme - primary );
2026-05-18 09:46:11 +08:00
}
. message - main {
display : grid ;
gap : 4 px ;
}
. message - main em {
width : fit - content ;
padding : 2 px 8 px ;
border - radius : 999 px ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - primary - soft );
color : var ( -- theme - primary );
2026-05-18 09:46:11 +08:00
font - size : 12 px ;
font - style : normal ;
}
. message - main small ,
. message - meta {
2026-05-29 13:30:56 +08:00
color : var ( -- text - secondary );
2026-05-18 09:46:11 +08:00
}
. message - content {
line - height : 1.8 ;
2026-05-29 13:30:56 +08:00
overflow - wrap : break - word ;
}
. message - content : deep ( * ) {
max - width : 100 % ;
}
. message - content : deep ( p ),
. message - content : deep ( ul ),
. message - content : deep ( ol ),
. message - content : deep ( blockquote ),
. message - content : deep ( pre ),
. message - content : deep ( table ) {
margin : 0 0 12 px ;
}
. message - content : deep ( p : last - child ),
. message - content : deep ( ul : last - child ),
. message - content : deep ( ol : last - child ),
. message - content : deep ( blockquote : last - child ),
. message - content : deep ( pre : last - child ),
. message - content : deep ( table : last - child ) {
margin - bottom : 0 ;
}
. message - content : deep ( ul ),
. message - content : deep ( ol ) {
padding - left : 1.25 em ;
}
. message - content : deep ( a ) {
color : var ( -- theme - primary );
}
. message - content : deep ( img ) {
display : block ;
max - width : 100 % ;
border - radius : 8 px ;
}
. message - content : deep ( pre ) {
overflow - x : auto ;
padding : 10 px 12 px ;
border - radius : 8 px ;
background : var ( -- theme - primary - soft );
2026-05-18 09:46:11 +08:00
}
. message - image {
display : block ;
width : 100 % ;
max - height : 420 px ;
margin - top : 14 px ;
object - fit : contain ;
border - radius : 8 px ;
2026-05-29 13:30:56 +08:00
background : var ( -- theme - primary - soft );
}
. notifications - page {
padding : 18 px 18 px 34 px ;
background :
radial - gradient ( circle at 84 % 0 % , color - mix ( in srgb , var ( -- theme - primary ) 28 % , transparent ), transparent 30 % ),
linear - gradient ( 180 deg , color - mix ( in srgb , var ( -- theme - card - bg ) 74 % , transparent ), var ( -- theme - page - bg ));
}
. page - header {
margin - bottom : 22 px ;
}
. page - header h1 {
2026-05-31 18:36:52 +08:00
font - size : 21 px ;
2026-05-29 13:30:56 +08:00
font - weight : 860 ;
}
. page - header p {
color : var ( -- theme - secondary );
font - weight : 700 ;
}
. back - btn {
color : var ( -- theme - primary - action );
background : color - mix ( in srgb , var ( -- theme - card - bg ) 82 % , transparent );
box - shadow : 0 12 px 24 px color - mix ( in srgb , var ( -- theme - neutral ) 8 % , transparent );
}
. message - list {
gap : 12 px ;
}
. message - item {
align - items : flex - start ;
padding : 17 px ;
border - radius : 22 px ;
background : color - mix ( in srgb , var ( -- theme - card - bg ) 90 % , transparent );
box - shadow : 0 18 px 38 px color - mix ( in srgb , var ( -- theme - neutral ) 7 % , transparent );
}
. message - item . unread {
border - color : color - mix ( in srgb , var ( -- theme - primary ) 36 % , var ( -- theme - border ));
}
. message - item . unread . dot {
background : var ( -- theme - primary - action );
}
. message - main strong {
color : var ( -- text - primary );
font - size : 15 px ;
}
. message - main em {
color : var ( -- theme - primary - action );
background : color - mix ( in srgb , var ( -- theme - primary ) 18 % , var ( -- theme - card - bg ));
}
. message - content : deep ( a ) {
color : var ( -- theme - primary - action );
2026-05-18 09:46:11 +08:00
}
</ style >