fix: 修复公告关闭功能 - 当次关闭与永久关闭区分
问题:不管选择"当次关闭"还是"永久关闭",都会永久关闭公告 修复: - 当次关闭:使用 sessionStorage + pageToken - pageToken 基于 performance.timeOrigin 生成 - 刷新页面后 token 变化,公告重新显示 - 永久关闭:使用 localStorage - 持久化存储,刷新/重开后不再显示 修改文件: - app-frontend/src/layouts/AppLayout.vue - templates/index.html 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,56 @@ const announcementOpen = ref(false)
|
||||
const announcement = ref(null)
|
||||
const announcementLoading = ref(false)
|
||||
|
||||
const announcementPageToken = (() => {
|
||||
try {
|
||||
const timeOrigin = window.performance?.timeOrigin
|
||||
if (typeof timeOrigin === 'number' && Number.isFinite(timeOrigin)) return String(timeOrigin)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
return String(Date.now())
|
||||
})()
|
||||
|
||||
function announcementOnceKey(announcementId) {
|
||||
return `announcement_closed_once_${announcementId}`
|
||||
}
|
||||
|
||||
function announcementPermanentKey(announcementId) {
|
||||
return `announcement_closed_${announcementId}`
|
||||
}
|
||||
|
||||
function wasAnnouncementClosedOnce(announcementId) {
|
||||
try {
|
||||
return window.sessionStorage.getItem(announcementOnceKey(announcementId)) === announcementPageToken
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function wasAnnouncementClosedPermanently(announcementId) {
|
||||
try {
|
||||
return window.localStorage.getItem(announcementPermanentKey(announcementId)) === '1'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function markAnnouncementClosedOnce(announcementId) {
|
||||
try {
|
||||
window.sessionStorage.setItem(announcementOnceKey(announcementId), announcementPageToken)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
function markAnnouncementClosedPermanently(announcementId) {
|
||||
try {
|
||||
window.localStorage.setItem(announcementPermanentKey(announcementId), '1')
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const feedbackOpen = ref(false)
|
||||
const feedbackTab = ref('new')
|
||||
const feedbackSubmitting = ref(false)
|
||||
@@ -329,8 +379,8 @@ async function loadAnnouncement() {
|
||||
const ann = data?.announcement
|
||||
if (!ann?.id) return
|
||||
|
||||
const sessionKey = `announcement_closed_${ann.id}`
|
||||
if (window.sessionStorage.getItem(sessionKey) === '1') return
|
||||
if (wasAnnouncementClosedPermanently(ann.id)) return
|
||||
if (wasAnnouncementClosedOnce(ann.id)) return
|
||||
|
||||
announcement.value = ann
|
||||
announcementOpen.value = true
|
||||
@@ -343,7 +393,7 @@ async function loadAnnouncement() {
|
||||
|
||||
function closeAnnouncementOnce() {
|
||||
const ann = announcement.value
|
||||
if (ann?.id) window.sessionStorage.setItem(`announcement_closed_${ann.id}`, '1')
|
||||
if (ann?.id) markAnnouncementClosedOnce(ann.id)
|
||||
announcementOpen.value = false
|
||||
}
|
||||
|
||||
@@ -353,6 +403,7 @@ async function dismissAnnouncementPermanently() {
|
||||
announcementOpen.value = false
|
||||
return
|
||||
}
|
||||
markAnnouncementClosedPermanently(ann.id)
|
||||
try {
|
||||
const res = await dismissAnnouncement(ann.id)
|
||||
if (res?.success) ElMessage.success('已永久关闭')
|
||||
|
||||
Reference in New Issue
Block a user