Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
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, 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 {
|
||||
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';
|
||||
|
||||
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: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Crown size={18} />
|
||||
{t('会员管理')}
|
||||
</span>
|
||||
),
|
||||
content: <SettingsMembership />,
|
||||
itemKey: 'membership',
|
||||
};
|
||||
|
||||
// 先构建全部 tab,再按角色 + 下放配置过滤可见性(见下方)。
|
||||
{
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Settings size={18} />
|
||||
{t('运营设置')}
|
||||
</span>
|
||||
),
|
||||
content: <OperationSetting />,
|
||||
itemKey: 'operation',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<ShieldCheck size={18} />
|
||||
{t('数据安全')}
|
||||
</span>
|
||||
),
|
||||
content: <DataSecuritySetting />,
|
||||
itemKey: 'data-security',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<ShieldAlert size={18} />
|
||||
{t('大模型内容防护')}
|
||||
</span>
|
||||
),
|
||||
content: <ContentGuardSetting />,
|
||||
itemKey: 'content-guard',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<LayoutDashboard size={18} />
|
||||
{t('仪表盘设置')}
|
||||
</span>
|
||||
),
|
||||
content: <DashboardSetting />,
|
||||
itemKey: 'dashboard',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<MessageSquare size={18} />
|
||||
{t('聊天设置')}
|
||||
</span>
|
||||
),
|
||||
content: <ChatsSetting />,
|
||||
itemKey: 'chats',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Palette size={18} />
|
||||
{t('绘图设置')}
|
||||
</span>
|
||||
),
|
||||
content: <DrawingSetting />,
|
||||
itemKey: 'drawing',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<CreditCard size={18} />
|
||||
{t('支付设置')}
|
||||
</span>
|
||||
),
|
||||
content: <PaymentSetting />,
|
||||
itemKey: 'payment',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Coins size={18} />
|
||||
{t('充值档位管理')}
|
||||
</span>
|
||||
),
|
||||
content: <AmountOptionsManager />,
|
||||
itemKey: 'amount-options',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Coins size={18} />
|
||||
{t('企业充值档位')}
|
||||
</span>
|
||||
),
|
||||
content: (
|
||||
<AmountOptionsManager
|
||||
apiPath='/api/user/payment/org-amount-options'
|
||||
title={t('企业充值档位管理')}
|
||||
/>
|
||||
),
|
||||
itemKey: 'org-amount-options',
|
||||
});
|
||||
panes.push(membershipPane);
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Calculator size={18} />
|
||||
{t('分组与模型定价设置')}
|
||||
</span>
|
||||
),
|
||||
content: <RatioSetting />,
|
||||
itemKey: 'ratio',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Layers size={18} />
|
||||
{t('等级与模型访问')}
|
||||
</span>
|
||||
),
|
||||
content: <LevelPolicySetting />,
|
||||
itemKey: 'level_policy',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Gauge size={18} />
|
||||
{t('速率限制设置')}
|
||||
</span>
|
||||
),
|
||||
content: <RateLimitSetting />,
|
||||
itemKey: 'ratelimit',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Shapes size={18} />
|
||||
{t('模型相关设置')}
|
||||
</span>
|
||||
),
|
||||
content: <ModelSetting />,
|
||||
itemKey: 'models',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Headphones size={18} />
|
||||
{t('客服设置')}
|
||||
</span>
|
||||
),
|
||||
content: <CustomerServiceSetting />,
|
||||
itemKey: 'customer-service',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Video size={18} />
|
||||
{t('教程视频管理')}
|
||||
</span>
|
||||
),
|
||||
content: <TutorialVideoSetting />,
|
||||
itemKey: 'tutorial-video',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<Cog size={18} />
|
||||
{t('系统设置')}
|
||||
</span>
|
||||
),
|
||||
content: <SystemSetting />,
|
||||
itemKey: 'system',
|
||||
});
|
||||
panes.push({
|
||||
tab: (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
||||
<MoreHorizontal size={18} />
|
||||
{t('其他设置')}
|
||||
</span>
|
||||
),
|
||||
content: <OtherSetting />,
|
||||
itemKey: 'other',
|
||||
});
|
||||
}
|
||||
|
||||
// 解析 root 配置的「下放给普通管理员」tab 列表
|
||||
let delegatedTabs = [];
|
||||
try {
|
||||
const raw = statusState?.status?.AdminDelegatedSettingTabs;
|
||||
if (raw) delegatedTabs = JSON.parse(raw);
|
||||
} catch (e) {
|
||||
delegatedTabs = [];
|
||||
}
|
||||
|
||||
// 可见性过滤: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 (
|
||||
<div className='mt-[60px] px-2'>
|
||||
<Layout>
|
||||
<Layout.Content>
|
||||
<Tabs
|
||||
type='card'
|
||||
collapsible
|
||||
activeKey={tabActiveKey}
|
||||
onChange={(key) => onChangeTab(key)}
|
||||
>
|
||||
{panes.map((pane) => (
|
||||
<TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
|
||||
{tabActiveKey === pane.itemKey && pane.content}
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Setting;
|
||||
Reference in New Issue
Block a user