Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
const FooterBar = () => {
|
||||
// 全局隐藏页脚
|
||||
return null;
|
||||
};
|
||||
|
||||
export default FooterBar;
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useContext, useMemo, useRef, useState, useEffect } from 'react';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { Megaphone } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const Marquee = () => {
|
||||
const { t } = useTranslation();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const marqueeContent = statusState?.status?.marquee_content || '';
|
||||
const containerRef = useRef(null);
|
||||
const measureRef = useRef(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [scrollConfig, setScrollConfig] = useState({
|
||||
padding: 0,
|
||||
duration: 20,
|
||||
});
|
||||
|
||||
// 将 | 分隔的多条公告拼接成一条,用分隔符分开
|
||||
const displayText = useMemo(() => {
|
||||
if (!marqueeContent.trim()) return '';
|
||||
const items = marqueeContent
|
||||
.split('|')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
if (items.length === 0) return '';
|
||||
// 每条公告之间添加装饰分隔符
|
||||
return items.join(' ✦ ');
|
||||
}, [marqueeContent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!displayText) {
|
||||
setReady(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const update = () => {
|
||||
const container = containerRef.current;
|
||||
const measureEl = measureRef.current;
|
||||
if (!container || !measureEl) return;
|
||||
|
||||
const containerWidth = container.offsetWidth;
|
||||
const textWidth = measureEl.offsetWidth;
|
||||
|
||||
// 每份文本后留出容器宽度的间距
|
||||
// 这样文本1从左边消失时,文本2刚好从右边进入
|
||||
// 总 "单元" 宽度 = textWidth + containerWidth
|
||||
// translateX(-50%) 正好移动一个单元,形成无缝循环
|
||||
const scrollDistance = textWidth + containerWidth;
|
||||
const speed = 50; // 像素/秒
|
||||
const duration = Math.max(scrollDistance / speed, 5);
|
||||
|
||||
setScrollConfig({ padding: containerWidth, duration });
|
||||
setReady(true);
|
||||
};
|
||||
|
||||
// 等待下一帧让测量元素渲染完成
|
||||
const raf = requestAnimationFrame(update);
|
||||
window.addEventListener('resize', update);
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
window.removeEventListener('resize', update);
|
||||
};
|
||||
}, [displayText]);
|
||||
|
||||
if (!displayText) return null;
|
||||
|
||||
return (
|
||||
<div className='marquee-bar relative w-full overflow-hidden z-[99]'>
|
||||
{/* 顶部发光线 */}
|
||||
<div className='absolute top-0 left-0 right-0 h-[1px] bg-gradient-to-r from-transparent via-white/50 to-transparent dark:via-white/20' />
|
||||
|
||||
<div className='flex items-center h-10 px-5'>
|
||||
{/* 左侧图标 - 固定不动 */}
|
||||
<div className='flex-shrink-0 flex items-center gap-2 mr-4 z-10'>
|
||||
<div
|
||||
className='flex items-center justify-center w-6 h-6 rounded-full bg-white/20 dark:bg-white/10 backdrop-blur-sm'
|
||||
style={{ boxShadow: '0 0 8px rgba(255,255,255,0.2)' }}
|
||||
>
|
||||
<Megaphone size={13} className='text-white drop-shadow-sm' />
|
||||
</div>
|
||||
<span className='text-[13px] font-semibold text-white hidden sm:inline tracking-wider drop-shadow-sm'>
|
||||
{t('公告')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 跑马灯滚动区域 */}
|
||||
<div ref={containerRef} className='flex-1 overflow-hidden relative'>
|
||||
{/* 隐藏的测量元素 - 用于获取文本自然宽度,不受动态 padding 影响 */}
|
||||
<span
|
||||
ref={measureRef}
|
||||
className='invisible absolute whitespace-nowrap text-[14px] font-medium tracking-wide'
|
||||
style={{ top: -9999, left: -9999 }}
|
||||
aria-hidden='true'
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
|
||||
{/* 左侧渐变遮罩 */}
|
||||
<div className='marquee-mask-left absolute left-0 top-0 bottom-0 w-10 z-10' />
|
||||
{/* 右侧渐变遮罩 */}
|
||||
<div className='marquee-mask-right absolute right-0 top-0 bottom-0 w-10 z-10' />
|
||||
|
||||
{ready && (
|
||||
<div
|
||||
className='marquee-scroll inline-flex whitespace-nowrap'
|
||||
style={{ animationDuration: `${scrollConfig.duration}s` }}
|
||||
>
|
||||
<span
|
||||
className='marquee-text inline-block shrink-0 text-[14px] text-white/95 dark:text-white/90 font-medium tracking-wide'
|
||||
style={{ paddingRight: scrollConfig.padding }}
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
<span
|
||||
className='marquee-text inline-block shrink-0 text-[14px] text-white/95 dark:text-white/90 font-medium tracking-wide'
|
||||
style={{ paddingRight: scrollConfig.padding }}
|
||||
aria-hidden='true'
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部发光线 */}
|
||||
<div className='absolute bottom-0 left-0 right-0 h-[1px] bg-gradient-to-r from-transparent via-white/25 to-transparent dark:via-white/10' />
|
||||
|
||||
<style>{`
|
||||
/* 亮色模式 - 跟随主题色的 5 段渐变 */
|
||||
.marquee-bar {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--brand-primary-hover) 0%,
|
||||
var(--brand-gradient-via) 25%,
|
||||
var(--brand-gradient-to) 50%,
|
||||
var(--brand-primary) 75%,
|
||||
var(--brand-primary-hover) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: marquee-bg-shift 8s ease-in-out infinite;
|
||||
box-shadow:
|
||||
0 2px 8px color-mix(in srgb, var(--brand-primary) 30%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.marquee-mask-left {
|
||||
background: linear-gradient(to right, var(--brand-primary-hover), transparent);
|
||||
}
|
||||
|
||||
.marquee-mask-right {
|
||||
background: linear-gradient(to left, var(--brand-primary), transparent);
|
||||
}
|
||||
|
||||
/* 深色模式 - 同色调但与黑色混合更沉稳 */
|
||||
html.dark .marquee-bar {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-via) 35%, #000) 25%,
|
||||
color-mix(in srgb, var(--brand-primary) 40%, #000) 50%,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 75%,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
box-shadow:
|
||||
0 2px 12px color-mix(in srgb, var(--brand-primary) 30%, #000),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
html.dark .marquee-mask-left {
|
||||
background: linear-gradient(to right, color-mix(in srgb, var(--brand-primary) 35%, #000), transparent);
|
||||
}
|
||||
|
||||
html.dark .marquee-mask-right {
|
||||
background: linear-gradient(to left, color-mix(in srgb, var(--brand-primary) 35%, #000), transparent);
|
||||
}
|
||||
|
||||
@keyframes marquee-bg-shift {
|
||||
0%, 100% { background-position: 0% 0; }
|
||||
50% { background-position: 100% 0; }
|
||||
}
|
||||
|
||||
@keyframes marquee-scroll-anim {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
}
|
||||
|
||||
.marquee-scroll {
|
||||
animation: marquee-scroll-anim 20s linear infinite;
|
||||
}
|
||||
|
||||
.marquee-scroll:hover {
|
||||
animation-play-state: paused;
|
||||
}
|
||||
|
||||
.marquee-text {
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), 0 0 12px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
html.dark .marquee-text {
|
||||
text-shadow:
|
||||
0 1px 3px rgba(0, 0, 0, 0.4),
|
||||
0 0 8px color-mix(in srgb, var(--brand-gradient-to) 15%, transparent);
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Marquee;
|
||||
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useContext, useMemo } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
} from '@douyinfe/semi-ui';
|
||||
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';
|
||||
|
||||
const NoticeModal = ({
|
||||
visible,
|
||||
onClose,
|
||||
isMobile,
|
||||
defaultTab = 'inApp',
|
||||
unreadKeys = [],
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [noticeContent, setNoticeContent] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState(defaultTab);
|
||||
|
||||
const [statusState] = useContext(StatusContext);
|
||||
|
||||
const announcements = statusState?.status?.announcements || [];
|
||||
|
||||
const unreadSet = useMemo(() => new Set(unreadKeys), [unreadKeys]);
|
||||
|
||||
const getKeyForItem = (item) =>
|
||||
`${item?.publishDate || ''}-${(item?.content || '').slice(0, 30)}`;
|
||||
|
||||
const processedAnnouncements = useMemo(() => {
|
||||
return (announcements || []).slice(0, 20).map((item) => {
|
||||
const pubDate = item?.publishDate ? new Date(item.publishDate) : null;
|
||||
const absoluteTime =
|
||||
pubDate && !isNaN(pubDate.getTime())
|
||||
? `${pubDate.getFullYear()}-${String(pubDate.getMonth() + 1).padStart(2, '0')}-${String(pubDate.getDate()).padStart(2, '0')} ${String(pubDate.getHours()).padStart(2, '0')}:${String(pubDate.getMinutes()).padStart(2, '0')}`
|
||||
: item?.publishDate || '';
|
||||
return {
|
||||
key: getKeyForItem(item),
|
||||
type: item.type || 'default',
|
||||
time: absoluteTime,
|
||||
content: item.content,
|
||||
extra: item.extra,
|
||||
relative: getRelativeTime(item.publishDate),
|
||||
isUnread: unreadSet.has(getKeyForItem(item)),
|
||||
};
|
||||
});
|
||||
}, [announcements, unreadSet]);
|
||||
|
||||
const handleCloseTodayNotice = () => {
|
||||
const today = new Date().toDateString();
|
||||
localStorage.setItem('notice_close_date', today);
|
||||
onClose();
|
||||
};
|
||||
|
||||
const displayNotice = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/notice');
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (data !== '') {
|
||||
const htmlNotice = marked.parse(data);
|
||||
setNoticeContent(htmlNotice);
|
||||
} else {
|
||||
setNoticeContent('');
|
||||
}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
displayNotice();
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setActiveTab(defaultTab);
|
||||
}
|
||||
}, [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 renderBody = () => {
|
||||
if (activeTab === 'inApp') {
|
||||
return renderMarkdownNotice();
|
||||
}
|
||||
return renderAnnouncementTimeline();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={null}
|
||||
visible={visible}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
closable={false}
|
||||
size={isMobile ? 'full-width' : 'large'}
|
||||
className='notice-modal-enhanced'
|
||||
bodyStyle={{ padding: 0 }}
|
||||
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'
|
||||
>
|
||||
<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('系统公告')}
|
||||
<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>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default NoticeModal;
|
||||
@@ -0,0 +1,482 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import HeaderBar from './headerbar';
|
||||
import { Layout } from '@douyinfe/semi-ui';
|
||||
import SiderBar from './SiderBar';
|
||||
import App from '../../App';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import React, {
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
lazy,
|
||||
Suspense,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
API,
|
||||
clearUserData,
|
||||
getUserData,
|
||||
getLogo,
|
||||
getSystemName,
|
||||
isAuthPagePath,
|
||||
showError,
|
||||
setStatusData,
|
||||
setUserData,
|
||||
} from '../../helpers';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { applyTheme, setPresetOverrides } from '../../helpers/theme';
|
||||
// 用户问卷功能已禁用
|
||||
// import UserSurveyModal from '../common/modals/UserSurveyModal';
|
||||
import NewUserGiftModal from '../common/modals/NewUserGiftModal';
|
||||
|
||||
// 懒加载客服浮窗组件 - 非核心功能,延迟加载
|
||||
const CustomerServiceFloat = lazy(() => import('../customer-service'));
|
||||
|
||||
// 跑马灯公告组件
|
||||
import Marquee from './Marquee';
|
||||
|
||||
const { Sider, Content, Header } = Layout;
|
||||
|
||||
// 控制台欢迎语只打印一次(loadStatus 可能被多次触发)
|
||||
let consoleWelcomePrinted = false;
|
||||
const printConsoleWelcome = (status) => {
|
||||
if (consoleWelcomePrinted) return;
|
||||
consoleWelcomePrinted = true;
|
||||
const title = (status?.console_welcome_title || '').trim();
|
||||
const link = (status?.official_website || '').trim();
|
||||
if (!title && !link) return;
|
||||
console.log(
|
||||
`%c${title}%c${link ? ` 官网: ${link}` : ''}`,
|
||||
'color: #10b981; font-weight: bold; font-size: 24px;',
|
||||
'color: inherit; font-size: 14px;',
|
||||
);
|
||||
};
|
||||
|
||||
const PageLayout = () => {
|
||||
console.log('[PageLayout] Component rendering...');
|
||||
const [userState, userDispatch] = useContext(UserContext);
|
||||
const [statusState, statusDispatch] = useContext(StatusContext);
|
||||
const isMobile = useIsMobile();
|
||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||
const { i18n } = useTranslation();
|
||||
const location = useLocation();
|
||||
|
||||
// 用户问卷弹窗状态 - 功能已禁用
|
||||
// const [showSurveyModal, setShowSurveyModal] = useState(false);
|
||||
// const surveyCheckedRef = useRef(false);
|
||||
|
||||
// 新用户注册赠送额度弹窗
|
||||
const [showGiftModal, setShowGiftModal] = useState(false);
|
||||
const [giftQuota, setGiftQuota] = useState(0);
|
||||
|
||||
const shouldInnerPadding =
|
||||
location.pathname.includes('/console') &&
|
||||
!location.pathname.startsWith('/console/chat') &&
|
||||
location.pathname !== '/console/playground';
|
||||
|
||||
const isConsoleRoute = location.pathname.startsWith('/console');
|
||||
const showSider = isConsoleRoute && (!isMobile || drawerOpen);
|
||||
const isHomePage = location.pathname === '/';
|
||||
|
||||
// 隐私政策和用户协议页面需要隐藏顶部工具栏
|
||||
const isLegalPage =
|
||||
location.pathname === '/user-agreement' ||
|
||||
location.pathname === '/privacy-policy';
|
||||
const hideHeader = isHomePage || isLegalPage;
|
||||
|
||||
// 这些页面有自己的滚动控制,不需要外部滚动
|
||||
const isExperienceCenter = location.pathname.includes('/experience-center');
|
||||
const isUserCenter = location.pathname.includes('/user-center');
|
||||
|
||||
// 认证页(登录/注册/企业登录等):内容垂直居中的独立屏
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
|
||||
// 企业管理页面有自己的布局和滚动控制。
|
||||
// 注意排除 /org/login、/org/register、/org/:slug/login 等认证页——
|
||||
// 它们没有内部滚动容器,若被禁用外层滚动,内容超出视口(如企业注册开启邮箱验证时)会被截断且无法滚动。
|
||||
const isOrgPage =
|
||||
location.pathname.startsWith('/org') &&
|
||||
location.pathname !== '/org/create' &&
|
||||
!isAuthPage;
|
||||
|
||||
// 需要禁用外层滚动的页面(这些页面内部有自己的滚动容器)
|
||||
const disableOuterScroll =
|
||||
isExperienceCenter || isUserCenter || isHomePage || isOrgPage;
|
||||
|
||||
// 需要显示可见滚动条的页面(覆盖 semi-layout 默认隐藏滚动条的行为)。
|
||||
// 认证页也纳入:内容确实超出视口时(小屏/长表单)用主题色滚动条明示,而不是隐形滚动导致卡片"莫名移动"。
|
||||
const isKeyManagement = location.pathname === '/key-management';
|
||||
const showVisibleScrollbar = isKeyManagement || isAuthPage;
|
||||
|
||||
// 跑马灯公告是否存在(用于动态计算头部总高度)。
|
||||
// 认证页(登录/注册/企业登录/企业注册)不展示:用户尚未进入平台,公告是面向平台内用户的信息。
|
||||
const hasMarquee =
|
||||
!hideHeader &&
|
||||
!isAuthPage &&
|
||||
!!statusState?.status?.marquee_content?.trim();
|
||||
const marqueeHeight = hasMarquee ? 40 : 0; // h-10 = 40px
|
||||
const headerBarHeight = isMobile ? 56 : 64; // h-14(56px) on mobile, h-16(64px) on desktop
|
||||
const totalHeaderHeight = headerBarHeight + marqueeHeight;
|
||||
|
||||
// 滚动容器引用
|
||||
const scrollContainerRef = useRef(null);
|
||||
const authBootstrappedRef = useRef(false);
|
||||
|
||||
// 路由切换兜底:
|
||||
// (1) 清除 Semi Modal/SideSheet 在并发开关/异常 unmount 时残留的 body 锁。
|
||||
// Semi 的 enabledBodyScroll 有 `bodyOverflow !== 'hidden'` 保护,多 modal 并发或
|
||||
// visible=true 时被强制卸载,会跳过还原,表现为"滚动条可见但滚不动,刷新才好"。
|
||||
// (2) 重置外层滚动位置(注:scrollContainerRef 当前挂在 Semi Layout 上无法直接拿到 DOM,
|
||||
// scrollTop 赋值是 no-op;保留是为了未来把 ref 换成原生 div 后能立即生效)。
|
||||
useEffect(() => {
|
||||
document.body.style.overflow = '';
|
||||
document.body.style.width = '';
|
||||
// 抽屉态必须跟着路由清掉:它此前只由 SiderBar 的 onNavigate 复位,
|
||||
// 用户从顶栏导航离开控制台时会残留 true,回到 /console 就自动带着遮罩打开,
|
||||
// 整页发暗且看不出原因(遮罩上线前这个残留是不可见的)。
|
||||
setDrawerOpen(false);
|
||||
if (scrollContainerRef.current) {
|
||||
scrollContainerRef.current.scrollTop = 0;
|
||||
}
|
||||
}, [location.pathname]);
|
||||
|
||||
// 跨断点同理:桌面态残留的 drawerOpen 会在缩窄到手机时凭空展开一个带遮罩的抽屉
|
||||
useEffect(() => {
|
||||
setDrawerOpen(false);
|
||||
}, [isMobile]);
|
||||
|
||||
// 手机抽屉恒定展开:不再用 setCollapsed(false) 改写持久化偏好——
|
||||
// 那会让用户在桌面端收起过的侧栏,因为在手机上开过一次抽屉就被重置。
|
||||
// 改为把 forceExpanded 透传给 SiderBar,只影响这一次渲染。
|
||||
const siderForceExpanded = isMobile && drawerOpen;
|
||||
|
||||
// 顶栏总高(顶栏 + 跑马灯)发布成全局 CSS 变量。
|
||||
// 顶栏是 position:fixed,内容区从视口 0 开始流动,任何 `sticky top-0` 的页内元素
|
||||
// 都会吸到顶栏底下被盖住。页面无从得知跑马灯开没开,只能由这里统一给出。
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--app-header-height', `${totalHeaderHeight}px`);
|
||||
}, [totalHeaderHeight]);
|
||||
|
||||
// 抽屉支持 Esc 关闭:遮罩是 aria-hidden 的纯点击区,键盘用户否则只能回到汉堡按钮
|
||||
useEffect(() => {
|
||||
if (!siderForceExpanded) return;
|
||||
const onKeyDown = (e) => {
|
||||
if (e.key === 'Escape') setDrawerOpen(false);
|
||||
};
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
return () => document.removeEventListener('keydown', onKeyDown);
|
||||
}, [siderForceExpanded]);
|
||||
|
||||
const loadUser = async () => {
|
||||
const cachedUser = getUserData();
|
||||
if (!cachedUser) {
|
||||
userDispatch({ type: 'auth_checked' });
|
||||
return;
|
||||
}
|
||||
|
||||
userDispatch({ type: 'auth_start' });
|
||||
try {
|
||||
const res = await API.get('/api/user/self', {
|
||||
skipErrorHandler: true,
|
||||
disableDuplicate: true,
|
||||
});
|
||||
const { success, data } = res.data;
|
||||
if (success && data) {
|
||||
setUserData(data);
|
||||
userDispatch({ type: 'login', payload: data });
|
||||
} else {
|
||||
clearUserData();
|
||||
userDispatch({ type: 'logout' });
|
||||
}
|
||||
} catch (error) {
|
||||
if (error?.response?.status === 401 || error?.response?.status === 403) {
|
||||
clearUserData();
|
||||
userDispatch({ type: 'logout' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 网络临时异常时保留本地展示态,后续接口仍会按真实 session 鉴权。
|
||||
userDispatch({ type: 'login', payload: cachedUser });
|
||||
}
|
||||
};
|
||||
|
||||
const loadStatus = async () => {
|
||||
console.log('[PageLayout] Loading status from API...');
|
||||
try {
|
||||
const res = await API.get('/api/status');
|
||||
console.log('[PageLayout] API response received:', res.data);
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
statusDispatch({ type: 'set', payload: data });
|
||||
setStatusData(data);
|
||||
printConsoleWelcome(data);
|
||||
// 先同步预设覆盖(管理员编辑过的预设模板),再应用主题
|
||||
if (data.theme_presets !== undefined) {
|
||||
setPresetOverrides(data.theme_presets);
|
||||
}
|
||||
// 用服务器最新主题配置覆盖 cache 注入的版本
|
||||
if (data.theme_config !== undefined) {
|
||||
applyTheme(data.theme_config);
|
||||
}
|
||||
console.log('[PageLayout] Status loaded successfully');
|
||||
} else {
|
||||
console.error('[PageLayout] API returned success=false');
|
||||
showError('Unable to connect to server');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[PageLayout] Failed to load status:', error);
|
||||
showError('Failed to load status');
|
||||
throw error; // 重新抛出以便上层catch
|
||||
}
|
||||
};
|
||||
|
||||
// 检查用户是否需要填写问卷 - 功能已禁用
|
||||
// const checkUserSurvey = useCallback(async () => {
|
||||
// // 已经检查过且已完成,不再检查
|
||||
// if (surveyCheckedRef.current === 'completed') return;
|
||||
//
|
||||
// try {
|
||||
// const res = await API.get('/api/user/survey/check');
|
||||
// const { success, data } = res.data;
|
||||
// if (success) {
|
||||
// if (data && !data.survey_completed) {
|
||||
// setShowSurveyModal(true);
|
||||
// surveyCheckedRef.current = 'pending'; // 等待用户填写
|
||||
// } else {
|
||||
// surveyCheckedRef.current = 'completed'; // 已完成,不再检查
|
||||
// }
|
||||
// }
|
||||
// // 如果请求失败(success=false),不设置状态,下次还会重试
|
||||
// } catch (error) {
|
||||
// console.error('Check survey failed:', error);
|
||||
// // 网络错误时不设置状态,下次还会重试
|
||||
// }
|
||||
// }, []);
|
||||
|
||||
// 当用户登录状态变化时检查问卷 - 功能已禁用
|
||||
// useEffect(() => {
|
||||
// if (userState?.user?.id) {
|
||||
// checkUserSurvey();
|
||||
// } else {
|
||||
// // 用户登出时重置检查状态
|
||||
// surveyCheckedRef.current = null;
|
||||
// setShowSurveyModal(false);
|
||||
// }
|
||||
// }, [userState?.user?.id, checkUserSurvey]);
|
||||
|
||||
// 问卷提交成功后的回调 - 功能已禁用
|
||||
// const handleSurveySuccess = useCallback(() => {
|
||||
// surveyCheckedRef.current = 'completed';
|
||||
// setShowSurveyModal(false);
|
||||
// }, []);
|
||||
|
||||
// 新用户注册赠送额度弹窗:登录后检查是否是刚注册的用户
|
||||
useEffect(() => {
|
||||
const userId = userState?.user?.id;
|
||||
const username = userState?.user?.username;
|
||||
if (!userId || !username) return;
|
||||
|
||||
const pendingUser = localStorage.getItem('new_user_gift_pending');
|
||||
if (pendingUser === username) {
|
||||
localStorage.removeItem('new_user_gift_pending');
|
||||
const quota = userState?.user?.quota || 0;
|
||||
if (quota > 0) {
|
||||
setGiftQuota(quota);
|
||||
setShowGiftModal(true);
|
||||
}
|
||||
}
|
||||
}, [userState?.user?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authBootstrappedRef.current) {
|
||||
authBootstrappedRef.current = true;
|
||||
loadUser();
|
||||
}
|
||||
loadStatus().catch((error) => {
|
||||
console.error('Failed to load status:', error);
|
||||
// 即使加载失败也设置一个默认状态,避免卡住
|
||||
statusDispatch({ type: 'set', payload: { setup: true } });
|
||||
});
|
||||
let systemName = getSystemName();
|
||||
if (systemName) {
|
||||
document.title = systemName;
|
||||
}
|
||||
let logo = getLogo();
|
||||
if (logo) {
|
||||
let linkElement = document.querySelector("link[rel~='icon']");
|
||||
if (linkElement) {
|
||||
linkElement.href = logo;
|
||||
}
|
||||
}
|
||||
// 界面语言已由 i18n/bootstrap.js 在渲染前判定,这里不再读取语言缓存
|
||||
}, [i18n]);
|
||||
|
||||
return (
|
||||
<Layout
|
||||
style={{
|
||||
height: '100vh',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden', // 外层保持 hidden,滚动由内部 scrollContainerRef 控制
|
||||
}}
|
||||
>
|
||||
{!hideHeader && (
|
||||
<Header
|
||||
style={{
|
||||
padding: 0,
|
||||
height: 'auto',
|
||||
lineHeight: 'normal',
|
||||
position: 'fixed',
|
||||
width: '100%',
|
||||
top: 0,
|
||||
zIndex: 100,
|
||||
}}
|
||||
>
|
||||
<HeaderBar
|
||||
onMobileMenuToggle={() => setDrawerOpen((prev) => !prev)}
|
||||
drawerOpen={drawerOpen}
|
||||
/>
|
||||
{/* 跑马灯公告 - 固定在导航栏正下方;认证页不展示(与 hasMarquee 的高度计算保持一致) */}
|
||||
{!isAuthPage && <Marquee />}
|
||||
</Header>
|
||||
)}
|
||||
<Layout
|
||||
ref={scrollContainerRef}
|
||||
className={showVisibleScrollbar ? 'app-scrollbar' : undefined}
|
||||
style={{
|
||||
// 部分页面有自己的滚动控制,不需要外层滚动
|
||||
overflowY: disableOuterScroll ? 'hidden' : 'auto',
|
||||
overflowX: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flex: 1,
|
||||
WebkitOverflowScrolling: 'touch', // iOS 平滑滚动
|
||||
}}
|
||||
>
|
||||
{/* 手机抽屉遮罩:点击关闭。没有它时抽屉浮在内容上、只能再点汉堡才能收,
|
||||
且看不出「当前处于抽屉态」。层级压在 Sider(99) 之下、内容之上。 */}
|
||||
{showSider && isMobile && (
|
||||
<div
|
||||
className='fixed inset-x-0 bottom-0 z-[98] bg-black/45 backdrop-blur-[2px]'
|
||||
style={{ top: `${totalHeaderHeight}px` }}
|
||||
onClick={() => setDrawerOpen(false)}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
)}
|
||||
{showSider && (
|
||||
<Sider
|
||||
style={{
|
||||
position: 'fixed',
|
||||
left: 0,
|
||||
top: `${totalHeaderHeight}px`,
|
||||
zIndex: 99,
|
||||
border: 'none',
|
||||
paddingRight: '0',
|
||||
height: `calc(100vh - ${totalHeaderHeight}px)`,
|
||||
// 手机抽屉不跟随桌面的折叠宽度,否则用户在桌面收起过侧栏后,
|
||||
// 抽屉会变成 60px 纯图标窄条,等于看不到导航
|
||||
width: siderForceExpanded
|
||||
? 'var(--sidebar-width)'
|
||||
: 'var(--sidebar-current-width)',
|
||||
boxShadow: siderForceExpanded
|
||||
? '0 0 24px rgba(0,0,0,0.28)'
|
||||
: undefined,
|
||||
}}
|
||||
>
|
||||
<SiderBar
|
||||
forceExpanded={siderForceExpanded}
|
||||
onNavigate={() => {
|
||||
if (isMobile) setDrawerOpen(false);
|
||||
}}
|
||||
/>
|
||||
</Sider>
|
||||
)}
|
||||
<Layout
|
||||
style={{
|
||||
marginLeft: isMobile
|
||||
? '0'
|
||||
: showSider
|
||||
? 'var(--sidebar-current-width)'
|
||||
: '0',
|
||||
flex: '1 0 auto',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
minHeight: disableOuterScroll ? '100%' : 'auto', // 内部滚动的页面需要撑满高度
|
||||
}}
|
||||
>
|
||||
<Content
|
||||
style={{
|
||||
flex: '1 0 auto',
|
||||
WebkitOverflowScrolling: 'touch',
|
||||
padding: shouldInnerPadding
|
||||
? isMobile
|
||||
? '5px'
|
||||
: '24px 24px 0 24px'
|
||||
: '0',
|
||||
position: 'relative',
|
||||
// 认证页等 min-height:100vh 的独立屏用它抵扣上方跑马灯占位的高度,
|
||||
// 保证「占位 + 容器」总高恰为 100vh(无占位时回退 0px,不影响其他页面)
|
||||
'--content-top-offset': `${marqueeHeight}px`,
|
||||
}}
|
||||
>
|
||||
{/* 跑马灯占位:当跑马灯存在时,为内容区域顶部增加等高间距,防止被固定头部遮挡 */}
|
||||
{/* 注意:ExperienceCenter、UserCenter 和 Organization 使用 h-screen 并自行处理顶部偏移,不需要这个占位。
|
||||
认证页保留占位(防内容顶部被跑马灯遮挡且滚不出来),并通过 Content 上的
|
||||
--content-top-offset 变量让认证页容器等量收缩(calc(100vh - offset)),
|
||||
总高度恰为 100vh,不会出现"滚轮一动登录卡片就上下漂移"的幽灵滚动 */}
|
||||
{marqueeHeight > 0 &&
|
||||
!isExperienceCenter &&
|
||||
!isUserCenter &&
|
||||
!isOrgPage && (
|
||||
<div style={{ height: marqueeHeight, flexShrink: 0 }} />
|
||||
)}
|
||||
<App />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
<ToastContainer />
|
||||
<Suspense fallback={null}>
|
||||
<CustomerServiceFloat />
|
||||
</Suspense>
|
||||
|
||||
{/* 用户问卷弹窗 - 功能已禁用 */}
|
||||
{/* <UserSurveyModal
|
||||
visible={showSurveyModal}
|
||||
onClose={() => setShowSurveyModal(false)}
|
||||
onSuccess={handleSurveySuccess}
|
||||
/> */}
|
||||
|
||||
{/* 新用户注册赠送额度弹窗 */}
|
||||
<NewUserGiftModal
|
||||
visible={showGiftModal}
|
||||
onClose={() => setShowGiftModal(false)}
|
||||
quota={giftQuota}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageLayout;
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
|
||||
const SetupCheck = ({ children }) => {
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
statusState?.status?.setup === false &&
|
||||
location.pathname !== '/setup'
|
||||
) {
|
||||
window.location.href = '/setup';
|
||||
}
|
||||
}, [statusState?.status?.setup, location.pathname]);
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default SetupCheck;
|
||||
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getLucideIcon } from '../../helpers/render';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
|
||||
import { useSidebar } from '../../hooks/common/useSidebar';
|
||||
import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime';
|
||||
import { isAdmin, isRoot, showError } from '../../helpers';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import SkeletonWrapper from './components/SkeletonWrapper';
|
||||
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
|
||||
|
||||
import { Nav, Divider, Button } from '@douyinfe/semi-ui';
|
||||
|
||||
const routerMap = {
|
||||
home: '/',
|
||||
channel: '/console/channel',
|
||||
'admin-token': '/console/token',
|
||||
redemption: '/console/redemption',
|
||||
topup: '/console/topup',
|
||||
user: '/console/user',
|
||||
log: '/console/log',
|
||||
midjourney: '/console/midjourney',
|
||||
setting: '/console/setting',
|
||||
about: '/about',
|
||||
detail: '/console',
|
||||
pricing: '/market',
|
||||
task: '/console/task',
|
||||
models: '/console/models',
|
||||
playground: '/console/playground',
|
||||
personal: '/console/personal',
|
||||
monitor: '/console/monitor',
|
||||
analytics: '/console/analytics',
|
||||
commission: '/console/commission',
|
||||
'my-commission': '/console/my-commission',
|
||||
partner: '/console/partner',
|
||||
organizations: '/console/organizations',
|
||||
'skill-platform': '/console/skill-platform',
|
||||
'expert-platform': '/console/expert-platform',
|
||||
order: '/console/order',
|
||||
invoice: '/console/invoice',
|
||||
subscription: '/console/subscription',
|
||||
};
|
||||
|
||||
// forceExpanded:手机端抽屉态。抽屉本来就是临时全宽浮层,折叠成 60px 图标条毫无意义,
|
||||
// 且不应把桌面端的折叠偏好一起改掉,所以只在本次渲染里强制展开。
|
||||
const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||||
const { t } = useTranslation();
|
||||
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
|
||||
const collapsed = forceExpanded ? false : persistedCollapsed;
|
||||
const {
|
||||
isModuleVisible,
|
||||
hasSectionVisibleModules,
|
||||
loading: sidebarLoading,
|
||||
} = useSidebar();
|
||||
|
||||
const [statusState] = useContext(StatusContext);
|
||||
// 系统设置 tab 权限下放:普通管理员在被下放了至少一个 tab 时,才显示「系统设置」入口
|
||||
const delegatedSettingTabs = useMemo(() => {
|
||||
try {
|
||||
const raw = statusState?.status?.AdminDelegatedSettingTabs;
|
||||
const parsed = raw ? JSON.parse(raw) : [];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}, [statusState?.status?.AdminDelegatedSettingTabs]);
|
||||
const canAccessSetting =
|
||||
isRoot() || (isAdmin() && delegatedSettingTabs.length > 0);
|
||||
|
||||
const showSkeleton = useMinimumLoadingTime(sidebarLoading, 200);
|
||||
|
||||
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
||||
const [chatItems, setChatItems] = useState([]);
|
||||
const [openedKeys, setOpenedKeys] = useState([]);
|
||||
const location = useLocation();
|
||||
const [routerMapState, setRouterMapState] = useState(routerMap);
|
||||
|
||||
const workspaceItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('数据看板'),
|
||||
itemKey: 'detail',
|
||||
to: '/detail',
|
||||
className:
|
||||
localStorage.getItem('enable_data_export') === 'true'
|
||||
? ''
|
||||
: 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('令牌管理'),
|
||||
itemKey: 'token',
|
||||
to: '/token',
|
||||
},
|
||||
{
|
||||
text: t('使用日志'),
|
||||
itemKey: 'log',
|
||||
to: '/log',
|
||||
},
|
||||
{
|
||||
text: t('绘图日志'),
|
||||
itemKey: 'midjourney',
|
||||
to: '/midjourney',
|
||||
className:
|
||||
localStorage.getItem('enable_drawing') === 'true'
|
||||
? ''
|
||||
: 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('任务日志'),
|
||||
itemKey: 'task',
|
||||
to: '/task',
|
||||
className:
|
||||
localStorage.getItem('enable_task') === 'true' ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('监控中心'),
|
||||
itemKey: 'monitor',
|
||||
to: '/monitor',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('console', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [
|
||||
localStorage.getItem('enable_data_export'),
|
||||
localStorage.getItem('enable_drawing'),
|
||||
localStorage.getItem('enable_task'),
|
||||
t,
|
||||
isModuleVisible,
|
||||
]);
|
||||
|
||||
const financeItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('钱包管理'),
|
||||
itemKey: 'topup',
|
||||
to: '/topup',
|
||||
},
|
||||
{
|
||||
text: t('个人设置'),
|
||||
itemKey: 'personal',
|
||||
to: '/personal',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('personal', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
// 我的提成:新模块不在 sidebar 配置注册表内,直接追加(非销售用户页面为空态)
|
||||
filteredItems.push({
|
||||
text: t('我的提成'),
|
||||
itemKey: 'my-commission',
|
||||
to: '/console/my-commission',
|
||||
});
|
||||
|
||||
// 合作伙伴:受平台总开关控制(参数设置页可配),开放后对全部登录用户可见
|
||||
if (statusState?.status?.commission_partner_portal_enabled === true) {
|
||||
filteredItems.push({
|
||||
text: t('合作伙伴'),
|
||||
itemKey: 'partner',
|
||||
to: '/console/partner',
|
||||
});
|
||||
}
|
||||
|
||||
return filteredItems;
|
||||
}, [
|
||||
t,
|
||||
isModuleVisible,
|
||||
statusState?.status?.commission_partner_portal_enabled,
|
||||
]);
|
||||
|
||||
const adminItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('运营看板'),
|
||||
itemKey: 'analytics',
|
||||
to: '/console/analytics',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('分佣管理'),
|
||||
itemKey: 'commission',
|
||||
to: '/console/commission',
|
||||
className: isRoot() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('渠道管理'),
|
||||
itemKey: 'channel',
|
||||
to: '/channel',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('模型管理'),
|
||||
itemKey: 'models',
|
||||
to: '/console/models',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('兑换码管理'),
|
||||
itemKey: 'redemption',
|
||||
to: '/redemption',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('用户管理'),
|
||||
itemKey: 'user',
|
||||
to: '/user',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('会员卡管理'),
|
||||
itemKey: 'subscription',
|
||||
to: '/console/subscription',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('秘钥管理'),
|
||||
itemKey: 'admin-token',
|
||||
to: '/console/token',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('企业管理'),
|
||||
itemKey: 'organizations',
|
||||
to: '/console/organizations',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('平台 Skill 中心'),
|
||||
itemKey: 'skill-platform',
|
||||
to: '/console/skill-platform',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('平台专家中心'),
|
||||
itemKey: 'expert-platform',
|
||||
to: '/console/expert-platform',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('订单管理'),
|
||||
itemKey: 'order',
|
||||
to: '/console/order',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('发票管理'),
|
||||
itemKey: 'invoice',
|
||||
to: '/console/invoice',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('系统设置'),
|
||||
itemKey: 'setting',
|
||||
to: '/setting',
|
||||
className: canAccessSetting ? '' : 'tableHiddle',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
if (
|
||||
!CLOUD_BRAIN_UI_ENABLED &&
|
||||
(item.itemKey === 'skill-platform' ||
|
||||
item.itemKey === 'expert-platform')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
// 分佣管理:新增模块不在 sidebar 配置注册表内,绕过 isModuleVisible(Root 硬门控)
|
||||
if (item.itemKey === 'commission') {
|
||||
return isRoot();
|
||||
}
|
||||
// 系统设置入口:被下放了至少一个 tab 的普通管理员强制可见
|
||||
// (需绕过 isModuleVisible,因为 GetSelf 默认对普通管理员置 admin.setting=false)。
|
||||
// root 及其它情况仍走原有 isModuleVisible 逻辑,保留 root 自行隐藏该入口的能力。
|
||||
if (
|
||||
item.itemKey === 'setting' &&
|
||||
isAdmin() &&
|
||||
!isRoot() &&
|
||||
delegatedSettingTabs.length > 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
const configVisible = isModuleVisible('admin', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [isAdmin(), isRoot(), t, isModuleVisible, canAccessSetting]);
|
||||
|
||||
const chatMenuItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('操练场'),
|
||||
itemKey: 'playground',
|
||||
to: '/playground',
|
||||
},
|
||||
{
|
||||
text: t('聊天'),
|
||||
itemKey: 'chat',
|
||||
items: chatItems,
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('chat', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [chatItems, t, isModuleVisible]);
|
||||
|
||||
// 更新路由映射,添加聊天路由
|
||||
const updateRouterMapWithChats = (chats) => {
|
||||
const newRouterMap = { ...routerMap };
|
||||
|
||||
if (Array.isArray(chats) && chats.length > 0) {
|
||||
for (let i = 0; i < chats.length; i++) {
|
||||
newRouterMap['chat' + i] = '/console/chat/' + i;
|
||||
}
|
||||
}
|
||||
|
||||
setRouterMapState(newRouterMap);
|
||||
return newRouterMap;
|
||||
};
|
||||
|
||||
// 加载聊天项
|
||||
useEffect(() => {
|
||||
let chats = localStorage.getItem('chats');
|
||||
if (chats) {
|
||||
try {
|
||||
chats = JSON.parse(chats);
|
||||
if (Array.isArray(chats)) {
|
||||
let chatItems = [];
|
||||
for (let i = 0; i < chats.length; i++) {
|
||||
let shouldSkip = false;
|
||||
let chat = {};
|
||||
for (let key in chats[i]) {
|
||||
let link = chats[i][key];
|
||||
if (typeof link !== 'string') continue; // 确保链接是字符串
|
||||
if (link.startsWith('fluent')) {
|
||||
shouldSkip = true;
|
||||
break; // 跳过 Fluent Read
|
||||
}
|
||||
chat.text = key;
|
||||
chat.itemKey = 'chat' + i;
|
||||
chat.to = '/console/chat/' + i;
|
||||
}
|
||||
if (shouldSkip || !chat.text) continue; // 避免推入空项
|
||||
chatItems.push(chat);
|
||||
}
|
||||
setChatItems(chatItems);
|
||||
updateRouterMapWithChats(chats);
|
||||
}
|
||||
} catch (e) {
|
||||
showError(t('聊天数据解析失败'));
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 根据当前路径设置选中的菜单项
|
||||
useEffect(() => {
|
||||
const currentPath = location.pathname;
|
||||
let matchingKey = Object.keys(routerMapState).find(
|
||||
(key) => routerMapState[key] === currentPath,
|
||||
);
|
||||
|
||||
// 处理聊天路由
|
||||
if (!matchingKey && currentPath.startsWith('/console/chat/')) {
|
||||
const chatIndex = currentPath.split('/').pop();
|
||||
if (!isNaN(chatIndex)) {
|
||||
matchingKey = 'chat' + chatIndex;
|
||||
} else {
|
||||
matchingKey = 'chat';
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到匹配的键,更新选中的键
|
||||
if (matchingKey) {
|
||||
setSelectedKeys([matchingKey]);
|
||||
}
|
||||
}, [location.pathname, routerMapState]);
|
||||
|
||||
// 监控折叠状态变化以更新 body class(--sidebar-current-width 由它驱动)。
|
||||
// 抽屉态下跳过:body class 是全局的,抽屉临时展开不该顺手把桌面侧栏宽度也改掉。
|
||||
useEffect(() => {
|
||||
if (forceExpanded) return;
|
||||
if (persistedCollapsed) {
|
||||
document.body.classList.add('sidebar-collapsed');
|
||||
} else {
|
||||
document.body.classList.remove('sidebar-collapsed');
|
||||
}
|
||||
}, [persistedCollapsed, forceExpanded]);
|
||||
|
||||
// 选中高亮颜色(统一)
|
||||
const SELECTED_COLOR = 'var(--semi-color-primary)';
|
||||
|
||||
// 渲染自定义菜单项
|
||||
const renderNavItem = (item) => {
|
||||
// 跳过隐藏的项目
|
||||
if (item.className === 'tableHiddle') return null;
|
||||
|
||||
const isSelected = selectedKeys.includes(item.itemKey);
|
||||
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Item
|
||||
key={item.itemKey}
|
||||
itemKey={item.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: textColor }}
|
||||
>
|
||||
{item.text}
|
||||
</span>
|
||||
}
|
||||
icon={
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{getLucideIcon(item.itemKey, isSelected)}
|
||||
</div>
|
||||
}
|
||||
className={item.className}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染子菜单项
|
||||
const renderSubItem = (item) => {
|
||||
if (item.items && item.items.length > 0) {
|
||||
const isSelected = selectedKeys.includes(item.itemKey);
|
||||
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Sub
|
||||
key={item.itemKey}
|
||||
itemKey={item.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: textColor }}
|
||||
>
|
||||
{item.text}
|
||||
</span>
|
||||
}
|
||||
icon={
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{getLucideIcon(item.itemKey, isSelected)}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{item.items.map((subItem) => {
|
||||
const isSubSelected = selectedKeys.includes(subItem.itemKey);
|
||||
const subTextColor = isSubSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Item
|
||||
key={subItem.itemKey}
|
||||
itemKey={subItem.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: subTextColor }}
|
||||
>
|
||||
{subItem.text}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Nav.Sub>
|
||||
);
|
||||
} else {
|
||||
return renderNavItem(item);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className='sidebar-container'
|
||||
style={{
|
||||
width: forceExpanded
|
||||
? 'var(--sidebar-width)'
|
||||
: 'var(--sidebar-current-width)',
|
||||
background: 'var(--semi-color-bg-0)',
|
||||
}}
|
||||
>
|
||||
<SkeletonWrapper
|
||||
loading={showSkeleton}
|
||||
type='sidebar'
|
||||
className=''
|
||||
collapsed={collapsed}
|
||||
showAdmin={isAdmin()}
|
||||
>
|
||||
<Nav
|
||||
className='sidebar-nav'
|
||||
defaultIsCollapsed={collapsed}
|
||||
isCollapsed={collapsed}
|
||||
onCollapseChange={toggleCollapsed}
|
||||
selectedKeys={selectedKeys}
|
||||
itemStyle='sidebar-nav-item'
|
||||
hoverStyle='sidebar-nav-item:hover'
|
||||
selectedStyle='sidebar-nav-item-selected'
|
||||
renderWrapper={({ itemElement, props }) => {
|
||||
const to =
|
||||
routerMapState[props.itemKey] || routerMap[props.itemKey];
|
||||
|
||||
// 如果没有路由,直接返回元素
|
||||
if (!to) return itemElement;
|
||||
|
||||
return (
|
||||
<Link
|
||||
style={{ textDecoration: 'none' }}
|
||||
to={to}
|
||||
onClick={onNavigate}
|
||||
>
|
||||
{itemElement}
|
||||
</Link>
|
||||
);
|
||||
}}
|
||||
onSelect={(key) => {
|
||||
// 如果点击的是已经展开的子菜单的父项,则收起子菜单
|
||||
if (openedKeys.includes(key.itemKey)) {
|
||||
setOpenedKeys(openedKeys.filter((k) => k !== key.itemKey));
|
||||
}
|
||||
|
||||
setSelectedKeys([key.itemKey]);
|
||||
}}
|
||||
openKeys={openedKeys}
|
||||
onOpenChange={(data) => {
|
||||
setOpenedKeys(data.openKeys);
|
||||
}}
|
||||
>
|
||||
{/* 聊天区域 */}
|
||||
{hasSectionVisibleModules('chat') && (
|
||||
<div className='sidebar-section'>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('聊天')}</div>
|
||||
)}
|
||||
{chatMenuItems.map((item) => renderSubItem(item))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 控制台区域 */}
|
||||
{hasSectionVisibleModules('console') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('控制台')}</div>
|
||||
)}
|
||||
{workspaceItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 个人中心区域 */}
|
||||
{hasSectionVisibleModules('personal') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('个人中心')}</div>
|
||||
)}
|
||||
{financeItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 管理员区域 - 只在管理员时显示且配置允许时显示 */}
|
||||
{isAdmin() && hasSectionVisibleModules('admin') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('管理员')}</div>
|
||||
)}
|
||||
{adminItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Nav>
|
||||
</SkeletonWrapper>
|
||||
|
||||
{/* 底部折叠按钮 —— 抽屉态不提供:收起后抽屉会变成 60px 窄条,等于自废 */}
|
||||
{!forceExpanded && (
|
||||
<div className='sidebar-collapse-button'>
|
||||
<SkeletonWrapper
|
||||
loading={showSkeleton}
|
||||
type='button'
|
||||
width={collapsed ? 36 : 156}
|
||||
height={24}
|
||||
className='w-full'
|
||||
>
|
||||
<Button
|
||||
theme='outline'
|
||||
type='tertiary'
|
||||
size='small'
|
||||
icon={
|
||||
<ChevronLeft
|
||||
size={16}
|
||||
strokeWidth={2.5}
|
||||
color='var(--semi-color-text-2)'
|
||||
style={{
|
||||
transform: collapsed ? 'rotate(180deg)' : 'rotate(0deg)',
|
||||
}}
|
||||
/>
|
||||
}
|
||||
onClick={toggleCollapsed}
|
||||
icononly={collapsed}
|
||||
style={
|
||||
collapsed
|
||||
? { width: 36, height: 24, padding: 0 }
|
||||
: { padding: '4px 12px', width: '100%' }
|
||||
}
|
||||
>
|
||||
{!collapsed ? t('收起侧边栏') : null}
|
||||
</Button>
|
||||
</SkeletonWrapper>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SiderBar;
|
||||
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Skeleton } from '@douyinfe/semi-ui';
|
||||
|
||||
const SkeletonWrapper = ({
|
||||
loading = false,
|
||||
type = 'text',
|
||||
count = 1,
|
||||
width = 60,
|
||||
height = 16,
|
||||
isMobile = false,
|
||||
className = '',
|
||||
collapsed = false,
|
||||
showAdmin = true,
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
if (!loading) {
|
||||
return children;
|
||||
}
|
||||
|
||||
// 导航链接骨架屏
|
||||
const renderNavigationSkeleton = () => {
|
||||
const skeletonLinkClasses = isMobile
|
||||
? 'flex items-center gap-1 p-1 w-full rounded-md'
|
||||
: 'flex items-center gap-1 p-2 rounded-md';
|
||||
|
||||
return Array(count)
|
||||
.fill(null)
|
||||
.map((_, index) => (
|
||||
<div key={index} className={skeletonLinkClasses}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: isMobile ? 40 : width, height }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
};
|
||||
|
||||
// 用户区域骨架屏 (头像 + 文本)
|
||||
const renderUserAreaSkeleton = () => {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center p-1 rounded-full bg-semi-color-fill-0 dark:bg-semi-color-fill-1 ${className}`}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar active size='extra-small' className='shadow-sm' />
|
||||
}
|
||||
/>
|
||||
<div className='ml-1.5 mr-1'>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: isMobile ? 15 : width, height: 12 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Logo图片骨架屏
|
||||
const renderImageSkeleton = () => {
|
||||
return (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Image
|
||||
active
|
||||
className={`absolute inset-0 !rounded-full ${className}`}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 系统名称骨架屏
|
||||
const renderTitleSkeleton = () => {
|
||||
return (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={<Skeleton.Title active style={{ width, height: 24 }} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 通用文本骨架屏
|
||||
const renderTextSkeleton = () => {
|
||||
return (
|
||||
<div className={className}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={<Skeleton.Title active style={{ width, height }} />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 按钮骨架屏(支持圆角)
|
||||
const renderButtonSkeleton = () => {
|
||||
return (
|
||||
<div className={className}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width, height, borderRadius: 9999 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 侧边栏导航项骨架屏 (图标 + 文本)
|
||||
const renderSidebarNavItemSkeleton = () => {
|
||||
return Array(count)
|
||||
.fill(null)
|
||||
.map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className={`flex items-center p-2 mb-1 rounded-md ${className}`}
|
||||
>
|
||||
{/* 图标骨架屏 */}
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar active size='extra-small' shape='square' />
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{/* 文本骨架屏 */}
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: width || 80, height: height || 14 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
};
|
||||
|
||||
// 侧边栏组标题骨架屏
|
||||
const renderSidebarGroupTitleSkeleton = () => {
|
||||
return (
|
||||
<div className={`mb-2 ${className}`}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: width || 60, height: height || 12 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 完整侧边栏骨架屏 - 1:1 还原,去重实现
|
||||
const renderSidebarSkeleton = () => {
|
||||
const NAV_WIDTH = 164;
|
||||
const NAV_HEIGHT = 30;
|
||||
const COLLAPSED_WIDTH = 44;
|
||||
const COLLAPSED_HEIGHT = 44;
|
||||
const ICON_SIZE = 16;
|
||||
const TITLE_HEIGHT = 12;
|
||||
const TEXT_HEIGHT = 16;
|
||||
|
||||
const renderIcon = () => (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar
|
||||
active
|
||||
shape='square'
|
||||
style={{ width: ICON_SIZE, height: ICON_SIZE }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
const renderLabel = (labelWidth) => (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: labelWidth, height: TEXT_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
const NavRow = ({ labelWidth }) => (
|
||||
<div
|
||||
className='flex items-center p-2 mb-1 rounded-md'
|
||||
style={{
|
||||
width: `${NAV_WIDTH}px`,
|
||||
height: `${NAV_HEIGHT}px`,
|
||||
margin: '3px 8px',
|
||||
}}
|
||||
>
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{renderIcon()}
|
||||
</div>
|
||||
{renderLabel(labelWidth)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const CollapsedRow = ({ keyPrefix, index }) => (
|
||||
<div
|
||||
key={`${keyPrefix}-${index}`}
|
||||
className='flex items-center justify-center'
|
||||
style={{
|
||||
width: `${COLLAPSED_WIDTH}px`,
|
||||
height: `${COLLAPSED_HEIGHT}px`,
|
||||
margin: '0 8px 4px 8px',
|
||||
}}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar
|
||||
active
|
||||
shape='square'
|
||||
style={{ width: ICON_SIZE, height: ICON_SIZE }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<div className={`w-full ${className}`} style={{ paddingTop: '12px' }}>
|
||||
{Array(2)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-chat' index={i} />
|
||||
))}
|
||||
{Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-console' index={i} />
|
||||
))}
|
||||
{Array(2)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-personal' index={i} />
|
||||
))}
|
||||
{Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-admin' index={i} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const sections = [
|
||||
{ key: 'chat', titleWidth: 32, itemWidths: [54, 32], wrapper: 'section' },
|
||||
{ key: 'console', titleWidth: 48, itemWidths: [64, 64, 64, 64, 64] },
|
||||
{ key: 'personal', titleWidth: 64, itemWidths: [64, 64] },
|
||||
...(showAdmin
|
||||
? [{ key: 'admin', titleWidth: 48, itemWidths: [64, 64, 80, 64, 64] }]
|
||||
: []),
|
||||
];
|
||||
|
||||
return (
|
||||
<div className={`w-full ${className}`} style={{ paddingTop: '12px' }}>
|
||||
{sections.map((sec, idx) => (
|
||||
<React.Fragment key={sec.key}>
|
||||
{sec.wrapper === 'section' ? (
|
||||
<div className='sidebar-section'>
|
||||
<div
|
||||
className='sidebar-group-label'
|
||||
style={{ padding: '4px 15px 8px' }}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: sec.titleWidth, height: TITLE_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{sec.itemWidths.map((w, i) => (
|
||||
<NavRow key={`${sec.key}-${i}`} labelWidth={w} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div
|
||||
className='sidebar-group-label'
|
||||
style={{ padding: '4px 15px 8px' }}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: sec.titleWidth, height: TITLE_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{sec.itemWidths.map((w, i) => (
|
||||
<NavRow key={`${sec.key}-${i}`} labelWidth={w} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 根据类型渲染不同的骨架屏
|
||||
switch (type) {
|
||||
case 'navigation':
|
||||
return renderNavigationSkeleton();
|
||||
case 'userArea':
|
||||
return renderUserAreaSkeleton();
|
||||
case 'image':
|
||||
return renderImageSkeleton();
|
||||
case 'title':
|
||||
return renderTitleSkeleton();
|
||||
case 'sidebarNavItem':
|
||||
return renderSidebarNavItemSkeleton();
|
||||
case 'sidebarGroupTitle':
|
||||
return renderSidebarGroupTitleSkeleton();
|
||||
case 'sidebar':
|
||||
return renderSidebarSkeleton();
|
||||
case 'button':
|
||||
return renderButtonSkeleton();
|
||||
case 'text':
|
||||
default:
|
||||
return renderTextSkeleton();
|
||||
}
|
||||
};
|
||||
|
||||
export default SkeletonWrapper;
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import { IconCreditCard } from '@douyinfe/semi-icons';
|
||||
import { Share2, BookOpen, MonitorDown } from 'lucide-react';
|
||||
import NewYearButton from './NewYearButton';
|
||||
import NotificationButton from './NotificationButton';
|
||||
import ThemeToggle from './ThemeToggle';
|
||||
import LanguageSelector from './LanguageSelector';
|
||||
import UserArea from './UserArea';
|
||||
import PromotionPosterModal from '../../promotion/PromotionPosterModal';
|
||||
import { StatusContext } from '../../../context/Status';
|
||||
import { isHeaderActionButtonVisible } from '../../../helpers/navigationVisibility';
|
||||
import { useWeyAiDownloadEntry } from '../../../hooks/common/useWeyAiWebEntry';
|
||||
|
||||
const ActionButtons = ({
|
||||
isAuthPage = false,
|
||||
isNewYear,
|
||||
unreadCount,
|
||||
onNoticeOpen,
|
||||
theme,
|
||||
onThemeToggle,
|
||||
currentLang,
|
||||
onLanguageChange,
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
sidebarModulesAdmin,
|
||||
isOrgUser,
|
||||
logout,
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const [promotionVisible, setPromotionVisible] = useState(false);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const isLoggedIn = userState?.user?.username;
|
||||
const userGroup = userState?.user?.group || 'default';
|
||||
// WeyAi 桌面端下载快捷入口:判定与用户中心侧栏项共用 useWeyAiDownloadEntry
|
||||
// (下载页开关 + 登录 + 网页端已配置时沿用其开放范围);管理员可在「功能按钮」
|
||||
// 里全局关闭,企业员工顶栏可在 rightActions 里单独关闭
|
||||
const { visible: weyaiDownloadVisible } = useWeyAiDownloadEntry();
|
||||
|
||||
// 顶栏功能按钮显示配置(新手教程 / 推广 / 充值)。
|
||||
// 数据源与 HeaderNavModules 一致,走公开的 /api/status(StatusContext / localStorage 缓存),
|
||||
// 普通用户也能读取;不要用 /api/option/,那是管理员(RootAuth)专用接口,普通用户会 403。
|
||||
let buttonConfig = null;
|
||||
try {
|
||||
const raw =
|
||||
statusState?.status?.HeaderActionButtons ||
|
||||
(localStorage.getItem('status')
|
||||
? JSON.parse(localStorage.getItem('status')).HeaderActionButtons
|
||||
: null);
|
||||
if (raw) {
|
||||
buttonConfig = JSON.parse(raw);
|
||||
}
|
||||
} catch (e) {
|
||||
buttonConfig = null;
|
||||
}
|
||||
|
||||
// 企业员工:教程/推广/充值 这三个主操作按钮由 HeaderActionButtons 控制,
|
||||
// 但企业顶栏配置走 headerNavModules.rightActions,故对 org 用户额外按 rightActions 隐藏。
|
||||
// 注意 key 映射:推广按钮在 HeaderActionButtons 里叫 'pricing',在 rightActions 里叫 'promotion'。
|
||||
const orgRightActionKey = {
|
||||
tutorial: 'tutorial',
|
||||
pricing: 'promotion',
|
||||
recharge: 'recharge',
|
||||
weyaiDownload: 'weyaiDownload',
|
||||
};
|
||||
|
||||
// 判断某个功能按钮是否显示:无配置、配置非数组(脏数据)或配置缺失该项时默认显示。
|
||||
// 认证页(登录/注册/企业登录等)一律隐藏主操作按钮:充值/教程/推广要么需要登录态,
|
||||
// 要么会把用户带离认证流程,行业惯例认证页顶栏只留最小化工具。
|
||||
const isButtonVisible = (key) => {
|
||||
if (isAuthPage) return false;
|
||||
if (isOrgUser) {
|
||||
const ra = orgRightActionKey[key];
|
||||
if (ra && headerNavModules?.rightActions?.[ra] === false) return false;
|
||||
}
|
||||
return isHeaderActionButtonVisible(buttonConfig, key, userGroup);
|
||||
};
|
||||
|
||||
// 右侧工具类按钮(新年 / 通知 / 主题切换)显隐:跟随 rightActions 配置,默认显示。
|
||||
// 认证页只保留主题切换(对未登录用户有意义且不打断认证流程),通知/新年装饰一并隐藏。
|
||||
const isActionVisible = (key) => {
|
||||
if (isAuthPage && key !== 'theme') return false;
|
||||
return headerNavModules?.rightActions?.[key] !== false;
|
||||
};
|
||||
|
||||
// 语言切换按钮(中/英):由管理员在 运营设置→通用设置 控制,默认显示。
|
||||
// 与 HeaderActionButtons 同源走公开 /api/status(普通用户可读),status 未加载时
|
||||
// 回退 localStorage 缓存;仅显式 false 才隐藏。认证页也展示(对未登录用户有意义)。
|
||||
let languageSwitchEnabled = true;
|
||||
try {
|
||||
const status =
|
||||
statusState?.status ||
|
||||
(localStorage.getItem('status')
|
||||
? JSON.parse(localStorage.getItem('status'))
|
||||
: null);
|
||||
if (status && status.language_switch_enabled === false) {
|
||||
languageSwitchEnabled = false;
|
||||
}
|
||||
} catch (e) {
|
||||
languageSwitchEnabled = true;
|
||||
}
|
||||
|
||||
// 是否存在「主操作区」按钮(新手教程 / 推广 / 充值),用于决定分隔线是否显示
|
||||
const showWeyAiDownload =
|
||||
isLoggedIn && weyaiDownloadVisible && isButtonVisible('weyaiDownload');
|
||||
|
||||
const hasPrimaryActions =
|
||||
(isLoggedIn && isButtonVisible('tutorial')) ||
|
||||
(isLoggedIn && isButtonVisible('pricing')) ||
|
||||
showWeyAiDownload ||
|
||||
isButtonVisible('recharge');
|
||||
|
||||
// 是否存在「工具区」按钮(新年 / 通知 / 主题 / 语言)
|
||||
const hasUtilityActions =
|
||||
isActionVisible('newYear') ||
|
||||
isActionVisible('notifications') ||
|
||||
isActionVisible('theme') ||
|
||||
languageSwitchEnabled;
|
||||
|
||||
// 进入用户区前是否需要分隔线(任一侧有按钮即显示)
|
||||
const hasHeaderActions = hasPrimaryActions || hasUtilityActions;
|
||||
|
||||
return (
|
||||
<div className='flex items-center shrink-0 gap-0.5 sm:gap-2 md:gap-3'>
|
||||
{/* Tutorial Button - 新手教程按钮 (桌面端显示) */}
|
||||
{isLoggedIn && isButtonVisible('tutorial') && (
|
||||
<Link to='/tutorial' className='hidden sm:block'>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<BookOpen size={15} />}
|
||||
className='group/btn hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('新手教程')}</span>}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* Promotion Button - 推广按钮 (桌面端显示) */}
|
||||
{isLoggedIn && isButtonVisible('pricing') && (
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<Share2 size={15} />}
|
||||
className='hidden sm:!inline-flex hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
onClick={() => setPromotionVisible(true)}
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('推广')}</span>}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* WeyAi 桌面端下载 - 有 WeyAi 访问权限且下载页已开放时显示 (桌面端显示) */}
|
||||
{showWeyAiDownload && (
|
||||
<Link
|
||||
to='/weyai/download'
|
||||
className='hidden sm:block'
|
||||
aria-label={t('下载 WeyAi 桌面端')}
|
||||
>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<MonitorDown size={15} />}
|
||||
className='group/btn hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
>
|
||||
{!isMobile && (
|
||||
<span className='font-medium'>{t('下载 WeyAi')}</span>
|
||||
)}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* Recharge Button - 充值按钮 (primary CTA) */}
|
||||
{isButtonVisible('recharge') && (
|
||||
<Link to='/recharge'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
icon={<IconCreditCard />}
|
||||
className='!bg-gradient-to-r !from-brand !to-brand-deep dark:!from-brand dark:!to-brand-deep !text-white !border-none !rounded-full !px-3 sm:!px-4 !h-7 sm:!h-8 !font-semibold !transition-all !duration-200 !shadow-md !shadow-brand/30 hover:!shadow-lg hover:!shadow-brand/45 hover:!-translate-y-0.5 active:!translate-y-0 active:!scale-[0.98]'
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('充值')}</span>}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
<PromotionPosterModal
|
||||
visible={promotionVisible}
|
||||
onClose={() => setPromotionVisible(false)}
|
||||
/>
|
||||
|
||||
{/* Divider */}
|
||||
{hasPrimaryActions && hasUtilityActions && (
|
||||
<div className='hidden md:block w-px h-6 bg-gradient-to-b from-transparent via-gray-300 dark:via-neutral-600 to-transparent mx-1' />
|
||||
)}
|
||||
|
||||
{isActionVisible('newYear') && (
|
||||
<NewYearButton isNewYear={isNewYear} t={t} />
|
||||
)}
|
||||
|
||||
{isActionVisible('notifications') && (
|
||||
<NotificationButton
|
||||
unreadCount={unreadCount}
|
||||
onNoticeOpen={onNoticeOpen}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isActionVisible('theme') && (
|
||||
<ThemeToggle theme={theme} onThemeToggle={onThemeToggle} t={t} />
|
||||
)}
|
||||
|
||||
{languageSwitchEnabled && (
|
||||
<LanguageSelector
|
||||
currentLang={currentLang}
|
||||
onLanguageChange={onLanguageChange}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Divider before user area(认证页 UserArea 通常为空,不渲染悬空分隔线) */}
|
||||
{hasHeaderActions && !isAuthPage && (
|
||||
<div className='hidden md:block w-px h-6 bg-gradient-to-b from-transparent via-gray-300 dark:via-neutral-600 to-transparent mx-1' />
|
||||
)}
|
||||
|
||||
<UserArea
|
||||
userState={userState}
|
||||
isLoading={isLoading}
|
||||
isMobile={isMobile}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
headerNavModules={headerNavModules}
|
||||
rightActions={headerNavModules?.rightActions}
|
||||
sidebarModulesAdmin={sidebarModulesAdmin}
|
||||
logout={logout}
|
||||
navigate={navigate}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActionButtons;
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Typography, Tag } from '@douyinfe/semi-ui';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
|
||||
const HeaderLogo = ({
|
||||
isMobile,
|
||||
isConsoleRoute,
|
||||
logo,
|
||||
logoLoaded,
|
||||
isLoading,
|
||||
systemName,
|
||||
isSelfUseMode,
|
||||
isDemoSiteMode,
|
||||
t,
|
||||
}) => {
|
||||
if (isMobile && isConsoleRoute) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Link to='/' className='group flex items-center gap-2'>
|
||||
<div className='relative w-8 h-8 md:w-8 md:h-8'>
|
||||
<SkeletonWrapper loading={isLoading || !logoLoaded} type='image' />
|
||||
<img
|
||||
src={logo}
|
||||
alt='logo'
|
||||
className={`absolute inset-0 w-full h-full transition-all duration-200 group-hover:scale-110 rounded-full ${!isLoading && logoLoaded ? 'opacity-100' : 'opacity-0'}`}
|
||||
/>
|
||||
</div>
|
||||
<div className='hidden md:flex items-center gap-2'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<SkeletonWrapper
|
||||
loading={isLoading}
|
||||
type='title'
|
||||
width={120}
|
||||
height={24}
|
||||
>
|
||||
<Typography.Title
|
||||
heading={4}
|
||||
className='!text-lg !font-semibold !mb-0'
|
||||
>
|
||||
{systemName}
|
||||
</Typography.Title>
|
||||
</SkeletonWrapper>
|
||||
{(isSelfUseMode || isDemoSiteMode) && !isLoading && (
|
||||
<Tag
|
||||
color={isSelfUseMode ? 'purple' : 'blue'}
|
||||
className='text-xs px-1.5 py-0.5 rounded whitespace-nowrap shadow-sm'
|
||||
size='small'
|
||||
shape='circle'
|
||||
>
|
||||
{isSelfUseMode ? t('自用模式') : t('演示站点')}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
export default HeaderLogo;
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Dropdown } from '@douyinfe/semi-ui';
|
||||
import { Globe } from 'lucide-react';
|
||||
import { CN, GB, JP, KR, TH, VN } from 'country-flag-icons/react/3x2';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
import { normalizeLanguage } from '../../../i18n/language';
|
||||
import { orderEnabledLanguages } from '../../../i18n/catalog';
|
||||
import {
|
||||
LANG_BOOT_UPDATED_EVENT,
|
||||
getBootConfig,
|
||||
} from '../../../i18n/bootstrap';
|
||||
|
||||
// 语言目录里的 flag 国家码 → 旗帜组件
|
||||
const FLAGS = { CN, GB, JP, KR, TH, VN };
|
||||
|
||||
const LanguageSelector = ({ currentLang, onLanguageChange, t }) => {
|
||||
// i18n.language 可能带地区码(如 zh-CN / en-US),高亮判断先归一化;
|
||||
// 繁体靠地区码区分,不能简单取主语言
|
||||
const lang = normalizeLanguage(currentLang);
|
||||
// 与 ThemeToggle 同规范:图标颜色随实际主题动态取色(Semi 暗色由
|
||||
// body[theme-mode] 驱动,Tailwind dark: 类在此不可靠),菜单样式走
|
||||
// semi-color token 天然亮暗自适应
|
||||
const actualTheme = useActualTheme();
|
||||
|
||||
// 首访时后台判定可能晚于顶栏首次渲染:结果写入缓存后重新读取启用语言,
|
||||
// 避免列出后台已停用的语言
|
||||
const [, setBootVersion] = useState(0);
|
||||
useEffect(() => {
|
||||
const handleBootUpdated = () => setBootVersion((version) => version + 1);
|
||||
window.addEventListener(LANG_BOOT_UPDATED_EVENT, handleBootUpdated);
|
||||
return () =>
|
||||
window.removeEventListener(LANG_BOOT_UPDATED_EVENT, handleBootUpdated);
|
||||
}, []);
|
||||
|
||||
const getItemClassName = (isSelected) =>
|
||||
`!flex !items-center !gap-2 !px-3 !py-1.5 !text-sm ${
|
||||
isSelected
|
||||
? '!bg-semi-color-primary-light-default !font-semibold'
|
||||
: 'hover:!bg-semi-color-fill-1'
|
||||
}`;
|
||||
|
||||
// 展示哪些语言、按什么顺序由后台「语言与地区」配置决定(经 /api/i18n/locale 缓存下发)
|
||||
const languages = orderEnabledLanguages(getBootConfig()?.enabled_languages);
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
position='bottomRight'
|
||||
render={
|
||||
<Dropdown.Menu>
|
||||
{languages.map(({ code, endonym, flag }) => {
|
||||
const Flag = FLAGS[flag];
|
||||
return (
|
||||
<Dropdown.Item
|
||||
key={code}
|
||||
onClick={() => onLanguageChange(code)}
|
||||
className={getItemClassName(lang === code)}
|
||||
>
|
||||
{Flag && <Flag title={endonym} className='!w-5 !h-auto' />}
|
||||
<span>{endonym}</span>
|
||||
</Dropdown.Item>
|
||||
);
|
||||
})}
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
icon={<Globe size={20} />}
|
||||
aria-label={t('common.changeLanguage')}
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='!w-8 !h-8 sm:!w-9 sm:!h-9 !flex !items-center !justify-center hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !rounded-full !transition-all !duration-200 hover:!scale-[1.08] active:!scale-95'
|
||||
style={{
|
||||
color:
|
||||
actualTheme === 'dark'
|
||||
? 'rgba(243,244,246,0.9)'
|
||||
: 'rgba(75,85,99,1)',
|
||||
}}
|
||||
/>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default LanguageSelector;
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import { IconClose, IconMenu } from '@douyinfe/semi-icons';
|
||||
|
||||
const MobileMenuButton = ({
|
||||
isConsoleRoute,
|
||||
isMobile,
|
||||
drawerOpen,
|
||||
collapsed,
|
||||
onToggle,
|
||||
t,
|
||||
}) => {
|
||||
if (!isConsoleRoute || !isMobile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
icon={
|
||||
(isMobile ? drawerOpen : collapsed) ? (
|
||||
<IconClose className='text-lg' />
|
||||
) : (
|
||||
<IconMenu className='text-lg' />
|
||||
)
|
||||
}
|
||||
aria-label={
|
||||
(isMobile ? drawerOpen : collapsed) ? t('关闭侧边栏') : t('打开侧边栏')
|
||||
}
|
||||
onClick={onToggle}
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='!p-2 !text-current !rounded-xl hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from focus:!bg-brand/10 !transition-all !duration-200 active:!scale-95'
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default MobileMenuButton;
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { Button, Dropdown } from '@douyinfe/semi-ui';
|
||||
import { Compass, ExternalLink } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* 移动端主导航入口。
|
||||
*
|
||||
* 顶栏宽度在手机上只够放「logo + 主操作 + 工具图标 + 头像」,
|
||||
* 主导航若继续内联平铺会把右侧按钮挤成一团(横向滚动条也不可见、不可发现)。
|
||||
* 因此 <768px 时把 mainNavLinks 收进这个下拉菜单,跟主流控制台的做法保持一致。
|
||||
*
|
||||
* 目标路径/外链的推导逻辑必须与桌面端 Navigation 保持一致,避免两端跳转不同。
|
||||
*/
|
||||
const MobileNavMenu = ({ mainNavLinks, userState, t }) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
if (!mainNavLinks || mainNavLinks.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 与 Navigation 一致:按完整路径段匹配,避免 /market 命中 /market-detail
|
||||
const isPathActive = (matchPath) => {
|
||||
if (!matchPath) return false;
|
||||
if (matchPath === '/') return location.pathname === '/';
|
||||
return (
|
||||
location.pathname === matchPath ||
|
||||
location.pathname.startsWith(`${matchPath}/`)
|
||||
);
|
||||
};
|
||||
|
||||
// 与 Navigation 一致:未登录时需要鉴权的入口统一引导到企业登录
|
||||
const resolveTarget = (link) => {
|
||||
if (link.requireAuth && !userState?.user) return '/org/login';
|
||||
if (link.itemKey === 'console' && !userState?.user) return '/org/login';
|
||||
return link.to;
|
||||
};
|
||||
|
||||
// 把「一级链接 + 二级子项」拍平成一份菜单项列表
|
||||
const menuItems = [];
|
||||
mainNavLinks.forEach((link) => {
|
||||
if (link.items && link.items.length > 0) {
|
||||
link.items.forEach((subItem) => {
|
||||
menuItems.push({
|
||||
key: `${link.itemKey}-${subItem.itemKey}`,
|
||||
text: subItem.text,
|
||||
to: subItem.to,
|
||||
active: isPathActive(subItem.to),
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetPath = resolveTarget(link);
|
||||
if (link.isExternal && targetPath !== '/org/login') {
|
||||
menuItems.push({
|
||||
key: link.itemKey,
|
||||
text: link.text,
|
||||
externalLink: link.externalLink,
|
||||
active: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
menuItems.push({
|
||||
key: link.itemKey,
|
||||
text: link.text,
|
||||
to: targetPath,
|
||||
active: isPathActive(link.activePrefix || targetPath),
|
||||
});
|
||||
});
|
||||
|
||||
const activeItem = menuItems.find((item) => item.active);
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
trigger='click'
|
||||
position='bottomLeft'
|
||||
visible={visible}
|
||||
onVisibleChange={setVisible}
|
||||
render={
|
||||
<Dropdown.Menu className='!min-w-[168px] !p-1.5 !rounded-xl !border !border-gray-100 dark:!border-neutral-800 !shadow-xl !shadow-gray-200/50 dark:!shadow-black/30 !backdrop-blur-xl !bg-white/95 dark:!bg-neutral-900/95'>
|
||||
{menuItems.map((item) => (
|
||||
<Dropdown.Item
|
||||
key={item.key}
|
||||
onClick={() => {
|
||||
setVisible(false);
|
||||
if (item.externalLink) {
|
||||
window.open(
|
||||
item.externalLink,
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
);
|
||||
} else if (item.to) {
|
||||
navigate(item.to);
|
||||
}
|
||||
}}
|
||||
className={`!rounded-lg !my-0.5 !px-3 !py-2 !text-sm !transition-colors ${
|
||||
item.active
|
||||
? '!bg-brand/10 dark:!bg-brand-deep/40 !text-brand-deep dark:!text-brand-from !font-semibold'
|
||||
: '!text-gray-700 dark:!text-neutral-200'
|
||||
}`}
|
||||
>
|
||||
<span className='flex items-center gap-1.5'>
|
||||
{item.text}
|
||||
{item.externalLink && (
|
||||
<ExternalLink size={12} className='opacity-50' />
|
||||
)}
|
||||
</span>
|
||||
</Dropdown.Item>
|
||||
))}
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
aria-label={t('主导航')}
|
||||
aria-haspopup='menu'
|
||||
aria-expanded={visible}
|
||||
icon={<Compass size={16} />}
|
||||
className='!ml-1 !px-2 !h-8 max-w-[9rem] !rounded-xl !text-current hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !transition-all !duration-200 active:!scale-95 [&_.semi-button-content]:min-w-0'
|
||||
>
|
||||
<span className='ml-1 text-[13px] font-semibold truncate'>
|
||||
{activeItem ? activeItem.text : t('导航')}
|
||||
</span>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default MobileNavMenu;
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Dropdown } from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
|
||||
const Navigation = ({ mainNavLinks, isMobile, isLoading, userState }) => {
|
||||
const location = useLocation();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const renderNavLinks = () => {
|
||||
const baseClasses =
|
||||
'nav-item-enhanced flex-shrink-0 flex items-center gap-1.5 font-semibold rounded-xl transition-all duration-300 ease-out relative overflow-hidden group';
|
||||
const defaultClasses = 'text-gray-600 dark:text-neutral-300';
|
||||
const hoverClasses = 'hover:text-brand-deep dark:hover:text-brand-from';
|
||||
const activeClasses =
|
||||
'text-brand-deep dark:text-brand-from bg-brand/5 dark:bg-brand-deep/30';
|
||||
const spacingClasses = isMobile ? 'px-2 py-1 text-sm' : 'px-4 py-2';
|
||||
|
||||
// Match on full path segments so /market doesn't light up on /market-detail
|
||||
const isPathActive = (matchPath) => {
|
||||
if (matchPath === '/') return location.pathname === '/';
|
||||
return (
|
||||
location.pathname === matchPath ||
|
||||
location.pathname.startsWith(`${matchPath}/`)
|
||||
);
|
||||
};
|
||||
|
||||
return mainNavLinks.map((link) => {
|
||||
const linkContent = <span className='relative z-10'>{link.text}</span>;
|
||||
|
||||
// Calculate target path for main link(未登录默认引导到企业登录)
|
||||
let targetPath = link.to;
|
||||
if (link.requireAuth && !userState.user) {
|
||||
targetPath = '/org/login';
|
||||
}
|
||||
if (link.itemKey === 'console' && !userState.user) {
|
||||
targetPath = '/org/login';
|
||||
}
|
||||
|
||||
// Check if active
|
||||
let isActive = false;
|
||||
if (link.items && link.items.length > 0) {
|
||||
isActive = link.items.some((subItem) => isPathActive(subItem.to));
|
||||
} else if (!link.isExternal && targetPath) {
|
||||
isActive = isPathActive(link.activePrefix || targetPath);
|
||||
}
|
||||
|
||||
// Hover background effect component
|
||||
const hoverBg = (
|
||||
<span className='absolute inset-0 bg-gradient-to-r from-brand-from/10 via-brand-via/5 to-brand-to/10 dark:from-brand-from/40 dark:via-brand-via/30 dark:to-brand-to/40 opacity-0 group-hover:opacity-100 transition-opacity duration-300 rounded-xl' />
|
||||
);
|
||||
|
||||
const finalClasses = `${baseClasses} ${spacingClasses} ${isActive ? `nav-item-active ${activeClasses}` : `${defaultClasses} ${hoverClasses}`}`;
|
||||
|
||||
if (link.items && link.items.length > 0) {
|
||||
return (
|
||||
<Dropdown
|
||||
key={link.itemKey}
|
||||
trigger={'hover'}
|
||||
position={'bottomLeft'}
|
||||
render={
|
||||
<Dropdown.Menu className='!rounded-xl !border !border-gray-100 dark:!border-neutral-800 !shadow-xl !shadow-gray-200/50 dark:!shadow-black/30 !backdrop-blur-xl !bg-white/95 dark:!bg-neutral-900/95'>
|
||||
{link.items.map((subItem) => (
|
||||
<Dropdown.Item
|
||||
key={subItem.itemKey}
|
||||
className='!rounded-lg !mx-1 !my-0.5 hover:!bg-brand/5 dark:hover:!bg-brand-deep/30 transition-colors'
|
||||
>
|
||||
<Link
|
||||
to={subItem.to}
|
||||
className='block w-full py-0.5 text-gray-700 dark:text-neutral-200 hover:text-brand-deep dark:hover:text-brand-from transition-colors'
|
||||
style={{ textDecoration: 'none' }}
|
||||
>
|
||||
{subItem.text}
|
||||
</Link>
|
||||
</Dropdown.Item>
|
||||
))}
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<div className={`${finalClasses} cursor-pointer`}>
|
||||
{hoverBg}
|
||||
{linkContent}
|
||||
{/* Dropdown arrow */}
|
||||
<svg
|
||||
className='w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-all duration-300 group-hover:rotate-180'
|
||||
fill='none'
|
||||
viewBox='0 0 24 24'
|
||||
stroke='currentColor'
|
||||
>
|
||||
<path
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
strokeWidth={2}
|
||||
d='M19 9l-7 7-7-7'
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
if (link.isExternal && targetPath !== '/org/login') {
|
||||
return (
|
||||
<a
|
||||
key={link.itemKey}
|
||||
href={link.externalLink}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
className={`${baseClasses} ${spacingClasses} ${defaultClasses} ${hoverClasses}`}
|
||||
>
|
||||
{hoverBg}
|
||||
{linkContent}
|
||||
{/* External link icon */}
|
||||
<svg
|
||||
className='w-3 h-3 opacity-50 group-hover:opacity-100 transition-opacity'
|
||||
fill='none'
|
||||
viewBox='0 0 24 24'
|
||||
stroke='currentColor'
|
||||
>
|
||||
<path
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
strokeWidth={2}
|
||||
d='M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14'
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={link.itemKey}
|
||||
to={targetPath}
|
||||
className={finalClasses}
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
>
|
||||
{hoverBg}
|
||||
{linkContent}
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<nav
|
||||
aria-label={t('主导航')}
|
||||
className='flex flex-1 items-center gap-1 lg:gap-2 mx-1 sm:mx-3 md:mx-6 overflow-x-auto whitespace-nowrap scrollbar-hide min-w-0'
|
||||
>
|
||||
<SkeletonWrapper
|
||||
loading={isLoading}
|
||||
type='navigation'
|
||||
count={4}
|
||||
width={60}
|
||||
height={16}
|
||||
isMobile={isMobile}
|
||||
>
|
||||
{renderNavLinks()}
|
||||
</SkeletonWrapper>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
export default Navigation;
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Dropdown } from '@douyinfe/semi-ui';
|
||||
import fireworks from 'react-fireworks';
|
||||
|
||||
const NewYearButton = ({ isNewYear, t }) => {
|
||||
if (!isNewYear) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleNewYearClick = () => {
|
||||
fireworks.init('root', {});
|
||||
fireworks.start();
|
||||
setTimeout(() => {
|
||||
fireworks.stop();
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
position='bottomRight'
|
||||
render={
|
||||
<Dropdown.Menu className='!bg-semi-color-bg-overlay !border-semi-color-border !shadow-lg !rounded-lg dark:!bg-gray-700 dark:!border-gray-600'>
|
||||
<Dropdown.Item
|
||||
onClick={handleNewYearClick}
|
||||
className='!text-semi-color-text-0 hover:!bg-semi-color-fill-1 dark:!text-gray-200 dark:hover:!bg-gray-600'
|
||||
>
|
||||
{t('新年快乐')} 🎉
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
icon={<span className='text-xl'>🎉</span>}
|
||||
aria-label={t('新年快乐')}
|
||||
className='!w-8 !h-8 sm:!w-9 sm:!h-9 !flex !items-center !justify-center !text-current hover:!bg-brand/10 dark:hover:!bg-brand/15 !rounded-full !transition-all !duration-200 hover:!scale-[1.08] active:!scale-95'
|
||||
/>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewYearButton;
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Badge } from '@douyinfe/semi-ui';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
|
||||
// 自定义通知图标 — 圆角方形气泡 + 圆点指示
|
||||
const NoticeIcon = ({ size = 19, color = 'currentColor' }) => (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox='0 0 24 24'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<rect
|
||||
x='3'
|
||||
y='4'
|
||||
width='18'
|
||||
height='14'
|
||||
rx='4'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
/>
|
||||
<circle cx='8.5' cy='11' r='1.25' fill={color} />
|
||||
<circle cx='12' cy='11' r='1.25' fill={color} />
|
||||
<circle cx='15.5' cy='11' r='1.25' fill={color} />
|
||||
<path
|
||||
d='M8 18l2.5-3h3L16 18'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const NotificationButton = ({ unreadCount, onNoticeOpen, t }) => {
|
||||
const actualTheme = useActualTheme();
|
||||
const isDark = actualTheme === 'dark';
|
||||
|
||||
const buttonProps = {
|
||||
icon: <NoticeIcon size={19} />,
|
||||
'aria-label': t('系统公告'),
|
||||
onClick: onNoticeOpen,
|
||||
theme: 'borderless',
|
||||
type: 'tertiary',
|
||||
className:
|
||||
'!w-8 !h-8 sm:!w-9 sm:!h-9 !flex !items-center !justify-center hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !rounded-full !transition-all !duration-200 hover:!scale-[1.08] active:!scale-95',
|
||||
style: { color: isDark ? 'rgba(243,244,246,0.9)' : 'rgba(75,85,99,1)' },
|
||||
};
|
||||
|
||||
if (unreadCount > 0) {
|
||||
return (
|
||||
<Badge count={unreadCount} type='danger' overflowCount={99}>
|
||||
<Button {...buttonProps} />
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
return <Button {...buttonProps} />;
|
||||
};
|
||||
|
||||
export default NotificationButton;
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { Button, Dropdown } from '@douyinfe/semi-ui';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
|
||||
// 自定义浅色图标 — 带光芒的太阳
|
||||
const LightIcon = ({ size = 18, color = 'currentColor' }) => (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox='0 0 24 24'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<circle cx='12' cy='12' r='4.5' stroke={color} strokeWidth='1.7' />
|
||||
<line
|
||||
x1='12'
|
||||
y1='2.5'
|
||||
x2='12'
|
||||
y2='5'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='12'
|
||||
y1='19'
|
||||
x2='12'
|
||||
y2='21.5'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='21.5'
|
||||
y1='12'
|
||||
x2='19'
|
||||
y2='12'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='5'
|
||||
y1='12'
|
||||
x2='2.5'
|
||||
y2='12'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='18.7'
|
||||
y1='5.3'
|
||||
x2='16.9'
|
||||
y2='7.1'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='7.1'
|
||||
y1='16.9'
|
||||
x2='5.3'
|
||||
y2='18.7'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='18.7'
|
||||
y1='18.7'
|
||||
x2='16.9'
|
||||
y2='16.9'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='7.1'
|
||||
y1='7.1'
|
||||
x2='5.3'
|
||||
y2='5.3'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// 自定义深色图标 — 带星星的弯月
|
||||
const DarkIcon = ({ size = 18, color = 'currentColor' }) => (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox='0 0 24 24'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<path
|
||||
d='M20.5 13.5a8.5 8.5 0 01-10-10A8.5 8.5 0 1020.5 13.5z'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
/>
|
||||
<circle cx='18' cy='5' r='0.8' fill={color} />
|
||||
<circle cx='20.5' cy='8' r='0.6' fill={color} />
|
||||
<circle cx='16' cy='3' r='0.5' fill={color} />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// 自定义自动模式图标 — 半日半月
|
||||
const AutoIcon = ({ size = 18, color = 'currentColor' }) => (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox='0 0 24 24'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<circle cx='12' cy='12' r='8.5' stroke={color} strokeWidth='1.7' />
|
||||
<path d='M12 3.5v17a8.5 8.5 0 000-17z' fill={color} fillOpacity='0.2' />
|
||||
<line
|
||||
x1='12'
|
||||
y1='1.5'
|
||||
x2='12'
|
||||
y2='3.5'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='12'
|
||||
y1='20.5'
|
||||
x2='12'
|
||||
y2='22.5'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='22.5'
|
||||
y1='12'
|
||||
x2='20.5'
|
||||
y2='12'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='3.5'
|
||||
y1='12'
|
||||
x2='1.5'
|
||||
y2='12'
|
||||
stroke={color}
|
||||
strokeWidth='1.7'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const ThemeToggle = ({ theme, onThemeToggle, t }) => {
|
||||
const actualTheme = useActualTheme();
|
||||
|
||||
const themeOptions = useMemo(
|
||||
() => [
|
||||
{
|
||||
key: 'light',
|
||||
icon: <LightIcon />,
|
||||
buttonIcon: <LightIcon />,
|
||||
label: t('浅色模式'),
|
||||
description: t('始终使用浅色主题'),
|
||||
},
|
||||
{
|
||||
key: 'dark',
|
||||
icon: <DarkIcon />,
|
||||
buttonIcon: <DarkIcon />,
|
||||
label: t('深色模式'),
|
||||
description: t('始终使用深色主题'),
|
||||
},
|
||||
{
|
||||
key: 'auto',
|
||||
icon: <AutoIcon />,
|
||||
buttonIcon: <AutoIcon />,
|
||||
label: t('自动模式'),
|
||||
description: t('跟随系统主题设置'),
|
||||
},
|
||||
],
|
||||
[t],
|
||||
);
|
||||
|
||||
const getItemClassName = (isSelected) =>
|
||||
isSelected
|
||||
? '!bg-semi-color-primary-light-default !font-semibold'
|
||||
: 'hover:!bg-semi-color-fill-1';
|
||||
|
||||
const currentButtonIcon = useMemo(() => {
|
||||
const currentOption = themeOptions.find((option) => option.key === theme);
|
||||
return currentOption?.buttonIcon || themeOptions[2].buttonIcon;
|
||||
}, [theme, themeOptions]);
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
position='bottomRight'
|
||||
render={
|
||||
<Dropdown.Menu>
|
||||
{themeOptions.map((option) => (
|
||||
<Dropdown.Item
|
||||
key={option.key}
|
||||
icon={option.icon}
|
||||
onClick={() => onThemeToggle(option.key)}
|
||||
className={getItemClassName(theme === option.key)}
|
||||
>
|
||||
<div className='flex flex-col'>
|
||||
<span>{option.label}</span>
|
||||
<span className='text-xs text-semi-color-text-2'>
|
||||
{option.description}
|
||||
</span>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
))}
|
||||
|
||||
{theme === 'auto' && (
|
||||
<>
|
||||
<Dropdown.Divider />
|
||||
<div className='px-3 py-2 text-xs text-semi-color-text-2'>
|
||||
{t('当前跟随系统')}:
|
||||
{actualTheme === 'dark' ? t('深色') : t('浅色')}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
icon={currentButtonIcon}
|
||||
aria-label={t('切换主题')}
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='!w-8 !h-8 sm:!w-9 sm:!h-9 !flex !items-center !justify-center hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !rounded-full !transition-all !duration-200 hover:!scale-[1.08] active:!scale-95'
|
||||
style={{
|
||||
color:
|
||||
actualTheme === 'dark'
|
||||
? 'rgba(243,244,246,0.9)'
|
||||
: 'rgba(75,85,99,1)',
|
||||
}}
|
||||
/>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeToggle;
|
||||
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Avatar, Button, Dropdown, Typography } from '@douyinfe/semi-ui';
|
||||
import { ChevronDown, User, Key, LogOut } from 'lucide-react';
|
||||
import {
|
||||
getUserAvatarUrl,
|
||||
stringToColor,
|
||||
isAuthPagePath,
|
||||
} from '../../../helpers';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
import { isHeaderModuleEnabled } from '../../../constants/headerNavModules';
|
||||
|
||||
const UserArea = ({
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
rightActions = {},
|
||||
sidebarModulesAdmin = {},
|
||||
logout,
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const location = useLocation();
|
||||
const actualTheme = useActualTheme();
|
||||
const isDark = actualTheme === 'dark';
|
||||
const isActionVisible = (key) => rightActions?.[key] !== false;
|
||||
const hasHeaderModuleConfig =
|
||||
headerNavModules && Object.keys(headerNavModules).length > 0;
|
||||
const isTopNavModuleVisible = (key) =>
|
||||
!hasHeaderModuleConfig || isHeaderModuleEnabled(headerNavModules, key);
|
||||
const isSidebarModuleVisible = (sectionKey, moduleKey) => {
|
||||
const section = sidebarModulesAdmin?.[sectionKey];
|
||||
if (!section) return true;
|
||||
return section.enabled !== false && section[moduleKey] !== false;
|
||||
};
|
||||
|
||||
// 在登录/注册/重置密码/企业登录页面时,未登录用户不显示登录注册按钮,避免重复
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<SkeletonWrapper
|
||||
loading={true}
|
||||
type='userArea'
|
||||
width={50}
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (userState.user) {
|
||||
const displayName = userState.user.display_name || userState.user.username;
|
||||
const avatarUrl = getUserAvatarUrl(userState.user);
|
||||
return (
|
||||
<Dropdown
|
||||
trigger='hover'
|
||||
position='bottomRight'
|
||||
showTick
|
||||
render={
|
||||
<Dropdown.Menu
|
||||
className='!min-w-[180px] !p-2 !backdrop-blur-xl !border !shadow-xl !rounded-xl'
|
||||
style={{
|
||||
backgroundColor: isDark
|
||||
? 'rgba(31,41,55,0.95)'
|
||||
: 'rgba(255,255,255,0.95)',
|
||||
borderColor: isDark ? 'rgba(55,65,81,1)' : 'rgba(243,244,246,1)',
|
||||
boxShadow: isDark
|
||||
? '0 20px 25px -5px rgba(0,0,0,0.3)'
|
||||
: '0 20px 25px -5px rgba(0,0,0,0.05)',
|
||||
}}
|
||||
>
|
||||
{/* 用户信息头部 */}
|
||||
<div
|
||||
className='px-3 py-2 mb-2 border-b'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<Avatar
|
||||
size='small'
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-8 !h-8 !text-xs'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
</Avatar>
|
||||
<div>
|
||||
<div
|
||||
className='text-sm font-semibold'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(243,244,246,0.9)'
|
||||
: 'rgba(31,41,55,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{userState.user.email || t('已登录')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isActionVisible('userSettings') &&
|
||||
isTopNavModuleVisible('userCenter') &&
|
||||
isSidebarModuleVisible('userCenter', 'settings') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/user-center/settings');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(30,58,138,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(219,234,254,1), rgba(224,231,255,1))',
|
||||
}}
|
||||
>
|
||||
<User
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(96,165,250,1)'
|
||||
: 'rgba(37,99,235,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('个人设置')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('管理账户信息')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
{isActionVisible('keyManagement') &&
|
||||
isTopNavModuleVisible('keyManagement') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/key-management');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(120,53,15,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,243,199,1), rgba(255,237,213,1))',
|
||||
}}
|
||||
>
|
||||
<Key
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(251,191,36,1)'
|
||||
: 'rgba(217,119,6,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('秘钥管理')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('查看和管理API秘钥')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
<div
|
||||
className='my-2 border-t'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dropdown.Item
|
||||
onClick={logout}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(127,29,29,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,226,226,1), rgba(255,228,230,1))',
|
||||
}}
|
||||
>
|
||||
<LogOut
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(248,113,113,1)'
|
||||
: 'rgba(220,38,38,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('退出登录')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('安全退出账户')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='flex items-center gap-2 !pl-1.5 !pr-2.5 !py-1.5 !h-10 !rounded-full hover:!bg-brand/10 dark:hover:!bg-brand/15 !bg-transparent !transition-all !duration-200 hover:!-translate-y-0.5 group'
|
||||
>
|
||||
<div className='relative'>
|
||||
<Avatar
|
||||
size='small'
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-7 !h-7 !text-xs ring-2 ring-white dark:ring-gray-800 group-hover:!ring-brand/40 dark:group-hover:!ring-brand/50 transition-all'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
</Avatar>
|
||||
{/* 在线状态点 */}
|
||||
<span className='absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-emerald-500 border-2 border-white dark:border-gray-800 rounded-full' />
|
||||
</div>
|
||||
<span className='hidden md:flex flex-col items-start'>
|
||||
<Typography.Text
|
||||
className='!text-sm !font-medium !leading-none'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</Typography.Text>
|
||||
</span>
|
||||
<ChevronDown
|
||||
size={14}
|
||||
style={{
|
||||
color: isDark ? 'rgba(209,213,219,1)' : 'rgba(156,163,175,1)',
|
||||
}}
|
||||
className='group-hover:!opacity-80 transition-colors'
|
||||
/>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
);
|
||||
} else {
|
||||
if (isAuthPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showRegisterButton = !isSelfUseMode;
|
||||
|
||||
const commonSizingAndLayoutClass =
|
||||
'flex items-center justify-center !py-[10px] !px-1.5';
|
||||
|
||||
const loginButtonSpecificStyling =
|
||||
'!bg-transparent hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep !transition-all !duration-200';
|
||||
let loginButtonClasses = `${commonSizingAndLayoutClass} ${loginButtonSpecificStyling}`;
|
||||
|
||||
let registerButtonClasses = `${commonSizingAndLayoutClass}`;
|
||||
|
||||
const loginButtonTextSpanClass =
|
||||
'!text-xs !text-semi-color-text-1 dark:!text-gray-300 !p-1.5';
|
||||
const registerButtonTextSpanClass = '!text-xs !text-white !p-1.5';
|
||||
|
||||
if (showRegisterButton) {
|
||||
if (isMobile) {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-l-full !rounded-r-none';
|
||||
}
|
||||
registerButtonClasses += ' !rounded-r-full !rounded-l-none';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex items-center'>
|
||||
<Link to='/org/login' className='flex'>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className={loginButtonClasses}
|
||||
>
|
||||
<span className={loginButtonTextSpanClass}>{t('登录')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
{showRegisterButton && (
|
||||
<div className='hidden md:block'>
|
||||
<Link to='/register' className='flex -ml-px'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
className={registerButtonClasses}
|
||||
>
|
||||
<span className={registerButtonTextSpanClass}>{t('注册')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default UserArea;
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { isAuthPagePath } from '../../../helpers';
|
||||
import { useHeaderBar } from '../../../hooks/common/useHeaderBar';
|
||||
import { useNotifications } from '../../../hooks/common/useNotifications';
|
||||
import { useNavigation } from '../../../hooks/common/useNavigation';
|
||||
import NoticeModal from '../NoticeModal';
|
||||
import MobileMenuButton from './MobileMenuButton';
|
||||
import HeaderLogo from './HeaderLogo';
|
||||
import Navigation from './Navigation';
|
||||
import MobileNavMenu from './MobileNavMenu';
|
||||
import ActionButtons from './ActionButtons';
|
||||
|
||||
const HeaderBar = ({ onMobileMenuToggle, drawerOpen }) => {
|
||||
const location = useLocation();
|
||||
// 认证页(登录/注册/企业登录等)顶栏按行业惯例最小化:
|
||||
// 隐藏主导航与需登录态的操作按钮,只保留 logo + 主题切换等基础工具
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
const {
|
||||
userState,
|
||||
statusState,
|
||||
isMobile,
|
||||
collapsed,
|
||||
logoLoaded,
|
||||
currentLang,
|
||||
isLoading,
|
||||
systemName,
|
||||
logo,
|
||||
isNewYear,
|
||||
isSelfUseMode,
|
||||
docsLink,
|
||||
isDemoSiteMode,
|
||||
isConsoleRoute,
|
||||
theme,
|
||||
headerNavModules,
|
||||
sidebarModulesAdmin,
|
||||
showOrgEntry,
|
||||
orgEntryPath,
|
||||
isOrgUser,
|
||||
logout,
|
||||
handleLanguageChange,
|
||||
handleThemeToggle,
|
||||
handleMobileMenuToggle,
|
||||
navigate,
|
||||
t,
|
||||
} = useHeaderBar({ onMobileMenuToggle, drawerOpen });
|
||||
|
||||
const {
|
||||
noticeVisible,
|
||||
unreadCount,
|
||||
handleNoticeOpen,
|
||||
handleNoticeClose,
|
||||
getUnreadKeys,
|
||||
} = useNotifications(statusState);
|
||||
|
||||
const userRole = userState?.user?.role || 0;
|
||||
const userGroup = userState?.user?.group || 'default';
|
||||
const { mainNavLinks } = useNavigation(
|
||||
t,
|
||||
docsLink,
|
||||
headerNavModules,
|
||||
userRole,
|
||||
userGroup,
|
||||
{ showOrgEntry, orgEntryPath },
|
||||
);
|
||||
|
||||
return (
|
||||
<header className='text-semi-color-text-0 sticky top-0 z-50 transition-all duration-300 relative'>
|
||||
{/* ===== BACKGROUND LAYERS ===== */}
|
||||
|
||||
{/* Main gradient background with glassmorphism */}
|
||||
<div className='absolute inset-0 bg-gradient-to-r from-slate-50/95 via-white/90 to-slate-50/95 dark:from-slate-900/95 dark:via-neutral-900/90 dark:to-slate-900/95 backdrop-blur-xl' />
|
||||
|
||||
{/* Animated gradient accent - top edge */}
|
||||
<div className='absolute top-0 left-0 right-0 h-[2px] bg-gradient-to-r from-brand-from via-brand-via to-brand-to opacity-80' />
|
||||
|
||||
{/* Subtle animated gradient orbs */}
|
||||
<div className='absolute -top-20 -left-20 w-40 h-40 bg-gradient-to-br from-brand-from/20 to-brand-to/10 dark:from-brand-from/10 dark:to-brand-to/5 rounded-full blur-3xl pointer-events-none' />
|
||||
<div className='absolute -top-20 -right-20 w-40 h-40 bg-gradient-to-bl from-brand-via/20 to-brand-to/10 dark:from-brand-via/10 dark:to-brand-to/5 rounded-full blur-3xl pointer-events-none' />
|
||||
<div className='absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-96 h-20 bg-gradient-to-r from-brand-from/5 via-brand-via/10 to-brand-to/5 dark:from-brand-from/5 dark:via-brand-via/5 dark:to-brand-to/5 rounded-full blur-2xl pointer-events-none' />
|
||||
|
||||
{/* Bottom border with gradient */}
|
||||
<div className='absolute bottom-0 left-0 right-0 h-[1px] bg-gradient-to-r from-transparent via-gray-200/80 to-transparent dark:via-neutral-700/50' />
|
||||
|
||||
{/* Subtle shimmer effect */}
|
||||
<div
|
||||
className='absolute inset-0 bg-gradient-to-r from-transparent via-white/5 to-transparent dark:via-white/[0.02] animate-shimmer pointer-events-none'
|
||||
style={{ backgroundSize: '200% 100%' }}
|
||||
/>
|
||||
|
||||
{/* ===== CONTENT ===== */}
|
||||
<NoticeModal
|
||||
visible={noticeVisible}
|
||||
onClose={handleNoticeClose}
|
||||
isMobile={isMobile}
|
||||
defaultTab={unreadCount > 0 ? 'system' : 'inApp'}
|
||||
unreadKeys={getUnreadKeys()}
|
||||
/>
|
||||
|
||||
<div className='relative w-full px-2 sm:px-3 md:px-4'>
|
||||
{/* 高度断点必须用 md(768) 而非 sm(640):PageLayout 的 headerBarHeight 按
|
||||
MOBILE_BREAKPOINT=768 算 56/64,用 sm 会让 640~767px 区间实际 64px、
|
||||
而侧栏 top、抽屉遮罩 top 全按 56px 定位,差 8px。 */}
|
||||
<div className='flex items-center justify-between gap-1 md:gap-0 h-14 md:h-16'>
|
||||
<div className='flex items-center min-w-0 md:min-w-[auto]'>
|
||||
<MobileMenuButton
|
||||
isConsoleRoute={isConsoleRoute}
|
||||
isMobile={isMobile}
|
||||
drawerOpen={drawerOpen}
|
||||
collapsed={collapsed}
|
||||
onToggle={handleMobileMenuToggle}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<HeaderLogo
|
||||
isMobile={isMobile}
|
||||
isConsoleRoute={isConsoleRoute}
|
||||
logo={logo}
|
||||
logoLoaded={logoLoaded}
|
||||
isLoading={isLoading}
|
||||
systemName={systemName}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
isDemoSiteMode={isDemoSiteMode}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
{/* 移动端:主导航收进下拉菜单,避免与右侧操作区互相挤压 */}
|
||||
{!isAuthPage && isMobile && !isLoading && (
|
||||
<MobileNavMenu
|
||||
mainNavLinks={mainNavLinks}
|
||||
userState={userState}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!isAuthPage && !isMobile && (
|
||||
<Navigation
|
||||
mainNavLinks={mainNavLinks}
|
||||
isMobile={isMobile}
|
||||
isLoading={isLoading}
|
||||
userState={userState}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ActionButtons
|
||||
isAuthPage={isAuthPage}
|
||||
isNewYear={isNewYear}
|
||||
unreadCount={unreadCount}
|
||||
onNoticeOpen={handleNoticeOpen}
|
||||
theme={theme}
|
||||
onThemeToggle={handleThemeToggle}
|
||||
currentLang={currentLang}
|
||||
onLanguageChange={handleLanguageChange}
|
||||
userState={userState}
|
||||
isLoading={isLoading}
|
||||
isMobile={isMobile}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
headerNavModules={headerNavModules}
|
||||
sidebarModulesAdmin={sidebarModulesAdmin}
|
||||
isOrgUser={isOrgUser}
|
||||
logout={logout}
|
||||
navigate={navigate}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* CSS for shimmer animation */}
|
||||
<style>{`
|
||||
@keyframes shimmer {
|
||||
0% { background-position: -200% 0; }
|
||||
100% { background-position: 200% 0; }
|
||||
}
|
||||
.animate-shimmer {
|
||||
animation: shimmer 8s ease-in-out infinite;
|
||||
}
|
||||
`}</style>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
export default HeaderBar;
|
||||
Reference in New Issue
Block a user