import React, { useEffect, useState } from 'react'; import { CloseOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import ReactMarkdown from 'react-markdown'; import rehypeRaw from 'rehype-raw'; import { shouldShowUpdate, isUpdateNotificationDisabled, getCurrentVersion, getVersionHistory } from './version'; import ImagePreview from '../ImagePreview'; import './style.less'; interface UpdateNotificationProps { version: string; // 版本号,用于控制是否显示 } const UpdateNotification: React.FC = ({ version }) => { const [visible, setVisible] = useState(false); const [content, setContent] = useState(''); const [isAnimating, setIsAnimating] = useState(false); const [previewImage, setPreviewImage] = useState(null); useEffect(() => { // 检查是否被禁用 if (isUpdateNotificationDisabled()) { return; } // 检查是否已经看过这个版本的更新 const lastViewedVersion = localStorage.getItem('lastViewedUpdateVersion'); if (shouldShowUpdate(lastViewedVersion)) { // 立即保存版本号,防止退出登录或刷新后重复显示 localStorage.setItem('lastViewedUpdateVersion', version); // 加载更新内容 - 从历史记录中提取最新版本 import('../../docs/update-history/index.md?raw') .then((module) => { const fullContent = module.default; // 提取第一个版本的内容(从第一个 ## 📅 到下一个 --- 之间的内容) const versionRegex = /##\s+📅.*?\n\n([\s\S]*?)(?=\n---)/; const match = fullContent.match(versionRegex); if (match && match[1]) { // 只取内容部分,不包括版本标题 setContent(match[1].trim()); } else { // 如果匹配失败,显示整个文档 console.warn('无法提取最新版本内容,显示完整文档'); setContent(fullContent); } setTimeout(() => { setVisible(true); setIsAnimating(true); }, 800); }) .catch((error) => { console.error('Failed to load update content:', error); }); } }, [version]); const handleClose = () => { setIsAnimating(false); setTimeout(() => { setVisible(false); }, 300); }; const handleImageClick = (src: string) => { setPreviewImage(src); }; const handleClosePreview = () => { setPreviewImage(null); }; if (!visible) return null; return ( <> {/* 遮罩层 */}
{/* 弹窗 */}
{getVersionHistory().find(v => v.version === getCurrentVersion())?.date || new Date().toISOString().split('T')[0]} 版本公告

, h4: (props: React.HTMLAttributes & { className?: string }) => (

), p: (props) =>

, div: (props: React.HTMLAttributes & { className?: string }) => { if (props.className === 'update-item') { return

; } return
; }, img: (props: React.ImgHTMLAttributes & { src?: string; alt?: string }) => { const src = props.src?.startsWith('/') ? props.src : `/${props.src || ''}`; return ( {props.alt handleImageClick(src)} /> ); }, }} > {content}
window.open('/help/update-history', '_blank')} style={{ cursor: 'pointer' }} > 版本公告将在帮助文档中
{/* 图片预览模态框 */} ); }; export default UpdateNotification;