2026-04-23 09:39:12 +08:00
|
|
|
|
<template>
|
2026-05-31 09:51:57 +08:00
|
|
|
|
<div class="notifications-view mini-scrollbar" @scroll="handleScroll">
|
|
|
|
|
|
<section class="notifications-hero">
|
|
|
|
|
|
<div class="notifications-hero__content">
|
|
|
|
|
|
<h1 class="notifications-hero__title">Notifications</h1>
|
|
|
|
|
|
<p class="notifications-hero__subtitle">System announcements and updates</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="notifications-content">
|
|
|
|
|
|
<NotificationsList
|
|
|
|
|
|
:items="notifications"
|
|
|
|
|
|
:unread-count="unreadCount"
|
|
|
|
|
|
@toggle-item="handleToggleItem"
|
|
|
|
|
|
@mark-all-as-read="handleMarkAllAsRead"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div v-if="loading" class="loading-indicator">Loading...</div>
|
|
|
|
|
|
<div v-if="!hasMore && notifications.length > 0" class="no-more-data">No more notifications</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
2026-04-23 09:39:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
2026-05-31 09:51:57 +08:00
|
|
|
|
import { computed, ref, onMounted } from 'vue'
|
2026-06-01 10:44:32 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n'
|
2026-05-31 09:51:57 +08:00
|
|
|
|
import NotificationsList from './components/NotificationsList.vue'
|
|
|
|
|
|
import type { NotificationRecord } from './types'
|
|
|
|
|
|
import { fetchAllMessageList, markMessageAsRead, markAllMessagesAsRead } from '@/api/notification'
|
|
|
|
|
|
|
2026-06-01 10:44:32 +08:00
|
|
|
|
const { locale } = useI18n()
|
|
|
|
|
|
|
|
|
|
|
|
// Store notifications with original date strings
|
|
|
|
|
|
interface NotificationWithOriginalDate extends NotificationRecord {
|
|
|
|
|
|
originalDate: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const notificationsRaw = ref<NotificationWithOriginalDate[]>([])
|
2026-05-31 09:51:57 +08:00
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const hasMore = ref(true)
|
|
|
|
|
|
|
2026-06-01 10:44:32 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Format date based on current language
|
|
|
|
|
|
* Chinese: yyyy年M月D日 (e.g., 2024年5月15日)
|
|
|
|
|
|
* English: Month Day, Year (e.g., January 15, 2024)
|
|
|
|
|
|
*/
|
|
|
|
|
|
const formatDate = (dateString: string): string => {
|
|
|
|
|
|
if (!dateString) return ''
|
|
|
|
|
|
|
|
|
|
|
|
const date = new Date(dateString)
|
|
|
|
|
|
if (isNaN(date.getTime())) return dateString
|
|
|
|
|
|
|
|
|
|
|
|
const isChinese = locale.value === 'CHINESE_SIMPLIFIED'
|
|
|
|
|
|
|
|
|
|
|
|
if (isChinese) {
|
|
|
|
|
|
// Chinese format: yyyy年M月D日 (without leading zeros)
|
|
|
|
|
|
const year = date.getFullYear()
|
|
|
|
|
|
const month = date.getMonth() + 1
|
|
|
|
|
|
const day = date.getDate()
|
|
|
|
|
|
return `${year}年${month}月${day}日`
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// English format: Month Day, Year
|
|
|
|
|
|
const options: Intl.DateTimeFormatOptions = {
|
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
|
month: 'long',
|
|
|
|
|
|
day: 'numeric'
|
|
|
|
|
|
}
|
|
|
|
|
|
return date.toLocaleDateString('en-US', options)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Computed property that formats dates based on current locale
|
|
|
|
|
|
const notifications = computed<NotificationRecord[]>(() => {
|
|
|
|
|
|
return notificationsRaw.value.map((item) => ({
|
|
|
|
|
|
id: item.id,
|
|
|
|
|
|
title: item.title,
|
|
|
|
|
|
date: formatDate(item.originalDate),
|
|
|
|
|
|
content: item.content,
|
|
|
|
|
|
isUnread: item.isUnread,
|
|
|
|
|
|
isExpanded: item.isExpanded
|
|
|
|
|
|
}))
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-05-31 09:51:57 +08:00
|
|
|
|
const unreadCount = computed(() => notifications.value.filter((item) => item.isUnread).length)
|
|
|
|
|
|
|
|
|
|
|
|
const handleToggleItem = async (id: NotificationRecord['id']) => {
|
2026-06-01 10:44:32 +08:00
|
|
|
|
const targetItem = notificationsRaw.value.find((item) => item.id === id)
|
2026-05-31 09:51:57 +08:00
|
|
|
|
|
|
|
|
|
|
if (!targetItem) return
|
|
|
|
|
|
|
|
|
|
|
|
const nextExpanded = !targetItem.isExpanded
|
|
|
|
|
|
|
|
|
|
|
|
// 如果消息是未读状态,调用API标记为已读
|
|
|
|
|
|
if (targetItem.isUnread) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await markMessageAsRead(id)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to mark message as read:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-01 10:44:32 +08:00
|
|
|
|
notificationsRaw.value = notificationsRaw.value.map((item) => ({
|
2026-05-31 09:51:57 +08:00
|
|
|
|
...item,
|
|
|
|
|
|
isUnread: item.id === id ? false : item.isUnread,
|
|
|
|
|
|
isExpanded: item.id === id ? nextExpanded : false
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleMarkAllAsRead = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await markAllMessagesAsRead()
|
2026-06-01 10:44:32 +08:00
|
|
|
|
notificationsRaw.value = notificationsRaw.value.map((item) => ({
|
2026-05-31 09:51:57 +08:00
|
|
|
|
...item,
|
|
|
|
|
|
isUnread: false
|
|
|
|
|
|
}))
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to mark all messages as read:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const params = ref({
|
|
|
|
|
|
page: 1,
|
|
|
|
|
|
size: 15
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const handleFetchMessageList = async () => {
|
|
|
|
|
|
if (loading.value || !hasMore.value) return
|
|
|
|
|
|
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await fetchAllMessageList(params.value)
|
|
|
|
|
|
|
2026-06-01 10:44:32 +08:00
|
|
|
|
// Transform API data to match NotificationRecord interface with original date
|
|
|
|
|
|
const newNotifications: NotificationWithOriginalDate[] = res.content.map((item: any) => ({
|
2026-05-31 09:51:57 +08:00
|
|
|
|
id: String(item.id),
|
|
|
|
|
|
title: item.title,
|
2026-06-01 10:44:32 +08:00
|
|
|
|
date: item.createTime, // This will be formatted by computed property
|
|
|
|
|
|
originalDate: item.createTime, // Store original date for re-formatting
|
2026-05-31 09:51:57 +08:00
|
|
|
|
content: item.content,
|
|
|
|
|
|
isUnread: item.isRead === 0,
|
|
|
|
|
|
isExpanded: false
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
if (params.value.page === 1) {
|
2026-06-01 10:44:32 +08:00
|
|
|
|
notificationsRaw.value = newNotifications
|
2026-05-31 09:51:57 +08:00
|
|
|
|
} else {
|
2026-06-01 10:44:32 +08:00
|
|
|
|
notificationsRaw.value = [...notificationsRaw.value, ...newNotifications]
|
2026-05-31 09:51:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check if there are more pages
|
|
|
|
|
|
hasMore.value = params.value.page < res.pages
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to fetch notifications:', error)
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleScroll = (event: Event) => {
|
|
|
|
|
|
const target = event.target as HTMLElement
|
|
|
|
|
|
const scrollTop = target.scrollTop
|
|
|
|
|
|
const scrollHeight = target.scrollHeight
|
|
|
|
|
|
const clientHeight = target.clientHeight
|
|
|
|
|
|
|
|
|
|
|
|
// Load more when scrolled to 80% of the content
|
|
|
|
|
|
if (scrollTop + clientHeight >= scrollHeight * 0.8 && !loading.value && hasMore.value) {
|
|
|
|
|
|
params.value.page++
|
|
|
|
|
|
handleFetchMessageList()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
handleFetchMessageList()
|
|
|
|
|
|
})
|
2026-04-23 09:39:12 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
2026-05-31 09:51:57 +08:00
|
|
|
|
.notifications-view {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero {
|
|
|
|
|
|
min-height: 14.8rem;
|
|
|
|
|
|
padding: 3.2rem 2rem;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2026-06-01 10:44:32 +08:00
|
|
|
|
background: url('@/assets/images/wardrobe/settings_bg.jpg') no-repeat;
|
|
|
|
|
|
background-size: cover;
|
2026-05-31 09:51:57 +08:00
|
|
|
|
border-bottom: 0.05rem solid #dfd8d1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero__content {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero__title {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
color: #232323;
|
|
|
|
|
|
font-size: 4rem;
|
|
|
|
|
|
line-height: 1;
|
|
|
|
|
|
font-family: 'KaiseiOpti-Bold';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero__subtitle {
|
|
|
|
|
|
margin: 1.2rem 0 0;
|
|
|
|
|
|
color: #585858;
|
|
|
|
|
|
font-size: 1.6rem;
|
|
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
font-family: 'KaiseiOpti-Regular';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-content {
|
|
|
|
|
|
width: min(108rem, calc(100% - 4rem));
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
padding: 4rem 0 8rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-indicator,
|
|
|
|
|
|
.no-more-data {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
padding: 2rem;
|
|
|
|
|
|
color: #979797;
|
|
|
|
|
|
font-size: 1.4rem;
|
|
|
|
|
|
font-family: 'KaiseiOpti-Regular';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
|
.notifications-hero {
|
|
|
|
|
|
min-height: 12rem;
|
|
|
|
|
|
padding: 2.8rem 1.6rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero__title {
|
|
|
|
|
|
font-size: 3rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-hero__subtitle {
|
|
|
|
|
|
margin-top: 0.8rem;
|
|
|
|
|
|
font-size: 1.4rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.notifications-content {
|
|
|
|
|
|
width: calc(100% - 3.2rem);
|
|
|
|
|
|
padding: 3.2rem 0 4.8rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-23 09:39:12 +08:00
|
|
|
|
</style>
|