184 lines
4.3 KiB
Vue
184 lines
4.3 KiB
Vue
<template>
|
||
<a-dropdown trigger="hover" placement="bottomRight" @visible-change="onMessageDropdownVisibleChange">
|
||
<div class="message-dropdown-trigger">
|
||
<IconNotification class="message-icon" :class="totalUnreadCount > 0 ? 'theMessage' : ''" title="消息" />
|
||
<a-badge
|
||
v-if="totalUnreadCount > 0"
|
||
class="message-badge"
|
||
:count="totalUnreadCount"
|
||
:max-count="99"
|
||
:number-style="badgeNumberStyle"
|
||
/>
|
||
<span v-else class="message-zero">(0)</span>
|
||
</div>
|
||
<template #content>
|
||
<a-doption @click="() => onMessageMenuClick({ key: 'notification' })">
|
||
通知({{ safeNotificationCount }})
|
||
</a-doption>
|
||
<a-doption @click="() => onMessageMenuClick({ key: 'message' })">
|
||
消息({{ safeMessageCount }})
|
||
</a-doption>
|
||
<a-doption @click="() => onMessageMenuClick({ key: 'notice' })">
|
||
公告({{ safeNoticeCount }})
|
||
</a-doption>
|
||
</template>
|
||
</a-dropdown>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { computed, ref, onMounted } from 'vue';
|
||
import { useRouter } from 'vue-router';
|
||
import { IconNotification } from '@arco-design/web-vue/es/icon';
|
||
|
||
const router = useRouter();
|
||
const notificationCount = ref<number | string>(0);
|
||
const messageCount = ref<number | string>(0);
|
||
const noticeCount = ref<number | string>(0);
|
||
|
||
const normalizeCount = (value: number | string) => {
|
||
const parsed = Number(value);
|
||
if (!Number.isFinite(parsed) || parsed < 0) {
|
||
return 0;
|
||
}
|
||
return Math.floor(parsed);
|
||
};
|
||
|
||
const safeNotificationCount = computed(() =>
|
||
normalizeCount(notificationCount.value)
|
||
);
|
||
const safeMessageCount = computed(() => normalizeCount(messageCount.value));
|
||
const safeNoticeCount = computed(() => normalizeCount(noticeCount.value));
|
||
|
||
const totalUnreadCount = computed(() => {
|
||
return (
|
||
safeNotificationCount.value +
|
||
safeMessageCount.value +
|
||
safeNoticeCount.value
|
||
);
|
||
});
|
||
|
||
const badgeNumberStyle = {
|
||
boxShadow: 'none',
|
||
height: '20px',
|
||
lineHeight: '20px',
|
||
minWidth: '20px',
|
||
fontSize: '16x',
|
||
fontWeight: 500,
|
||
padding: '0 6px',
|
||
};
|
||
|
||
// 加载通知和公告
|
||
const loadNotice = async () => {
|
||
try {
|
||
// TODO: 替换为实际的 API 调用
|
||
// const res = await ApiSystemMain.loadNotice();
|
||
// if (res.code == 0) {
|
||
// let readNum = 0;
|
||
// for (let i = 0; i < res.data.length; i++) {
|
||
// if (!res.data[i].read) {
|
||
// readNum++;
|
||
// }
|
||
// }
|
||
// noticeCount.value = readNum;
|
||
// }
|
||
} catch (error) {
|
||
console.error('Failed to load notice', error);
|
||
}
|
||
};
|
||
|
||
const loadNotification = async () => {
|
||
try {
|
||
// TODO: 替换为实际的 API 调用
|
||
// const res = await ApiSystemUser.systemNotificationMsg({});
|
||
// if (res.code == 0 && res.data) {
|
||
// const data = Array.isArray(res.data) ? res.data : [];
|
||
// notificationCount.value = data.filter((item: any) => !item.read).length || 0;
|
||
// }
|
||
} catch (error) {
|
||
console.error('Failed to load notification', error);
|
||
notificationCount.value = 0;
|
||
}
|
||
};
|
||
|
||
// 下拉菜单显示/隐藏时加载数据
|
||
const onMessageDropdownVisibleChange = (visible: boolean) => {
|
||
if (visible) {
|
||
loadNotice();
|
||
loadNotification();
|
||
}
|
||
};
|
||
|
||
// 点击菜单项 - 站内信功能已移除
|
||
const onMessageMenuClick = (event: any) => {
|
||
// 站内信功能已移除,不再跳转
|
||
};
|
||
|
||
onMounted(() => {
|
||
loadNotice();
|
||
loadNotification();
|
||
});
|
||
</script>
|
||
|
||
<style scoped>
|
||
@keyframes zy {
|
||
10% {
|
||
transform: rotate(15deg);
|
||
}
|
||
20% {
|
||
transform: rotate(-10deg);
|
||
}
|
||
30% {
|
||
transform: rotate(5deg);
|
||
}
|
||
40% {
|
||
transform: rotate(-5deg);
|
||
}
|
||
50%,
|
||
100% {
|
||
transform: rotate(0deg);
|
||
}
|
||
}
|
||
|
||
.theMessage {
|
||
animation: zy 2.5s 0.15s linear infinite;
|
||
-moz-animation: zy 2.5s 0.15s linear infinite;
|
||
-webkit-animation: zy 2.5s 0.15s linear infinite;
|
||
-o-animation: zy 2.5s 0.15s linear infinite;
|
||
}
|
||
|
||
.message-dropdown-trigger {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
white-space: nowrap;
|
||
cursor: pointer;
|
||
padding: 0 8px;
|
||
flex-shrink: 0;
|
||
color: inherit;
|
||
text-decoration: none;
|
||
transition: all 0.3s;
|
||
column-gap: 6px;
|
||
}
|
||
|
||
.message-dropdown-trigger:hover {
|
||
opacity: 0.8;
|
||
}
|
||
|
||
.message-icon {
|
||
font-size: 22px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.message-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.message-zero {
|
||
font-size: 16x;
|
||
font-weight: 500;
|
||
color: var(--color-text-3);
|
||
}
|
||
</style>
|
||
|