feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -19,23 +19,24 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import React, { useEffect, useState, useContext, useMemo } from 'react';
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
Modal,
|
||||
} from '@douyinfe/semi-ui';
|
||||
Segmented,
|
||||
Spin,
|
||||
Tag,
|
||||
theme,
|
||||
} from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API, showError, getRelativeTime } from '../../helpers';
|
||||
import { marked } from 'marked';
|
||||
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import {
|
||||
Bell,
|
||||
Megaphone,
|
||||
Sparkles,
|
||||
X,
|
||||
CalendarClock,
|
||||
Volume2,
|
||||
Clock,
|
||||
ChevronRight,
|
||||
} from 'lucide-react';
|
||||
import { Bell, Volume1 } from 'lucide-react';
|
||||
import './notice-modal.css';
|
||||
|
||||
const EMPTY_ANNOUNCEMENTS = [];
|
||||
|
||||
const NoticeModal = ({
|
||||
visible,
|
||||
@@ -45,14 +46,14 @@ const NoticeModal = ({
|
||||
unreadKeys = [],
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { token } = theme.useToken();
|
||||
const [noticeContent, setNoticeContent] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState(defaultTab);
|
||||
|
||||
const [dismissToday, setDismissToday] = useState(true);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
|
||||
const announcements = statusState?.status?.announcements || [];
|
||||
|
||||
const announcements =
|
||||
statusState?.status?.announcements || EMPTY_ANNOUNCEMENTS;
|
||||
const unreadSet = useMemo(() => new Set(unreadKeys), [unreadKeys]);
|
||||
|
||||
const getKeyForItem = (item) =>
|
||||
@@ -114,321 +115,145 @@ const NoticeModal = ({
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setActiveTab(defaultTab);
|
||||
setDismissToday(true);
|
||||
}
|
||||
}, [defaultTab, visible]);
|
||||
|
||||
const renderMarkdownNotice = () => {
|
||||
if (loading) {
|
||||
return (
|
||||
<div className='py-20 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-16 h-16 border-4 border-brand/10 dark:border-brand-deep rounded-full' />
|
||||
<div className='absolute inset-0 w-16 h-16 border-4 border-transparent border-t-brand rounded-full animate-spin' />
|
||||
<div
|
||||
className='absolute inset-2 w-12 h-12 border-4 border-transparent border-t-brand-via rounded-full animate-spin'
|
||||
style={{
|
||||
animationDirection: 'reverse',
|
||||
animationDuration: '0.8s',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<span className='mt-4 text-gray-500 dark:text-gray-400 font-medium'>
|
||||
{t('加载中...')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!noticeContent) {
|
||||
return (
|
||||
<div className='py-16 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-24 h-24 bg-gradient-to-br from-brand-from/5 to-brand-to/5 dark:from-brand-from/30 dark:to-brand-to/30 rounded-3xl flex items-center justify-center shadow-inner'>
|
||||
<Bell
|
||||
size={40}
|
||||
className='text-brand-from dark:text-brand-deep'
|
||||
/>
|
||||
</div>
|
||||
<div className='absolute -bottom-1 -right-1 w-8 h-8 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-xl flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={16} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<span className='mt-5 text-gray-700 dark:text-gray-300 text-lg font-semibold'>
|
||||
{t('暂无公告')}
|
||||
</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 text-sm mt-1'>
|
||||
{t('一切正常,稍后再来看看吧')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='notice-content-scroll max-h-[50vh] overflow-y-auto pr-2 custom-scrollbar'>
|
||||
<div className='p-4 bg-gray-50/80 dark:bg-gray-800/60 rounded-xl border border-gray-200/60 dark:border-gray-700/40'>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: noticeContent }}
|
||||
className='prose prose-sm dark:prose-invert max-w-none
|
||||
prose-headings:text-gray-900 dark:prose-headings:text-gray-50 prose-headings:font-bold
|
||||
prose-h1:text-xl prose-h2:text-lg prose-h3:text-base
|
||||
prose-p:text-gray-600 dark:prose-p:text-gray-300 prose-p:leading-relaxed
|
||||
prose-a:text-brand-deep dark:prose-a:text-brand-from prose-a:no-underline hover:prose-a:underline prose-a:font-medium
|
||||
prose-strong:text-gray-800 dark:prose-strong:text-gray-100
|
||||
prose-code:bg-gray-100 dark:prose-code:bg-gray-800 prose-code:text-gray-700 dark:prose-code:text-gray-300 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded-md prose-code:text-xs
|
||||
prose-pre:bg-gray-900 dark:prose-pre:bg-gray-950 prose-pre:text-gray-100 prose-pre:rounded-xl
|
||||
prose-img:rounded-xl
|
||||
prose-ul:space-y-1 prose-ol:space-y-1
|
||||
prose-li:text-gray-600 dark:prose-li:text-gray-300'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const getTypeConfig = (type) => {
|
||||
const configs = {
|
||||
success: {
|
||||
bg: 'bg-emerald-50 dark:bg-emerald-900/20',
|
||||
border: 'border-emerald-200 dark:border-emerald-800',
|
||||
dot: 'bg-emerald-500',
|
||||
tag: 'green',
|
||||
},
|
||||
warning: {
|
||||
bg: 'bg-amber-50 dark:bg-amber-900/20',
|
||||
border: 'border-amber-200 dark:border-amber-800',
|
||||
dot: 'bg-amber-500',
|
||||
tag: 'orange',
|
||||
},
|
||||
error: {
|
||||
bg: 'bg-red-50 dark:bg-red-900/20',
|
||||
border: 'border-red-200 dark:border-red-800',
|
||||
dot: 'bg-red-500',
|
||||
tag: 'red',
|
||||
},
|
||||
ongoing: {
|
||||
bg: 'bg-blue-50 dark:bg-blue-900/20',
|
||||
border: 'border-blue-200 dark:border-blue-800',
|
||||
dot: 'bg-blue-500',
|
||||
tag: 'blue',
|
||||
},
|
||||
default: {
|
||||
bg: 'bg-gray-50 dark:bg-gray-800/50',
|
||||
border: 'border-gray-200 dark:border-gray-700',
|
||||
dot: 'bg-brand',
|
||||
tag: 'violet',
|
||||
},
|
||||
};
|
||||
return configs[type] || configs.default;
|
||||
};
|
||||
|
||||
const renderAnnouncementTimeline = () => {
|
||||
if (processedAnnouncements.length === 0) {
|
||||
return (
|
||||
<div className='py-16 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-24 h-24 bg-gradient-to-br from-emerald-50 to-teal-50 dark:from-emerald-900/30 dark:to-teal-900/30 rounded-3xl flex items-center justify-center shadow-inner'>
|
||||
<Megaphone
|
||||
size={40}
|
||||
className='text-emerald-300 dark:text-emerald-600'
|
||||
/>
|
||||
</div>
|
||||
<div className='absolute -bottom-1 -right-1 w-8 h-8 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-xl flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={16} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<span className='mt-5 text-gray-700 dark:text-gray-300 text-lg font-semibold'>
|
||||
{t('暂无系统公告')}
|
||||
</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 text-sm mt-1'>
|
||||
{t('一切正常运行中')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='max-h-[50vh] overflow-y-auto pr-2 custom-scrollbar space-y-3'>
|
||||
{processedAnnouncements.map((item, idx) => {
|
||||
const htmlContent = marked.parse(item.content || '');
|
||||
const htmlExtra = item.extra ? marked.parse(item.extra) : '';
|
||||
const typeConfig = getTypeConfig(item.type);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className={`group relative rounded-xl border ${typeConfig.bg} ${typeConfig.border} p-4 transition-all duration-200 hover:shadow-md ${item.isUnread ? 'ring-1 ring-brand/30 ring-offset-1 ring-offset-white dark:ring-offset-gray-900' : ''}`}
|
||||
>
|
||||
{/* 未读标记 */}
|
||||
{item.isUnread && (
|
||||
<div className='absolute -top-1.5 -right-1.5'>
|
||||
<span className='relative flex h-4 w-4'>
|
||||
<span className='animate-ping absolute inline-flex h-full w-full rounded-full bg-brand-from opacity-60'></span>
|
||||
<span className='relative inline-flex rounded-full h-4 w-4 bg-gradient-to-r from-brand-from to-brand-to items-center justify-center'>
|
||||
<span className='text-[8px] text-white font-bold'>N</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 时间和类型标签 */}
|
||||
<div className='flex items-center justify-between mb-2.5'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div
|
||||
className={`w-2 h-2 rounded-full ${typeConfig.dot} flex-shrink-0`}
|
||||
/>
|
||||
<div className='flex items-center gap-1.5 text-xs'>
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{item.relative}
|
||||
</span>
|
||||
<span className='text-gray-300 dark:text-gray-600'>·</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 flex items-center gap-1'>
|
||||
<CalendarClock size={10} />
|
||||
{item.time}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{item.isUnread && (
|
||||
<span className='px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider rounded-md bg-brand/10 dark:bg-brand/20 text-brand-deep dark:text-brand-from'>
|
||||
NEW
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 公告内容 */}
|
||||
<div
|
||||
className='prose prose-sm dark:prose-invert max-w-none
|
||||
prose-p:text-gray-600 dark:prose-p:text-gray-300 prose-p:my-1 prose-p:leading-relaxed
|
||||
prose-a:text-brand-deep dark:prose-a:text-brand-from prose-a:font-medium prose-a:no-underline hover:prose-a:underline
|
||||
prose-strong:text-gray-800 dark:prose-strong:text-gray-100
|
||||
prose-code:bg-gray-100 dark:prose-code:bg-gray-800 prose-code:text-gray-700 dark:prose-code:text-gray-300 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-xs'
|
||||
dangerouslySetInnerHTML={{ __html: htmlContent }}
|
||||
/>
|
||||
|
||||
{/* 额外信息 */}
|
||||
{item.extra && (
|
||||
<div
|
||||
className='mt-2.5 pt-2.5 border-t border-gray-200/60 dark:border-gray-700/40 text-xs text-gray-500 dark:text-gray-400'
|
||||
dangerouslySetInnerHTML={{ __html: htmlExtra }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
const unreadCount = processedAnnouncements.filter(
|
||||
(item) => item.isUnread,
|
||||
).length;
|
||||
const typeColors = {
|
||||
success: 'success',
|
||||
warning: 'warning',
|
||||
error: 'error',
|
||||
ongoing: 'processing',
|
||||
default: 'default',
|
||||
};
|
||||
|
||||
const renderBody = () => {
|
||||
if (activeTab === 'inApp') {
|
||||
return renderMarkdownNotice();
|
||||
if (loading) {
|
||||
return (
|
||||
<div className='nm-empty'>
|
||||
<Spin tip={t('加载中...')}>
|
||||
<div className='nm-spin-placeholder' />
|
||||
</Spin>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!noticeContent) {
|
||||
return <div className='nm-empty'>{t('暂无公告')}</div>;
|
||||
}
|
||||
return (
|
||||
<div className='nm-notice-scroll' tabIndex={0} aria-label={t('通知')}>
|
||||
<div
|
||||
className='nm-markdown'
|
||||
dangerouslySetInnerHTML={{ __html: noticeContent }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return renderAnnouncementTimeline();
|
||||
if (processedAnnouncements.length === 0) {
|
||||
return <div className='nm-empty'>{t('暂无系统公告')}</div>;
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className='nm-announcement-scroll'
|
||||
tabIndex={0}
|
||||
aria-label={t('系统公告')}
|
||||
>
|
||||
{processedAnnouncements.map((item, idx) => (
|
||||
<Card key={idx} size='small'>
|
||||
<div className='nm-announcement-meta'>
|
||||
<span>
|
||||
<Badge status={typeColors[item.type] || 'default'} />{' '}
|
||||
{item.relative} · {item.time}
|
||||
</span>
|
||||
{item.isUnread && (
|
||||
<Tag color={typeColors[item.type] || 'default'}>NEW</Tag>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className='nm-markdown'
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked.parse(item.content || ''),
|
||||
}}
|
||||
/>
|
||||
{item.extra && (
|
||||
<div
|
||||
className='nm-announcement-extra nm-markdown'
|
||||
dangerouslySetInnerHTML={{ __html: marked.parse(item.extra) }}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={null}
|
||||
visible={visible}
|
||||
title={t('系统公告')}
|
||||
open={visible}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
closable={false}
|
||||
size={isMobile ? 'full-width' : 'large'}
|
||||
className='notice-modal-enhanced'
|
||||
bodyStyle={{ padding: 0 }}
|
||||
width={isMobile ? 'calc(100% - 32px)' : 860}
|
||||
className='notice-modal'
|
||||
rootClassName='notice-modal-root'
|
||||
styles={{
|
||||
mask: {
|
||||
background: `color-mix(in srgb, ${token.colorBgMask} 70%, transparent)`,
|
||||
},
|
||||
}}
|
||||
style={{
|
||||
'--nm-surface': token.colorBgContainer,
|
||||
'--nm-text': token.colorText,
|
||||
'--nm-muted': token.colorTextSecondary,
|
||||
'--nm-border': token.colorBorderSecondary,
|
||||
'--nm-fill': token.colorFillQuaternary,
|
||||
'--nm-tab-bg': token.colorBgLayout,
|
||||
'--nm-primary': token.colorPrimary,
|
||||
}}
|
||||
maskClosable={true}
|
||||
>
|
||||
<div className='relative overflow-hidden'>
|
||||
{/* 背景装饰 */}
|
||||
<div className='absolute inset-0 pointer-events-none overflow-hidden'>
|
||||
<div className='absolute -top-24 -right-24 w-48 h-48 bg-gradient-to-br from-brand-from/[0.08] to-brand-to/[0.08] dark:from-brand-from/15 dark:to-brand-to/15 rounded-full blur-3xl' />
|
||||
<div className='absolute -bottom-24 -left-24 w-48 h-48 bg-gradient-to-br from-pink-500/[0.08] to-rose-500/[0.08] dark:from-pink-500/15 dark:to-rose-500/15 rounded-full blur-3xl' />
|
||||
</div>
|
||||
|
||||
{/* 头部区域 */}
|
||||
<div className='relative px-6 pt-6 pb-4'>
|
||||
{/* 关闭按钮 */}
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='absolute top-4 right-4 p-2 rounded-full bg-gray-100/80 dark:bg-gray-700/80 hover:bg-gray-200 dark:hover:bg-gray-600 transition-all duration-200 z-10 backdrop-blur-sm hover:scale-105 active:scale-95'
|
||||
aria-label='Close'
|
||||
footer={
|
||||
<div className='nm-footer'>
|
||||
<Checkbox
|
||||
checked={dismissToday}
|
||||
onChange={(event) => setDismissToday(event.target.checked)}
|
||||
>
|
||||
<X size={16} className='text-gray-500 dark:text-gray-400' />
|
||||
</button>
|
||||
|
||||
{/* 标题 */}
|
||||
<div className='flex items-center gap-3 mb-5'>
|
||||
<div className='relative'>
|
||||
<div className='p-2.5 bg-gradient-to-br from-brand-from to-brand-to rounded-xl shadow-lg shadow-brand/20 dark:shadow-brand/30'>
|
||||
<Volume2 size={22} className='text-white' />
|
||||
</div>
|
||||
<div className='absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-500 rounded-full animate-pulse ring-2 ring-white dark:ring-gray-900' />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className='text-lg font-bold text-gray-900 dark:text-gray-50 flex items-center gap-2'>
|
||||
{t('今日不再提示')}
|
||||
</Checkbox>
|
||||
<Button
|
||||
type='primary'
|
||||
onClick={dismissToday ? handleCloseTodayNotice : onClose}
|
||||
>
|
||||
{t('我知道了')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Segmented
|
||||
block
|
||||
value={activeTab}
|
||||
onChange={setActiveTab}
|
||||
options={[
|
||||
{
|
||||
value: 'inApp',
|
||||
label: t('通知'),
|
||||
icon: <Bell size={14} strokeWidth={1.5} aria-hidden />,
|
||||
},
|
||||
{
|
||||
value: 'system',
|
||||
label: (
|
||||
<span className='nm-system-label'>
|
||||
{t('系统公告')}
|
||||
<Sparkles size={14} className='text-amber-500' />
|
||||
</h2>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-0.5'>
|
||||
{t('了解最新动态和通知')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tab 切换器 */}
|
||||
<div className='flex gap-1.5 p-1 bg-gray-100/80 dark:bg-gray-800/80 rounded-xl backdrop-blur-sm'>
|
||||
<button
|
||||
onClick={() => setActiveTab('inApp')}
|
||||
className={`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${
|
||||
activeTab === 'inApp'
|
||||
? 'bg-white dark:bg-gray-700 text-brand-deep dark:text-brand-from shadow-sm ring-1 ring-black/5 dark:ring-white/10'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-white/50 dark:hover:bg-gray-700/50'
|
||||
}`}
|
||||
>
|
||||
<Bell size={15} />
|
||||
{t('通知')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('system')}
|
||||
className={`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${
|
||||
activeTab === 'system'
|
||||
? 'bg-white dark:bg-gray-700 text-brand-deep dark:text-brand-from shadow-sm ring-1 ring-black/5 dark:ring-white/10'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-white/50 dark:hover:bg-gray-700/50'
|
||||
}`}
|
||||
>
|
||||
<Megaphone size={15} />
|
||||
{t('系统公告')}
|
||||
{processedAnnouncements.filter((a) => a.isUnread).length > 0 && (
|
||||
<span className='px-1.5 py-0.5 text-[10px] font-semibold bg-rose-500 text-white rounded-full min-w-[18px] text-center leading-tight'>
|
||||
{processedAnnouncements.filter((a) => a.isUnread).length}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区域 */}
|
||||
<div className='relative px-6 pb-2'>{renderBody()}</div>
|
||||
|
||||
{/* 底部按钮区域 */}
|
||||
<div className='relative px-6 py-4 border-t border-gray-200/60 dark:border-gray-700/60'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<button
|
||||
onClick={handleCloseTodayNotice}
|
||||
className='flex items-center gap-1.5 px-3 py-2 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-colors rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800'
|
||||
>
|
||||
<Clock size={13} />
|
||||
{t('今日不再提示')}
|
||||
</button>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='flex items-center gap-1.5 px-5 py-2 bg-gradient-to-r from-brand-from to-brand-to hover:from-brand-from hover:to-brand-to text-white text-sm font-medium rounded-xl shadow-md shadow-brand/20 dark:shadow-brand/30 transition-all duration-200 hover:shadow-lg hover:shadow-brand/25 hover:-translate-y-0.5 active:translate-y-0'
|
||||
>
|
||||
{t('我知道了')}
|
||||
<ChevronRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Badge count={unreadCount} size='small' />
|
||||
</span>
|
||||
),
|
||||
icon: <Volume1 size={14} strokeWidth={1.5} aria-hidden />,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<div className='nm-body'>{renderBody()}</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user