feat:【站内信】

This commit is contained in:
zpaeng
2025-08-21 23:42:53 +08:00
parent d8b3c68150
commit 84ab87878a
27 changed files with 1970 additions and 14 deletions

View File

@@ -6,7 +6,7 @@
<button class="menu-btn" ref="menuBtn" @click="$emit('toggle-menu')">
<i class="fas fa-bars"></i>
</button>
<span v-if="isMobile && unreadCount > 0" class="menu-unread-dot"></span>
<span v-if="isMobile && unreadMessageCount > 0" class="menu-unread-dot"></span>
</div>
<NuxtLink class="logo-container" :to="`/`" @click="refrechData">
<img
@@ -47,6 +47,13 @@
</div>
</ToolTip>
<ToolTip v-if="isLogin" content="站内信" placement="bottom">
<div class="messages-icon" @click="goToMessages">
<i class="fas fa-envelope"></i>
<span v-if="unreadMessageCount > 0" class="unread-badge">{{ unreadMessageCount }}</span>
</div>
</ToolTip>
<DropdownMenu v-if="isLogin" ref="userMenu" :items="headerMenuItems">
<template #trigger>
<div class="avatar-container">
@@ -75,7 +82,7 @@ import DropdownMenu from '~/components/DropdownMenu.vue'
import ToolTip from '~/components/ToolTip.vue'
import SearchDropdown from '~/components/SearchDropdown.vue'
import { authState, clearToken, loadCurrentUser } from '~/utils/auth'
import { fetchUnreadCount, notificationState } from '~/utils/notification'
import { useUnreadCount } from '~/composables/useUnreadCount'
import { useIsMobile } from '~/utils/screen'
import { themeState, cycleTheme, ThemeMode } from '~/utils/theme'
import { toast } from '~/main'
@@ -93,7 +100,7 @@ const props = defineProps({
const isLogin = computed(() => authState.loggedIn)
const isMobile = useIsMobile()
const unreadCount = computed(() => notificationState.unreadCount)
const { count: unreadMessageCount, fetchUnreadCount } = useUnreadCount()
const avatar = ref('')
const showSearch = ref(false)
const searchDropdown = ref(null)
@@ -182,15 +189,18 @@ const goToNewPost = () => {
}
const refrechData = async () => {
await fetchUnreadCount()
window.dispatchEvent(new Event('refresh-home'))
}
const goToMessages = () => {
navigateTo('/messages');
};
const headerMenuItems = computed(() => [
{ text: '设置', onClick: goToSettings },
{ text: '个人主页', onClick: goToProfile },
{ text: '退出', onClick: goToLogout },
])
]);
/** 其余逻辑保持不变 */
const iconClass = computed(() => {
@@ -215,9 +225,8 @@ onMounted(async () => {
}
const updateUnread = async () => {
if (authState.loggedIn) {
await fetchUnreadCount()
} else {
notificationState.unreadCount = 0
// Initialize the unread count composable
fetchUnreadCount();
}
}
@@ -226,7 +235,7 @@ onMounted(async () => {
watch(
() => authState.loggedIn,
async () => {
async (isLoggedIn) => {
await updateAvatar()
await updateUnread()
},
@@ -379,9 +388,27 @@ onMounted(async () => {
}
.rss-icon,
.new-post-icon {
.new-post-icon,
.messages-icon {
font-size: 18px;
cursor: pointer;
position: relative;
}
.unread-badge {
position: absolute;
top: -5px;
right: -10px;
background-color: #ff4d4f;
color: white;
border-radius: 50%;
padding: 2px 5px;
font-size: 10px;
font-weight: bold;
line-height: 1;
min-width: 16px;
text-align: center;
box-sizing: border-box;
}
.rss-icon {