/* 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, { useContext, useEffect, useState } from 'react'; import { Layout, TabPane, Tabs } from '@douyinfe/semi-ui'; import { useNavigate, useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { StatusContext } from '../../context/Status'; import { getDelegatedSettingTabs } from '../../helpers/adminDelegation'; import { ALWAYS_ADMIN_VISIBLE_TABS, ROOT_ONLY_SETTING_TABS, } from '../../constants/settingTabs'; import { Settings, Calculator, Gauge, Shapes, Cog, MoreHorizontal, LayoutDashboard, MessageSquare, Palette, CreditCard, Coins, Crown, Headphones, Video, ShieldCheck, ShieldAlert, Layers, } from 'lucide-react'; import SystemSetting from '../../components/settings/SystemSetting'; import { isAdmin, isRoot } from '../../helpers'; import OtherSetting from '../../components/settings/OtherSetting'; import OperationSetting from '../../components/settings/OperationSetting'; import DataSecuritySetting from '../../components/settings/DataSecuritySetting'; import ContentGuardSetting from '../../components/settings/ContentGuardSetting'; import RateLimitSetting from '../../components/settings/RateLimitSetting'; import ModelSetting from '../../components/settings/ModelSetting'; import DashboardSetting from '../../components/settings/DashboardSetting'; import RatioSetting from '../../components/settings/RatioSetting'; import LevelPolicySetting from '../../components/settings/LevelPolicySetting'; import ChatsSetting from '../../components/settings/ChatsSetting'; import DrawingSetting from '../../components/settings/DrawingSetting'; import PaymentSetting from '../../components/settings/PaymentSetting'; import CustomerServiceSetting from '../../components/settings/CustomerServiceSetting'; import TutorialVideoSetting from '../../components/settings/TutorialVideoSetting'; import AmountOptionsManager from './AmountOptionsManager'; import SettingsMembership from './Payment/SettingsMembership'; import './Setting.css'; const Setting = () => { const { t } = useTranslation(); const navigate = useNavigate(); const location = useLocation(); const [statusState] = useContext(StatusContext); const [tabActiveKey, setTabActiveKey] = useState('1'); let panes = []; const membershipPane = { tab: ( {t('会员管理')} ), content: , itemKey: 'membership', }; // 先构建全部 tab,再按角色 + 下放配置过滤可见性(见下方)。 { panes.push({ tab: ( {t('运营设置')} ), content: , itemKey: 'operation', }); panes.push({ tab: ( {t('数据安全')} ), content: , itemKey: 'data-security', }); panes.push({ tab: ( {t('大模型内容防护')} ), content: , itemKey: 'content-guard', }); panes.push({ tab: ( {t('仪表盘设置')} ), content: , itemKey: 'dashboard', }); panes.push({ tab: ( {t('聊天设置')} ), content: , itemKey: 'chats', }); panes.push({ tab: ( {t('绘图设置')} ), content: , itemKey: 'drawing', }); panes.push({ tab: ( {t('支付设置')} ), content: , itemKey: 'payment', }); panes.push({ tab: ( {t('充值档位管理')} ), content: , itemKey: 'amount-options', }); panes.push({ tab: ( {t('企业充值档位')} ), content: ( ), itemKey: 'org-amount-options', }); panes.push(membershipPane); panes.push({ tab: ( {t('分组与模型定价设置')} ), content: , itemKey: 'ratio', }); panes.push({ tab: ( {t('等级与模型访问')} ), content: , itemKey: 'level_policy', }); panes.push({ tab: ( {t('速率限制设置')} ), content: , itemKey: 'ratelimit', }); panes.push({ tab: ( {t('模型相关设置')} ), content: , itemKey: 'models', }); panes.push({ tab: ( {t('客服设置')} ), content: , itemKey: 'customer-service', }); panes.push({ tab: ( ), content: , itemKey: 'tutorial-video', }); panes.push({ tab: ( {t('系统设置')} ), content: , itemKey: 'system', }); panes.push({ tab: ( {t('其他设置')} ), content: , itemKey: 'other', }); } // 解析 root 配置的「下放给普通管理员」tab 列表 const delegatedTabs = getDelegatedSettingTabs( statusState?.status?.AdminDelegatedSettingTabs, ); // 可见性过滤:root 看全部;普通管理员看「会员管理 + 被下放的 tab」;其余看不到。 if (!isRoot()) { if (isAdmin()) { const allowed = new Set([ ...ALWAYS_ADMIN_VISIBLE_TABS, ...delegatedTabs.filter((tab) => !ROOT_ONLY_SETTING_TABS.includes(tab)), ]); panes = panes.filter((pane) => allowed.has(pane.itemKey)); } else { panes = []; } } const onChangeTab = (key) => { setTabActiveKey(key); navigate(`?tab=${key}`); }; useEffect(() => { // 非 root 的可见 tab 依赖 status 中的下放配置;status 未加载前不要急于重定向, // 否则深链到「被下放 tab」会因 panes 尚未包含它而被错误重定向走。 if (!isRoot() && !statusState?.status) { return; } const searchParams = new URLSearchParams(window.location.search); const tab = searchParams.get('tab'); const preferredDefault = isRoot() ? 'operation' : 'membership'; const defaultTabKey = panes.some( (pane) => pane.itemKey === preferredDefault, ) ? preferredDefault : panes[0]?.itemKey; const tabExists = panes.some((pane) => pane.itemKey === tab); const nextTab = tab && tabExists ? tab : defaultTabKey; setTabActiveKey(nextTab); if (tab !== nextTab) { navigate(`?tab=${nextTab}`, { replace: true }); } }, [location.search, statusState?.status?.AdminDelegatedSettingTabs]); return (
onChangeTab(key)} > {panes.map((pane) => ( {tabActiveKey === pane.itemKey && pane.content} ))}
); }; export default Setting;