feat(notice): 新增公告优先级和未读状态功能,优化公告展示逻辑

This commit is contained in:
2025-12-30 22:49:03 +08:00
parent 76c324b0df
commit 88a4e58130
21 changed files with 1520 additions and 13 deletions

View File

@@ -9,6 +9,9 @@ import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
// 全局变量,用于控制公告弹窗只显示一次
let hasShownNoticePopup = false
NProgress.configure({ showSpinner: false });
const whiteList = ['/login', '/register'];
@@ -65,4 +68,36 @@ router.beforeEach((to, from, next) => {
router.afterEach(() => {
NProgress.done()
})
// 登录成功后显示公告弹窗(仅限非登录页面且未显示过)
const token = getToken()
const isLoginPage = router.currentRoute.value.path === '/login'
if (token && !isLoginPage && !hasShownNoticePopup) {
// 延迟显示,确保页面完全加载
setTimeout(() => {
showNoticePopupGlobally()
hasShownNoticePopup = true
}, 1500)
}
})
// 全局函数:显示公告弹窗
function showNoticePopupGlobally() {
try {
// 通过多种方式尝试获取并显示公告弹窗
const layouts = document.querySelectorAll('.app-wrapper')
for (const layout of layouts) {
const noticePopupRef = layout.__vue_app__?.config.globalProperties.$refs?.noticePopupRef
if (noticePopupRef && noticePopupRef.showNotice) {
noticePopupRef.showNotice()
return
}
}
// 如果直接获取失败,尝试通过事件总线方式
window.dispatchEvent(new CustomEvent('show-notice-popup'))
} catch (error) {
console.error('显示公告弹窗失败:', error)
}
}