Files
JayuCloud/JY-Artist-Frontend/src/views/NotificationsView.vue
T
2026-06-29 23:26:43 +08:00

332 lines
9.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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="currentMessageContentHtml" class="message-content" v-html="currentMessageContentHtml"></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'
/**
* 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.
*/
import { userApi, type SystemMessageVO } from '@/api/user'
import { buildSystemMessageActionPath } from '@/utils/system-message-action'
import { renderRichContent } from '@/utils/rich-content'
/**
* 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.
*/
const router = useRouter()
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/**
* 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.
*/
const messages = ref<SystemMessageVO[]>([])
/** detailVisible is a reactive state variable used by the template and event handlers. */
const detailVisible = ref(false)
/**
* 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.
*/
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)
const currentMessageContentHtml = computed(() => renderRichContent(currentMessage.value?.content || ''))
/**
* 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.
*/
const resolveSystemMessageActionPath = (item: SystemMessageVO) => buildSystemMessageActionPath(item)
/**
* 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.
*/
const markMessageReadIfNeeded = async (item: SystemMessageVO) => {
if (item.readStatus === 1) {
return
}
await userApi.markMessageRead(item.id)
item.readStatus = 1
}
/** 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) => {
try {
await markMessageReadIfNeeded(item)
} catch (error: any) {
message.error(error?.message || '标记已读失败')
return
}
const actionPath = resolveSystemMessageActionPath(item)
if (actionPath) {
await router.push(actionPath)
return
}
currentMessage.value = item
detailVisible.value = true
}
onMounted(loadMessages)
</script>
<style scoped>
.notifications-page {
min-height: 100vh;
background: var(--theme-page-bg);
padding: 18px;
}
.page-header {
display: flex;
gap: 14px;
align-items: center;
margin-bottom: 18px;
}
.page-header h1 {
margin: 0;
font-size: 20px;
}
.page-header p {
margin: 4px 0 0;
color: var(--text-secondary);
}
.back-btn {
width: 40px;
height: 40px;
border: 0;
border-radius: 20px;
background: var(--theme-card-bg);
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: var(--theme-card-bg);
border: 1px solid var(--theme-border);
text-align: left;
}
.message-item .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--theme-border);
}
.message-item.unread .dot {
background: var(--theme-primary);
}
.message-main {
display: grid;
gap: 4px;
}
.message-main em {
width: fit-content;
padding: 2px 8px;
border-radius: 999px;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 12px;
font-style: normal;
}
.message-main small,
.message-meta {
color: var(--text-secondary);
}
.message-content {
line-height: 1.8;
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 12px;
}
.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.25em;
}
.message-content :deep(a) {
color: var(--theme-primary);
}
.message-content :deep(img) {
display: block;
max-width: 100%;
border-radius: 8px;
}
.message-content :deep(pre) {
overflow-x: auto;
padding: 10px 12px;
border-radius: 8px;
background: var(--theme-primary-soft);
}
.message-image {
display: block;
width: 100%;
max-height: 420px;
margin-top: 14px;
object-fit: contain;
border-radius: 8px;
background: var(--theme-primary-soft);
}
.notifications-page {
padding: 18px 18px 34px;
background:
radial-gradient(circle at 84% 0%, color-mix(in srgb, var(--theme-primary) 28%, transparent), transparent 30%),
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 74%, transparent), var(--theme-page-bg));
}
.page-header {
margin-bottom: 22px;
}
.page-header h1 {
font-size: 21px;
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 12px 24px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
}
.message-list {
gap: 12px;
}
.message-item {
align-items: flex-start;
padding: 17px;
border-radius: 22px;
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
box-shadow: 0 18px 38px 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: 15px;
}
.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);
}
</style>