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;