/* 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 . For commercial licensing, please contact support@quantumnous.com */ import React, { useState, useContext } from 'react'; import { Link } from 'react-router-dom'; import { isMiniProgramWebView } from '../../../helpers/miniProgram'; import { Button as AntButton, Divider, Tooltip } from 'antd'; import { Share2, BookOpen, Download, Wallet } 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, 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 actionIcon = (Icon) => ; return (
{/* Tutorial Button - 新手教程按钮 (桌面端显示) */} {isLoggedIn && isButtonVisible('tutorial') && ( {!isMobile && t('新手教程')} )} {/* Promotion Button - 推广按钮 (桌面端显示) */} {isLoggedIn && isButtonVisible('pricing') && ( setPromotionVisible(true)} > {!isMobile && t('推广')} )} {/* WeyAi 桌面端下载 - 有 WeyAi 访问权限且下载页已开放时显示 (桌面端显示) */} {showWeyAiDownload && ( {!isMobile && t('下载 WeyAi')} )} {/* Recharge Button - 充值按钮 */} {isButtonVisible('recharge') && !isMiniProgramWebView() && ( {!isMobile && t('充值')} )} setPromotionVisible(false)} /> {/* Divider:原型仅在主操作与工具按钮之间保留一条竖线 */} {hasPrimaryActions && hasUtilityActions && ( )} {isActionVisible('newYear') && ( )} {isActionVisible('theme') && ( )} {/* 系统公告:原型位于主题与语言之间 */} {isActionVisible('notifications') && ( )} {languageSwitchEnabled && ( )}
); }; export default ActionButtons;