Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -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;
+202
View File
@@ -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;