front/src/components/top-nav/RightTopMessage.vue
zzh 5191d1981f feat: 仓储模块前端、菜单同步扩展及相关页面优化
新增仓储模块页面与 API、店铺授权/店铺订单页面及路由权限目录;
扩展菜单管理同步能力支持二级子菜单与三级按钮;优化公告、仓库地址、下单等页面。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-11 15:19:35 +08:00

177 lines
4.0 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>
<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: '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';
import { getNoticeList } from '@/api/system/notice';
const router = useRouter();
const notificationCount = 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 safeNoticeCount = computed(() => normalizeCount(noticeCount.value));
const totalUnreadCount = computed(() => {
return safeNotificationCount.value + safeNoticeCount.value;
});
const badgeNumberStyle = {
boxShadow: 'none',
height: '20px',
lineHeight: '20px',
minWidth: '20px',
fontSize: '16x',
fontWeight: 500,
padding: '0 6px',
};
const loadNotice = async () => {
try {
const { total } = await getNoticeList({
page: 1,
pageSize: 1,
noticeType: 'notice',
});
noticeCount.value = total;
} catch (error) {
console.error('Failed to load notice', error);
noticeCount.value = 0;
}
};
/** 消息:NoticeType = message 的总数 */
const loadNotification = async () => {
try {
const { total } = await getNoticeList({
page: 1,
pageSize: 1,
noticeType: 'message',
});
notificationCount.value = total;
} catch (error) {
console.error('Failed to load notification (message type)', error);
notificationCount.value = 0;
}
};
// 下拉菜单显示/隐藏时加载数据
const onMessageDropdownVisibleChange = (visible: boolean) => {
if (visible) {
loadNotice();
loadNotification();
}
};
const onMessageMenuClick = (event: { key?: string }) => {
if (event.key === 'notification') {
router.push({ name: 'SystemAnnouncement', query: { noticeType: 'message' } });
return;
}
if (event.key === 'notice') {
router.push({ name: 'SystemAnnouncement', query: { noticeType: 'notice' } });
}
};
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>