Files
monkey-ai-web/src/components/settings/WeyAiSetting.jsx
T
zhanjunhao 8a48765a46 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

88 lines
2.9 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 系统设置 →「WeyAi」页签(M21)。WeyAi 的所有配置项都放在这个页签下,按子页签分组;
// 子页签记在地址的 sub 参数里(如 ?tab=weyai&sub=storage),可以直接分享链接。
//
// 「账号接入」「内容存储」只对超级管理员显示,后端同样按 root-only 校验;
// 「内容管理」「版本说明」root 和被下放了「WeyAi」页签的管理员都能用。
import React, { useEffect, useMemo } from 'react';
import { Empty, TabPane, Tabs } from '@/components/ui';
import { useLocation, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { isAdmin, isRoot } from '../../helpers';
import SettingsWeyAi from '../../pages/Setting/WeyAi/SettingsWeyAi';
import SettingsWeyAiContent from '../../pages/Setting/WeyAi/SettingsWeyAiContent';
import SettingsWeyAiContentStorage from '../../pages/Setting/WeyAi/SettingsWeyAiContentStorage';
import SettingsWeyAiReleaseNotes from '../../pages/Setting/WeyAi/SettingsWeyAiReleaseNotes';
const WeyAiSetting = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const subTabs = useMemo(() => {
const tabs = [];
if (isRoot()) {
tabs.push({
key: 'account',
label: t('账号接入'),
content: <SettingsWeyAi />,
});
}
// 能打开这个页签的普通管理员一定是被下放了「WeyAi」页签的(见 Setting/index.jsx)
if (isRoot() || isAdmin()) {
tabs.push({
key: 'content',
label: t('内容管理'),
content: <SettingsWeyAiContent />,
});
tabs.push({
key: 'release-notes',
label: t('版本说明'),
content: <SettingsWeyAiReleaseNotes />,
});
}
if (isRoot()) {
tabs.push({
key: 'storage',
label: t('内容存储'),
content: <SettingsWeyAiContentStorage />,
});
}
return tabs;
}, [t]);
const requested = new URLSearchParams(location.search).get('sub');
const active = subTabs.some((tab) => tab.key === requested)
? requested
: subTabs[0]?.key;
// 地址里没有 sub、或 sub 不存在时改写成当前子页签,刷新和分享都落在同一处
useEffect(() => {
if (active && requested !== active) {
navigate(`?tab=weyai&sub=${active}`, { replace: true });
}
}, [active, requested, navigate]);
if (subTabs.length === 0) {
return (
<Empty className='mt-8' description={t('暂无你可以管理的 WeyAi 配置')} />
);
}
return (
<Tabs
type='line'
activeKey={active}
onChange={(key) => navigate(`?tab=weyai&sub=${key}`)}
>
{subTabs.map((tab) => (
<TabPane itemKey={tab.key} tab={tab.label} key={tab.key}>
{active === tab.key && <div className='mt-2'>{tab.content}</div>}
</TabPane>
))}
</Tabs>
);
};
export default WeyAiSetting;