feat: 添加公告功能,支持查看公告和在系统浏览器中打开链接

This commit is contained in:
2025-08-31 23:11:24 +08:00
parent fe35e37371
commit c5fd0c1253
5 changed files with 108 additions and 6 deletions

View File

@@ -23,7 +23,12 @@
class="notice-tab-pane"
>
<div class="notice-content">
<div class="markdown-content" v-html="renderMarkdown(content)"></div>
<div
ref="markdownContentRef"
class="markdown-content"
v-html="renderMarkdown(content)"
@click="handleLinkClick"
></div>
</div>
</a-tab-pane>
</a-tabs>
@@ -116,6 +121,33 @@ const confirmNotices = async () => {
}
}
// 处理链接点击
const handleLinkClick = async (event: MouseEvent) => {
const target = event.target as HTMLElement
if (target.tagName === 'A') {
event.preventDefault()
const url = target.getAttribute('href')
if (url) {
try {
// 检查是否在Electron环境中
if (window.electronAPI && window.electronAPI.openUrl) {
const result = await window.electronAPI.openUrl(url)
if (!result.success) {
console.error('打开链接失败:', result.error)
message.error('打开链接失败,请手动复制链接地址')
}
} else {
// 如果不在Electron环境中使用普通的window.open
window.open(url, '_blank')
}
} catch (error) {
console.error('打开链接失败:', error)
message.error('打开链接失败,请手动复制链接地址')
}
}
}
}
// 监听公告数据变化,设置默认选中第一个公告
watch(
() => props.noticeData,