/*
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
*/
// 系统设置 →「WeyAi」页签(M21)。WeyAi 的所有配置项都放在这个页签下,按子页签分组;
// 子页签记在地址的 sub 参数里(如 ?tab=weyai&sub=storage),可以直接分享链接。
//
// 「账号接入」「内容存储」只对超级管理员显示,后端同样按 root-only 校验;
// 「内容管理」「版本说明」root 和被下放了「WeyAi」页签的管理员都能用。
import React, { useEffect, useMemo } from 'react';
import { Empty, TabPane, Tabs } from '@douyinfe/semi-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: ,
});
}
// 能打开这个页签的普通管理员一定是被下放了「WeyAi」页签的(见 Setting/index.jsx)
if (isRoot() || isAdmin()) {
tabs.push({
key: 'content',
label: t('内容管理'),
content: ,
});
tabs.push({
key: 'release-notes',
label: t('版本说明'),
content: ,
});
}
if (isRoot()) {
tabs.push({
key: 'storage',
label: t('内容存储'),
content: ,
});
}
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 (
);
}
return (
navigate(`?tab=weyai&sub=${key}`)}
>
{subTabs.map((tab) => (
{active === tab.key && {tab.content}
}
))}
);
};
export default WeyAiSetting;