import React, { useEffect, useState } from 'react'; import { Card, Spin, Tabs } from '@/components/ui'; import { useTranslation } from 'react-i18next'; import GroupRatioSettings from '../../pages/Setting/Ratio/GroupRatioSettings'; import ModelRatioSettings from '../../pages/Setting/Ratio/ModelRatioSettings'; import ModelSettingsVisualEditor from '../../pages/Setting/Ratio/ModelSettingsVisualEditor'; import ModelRatioNotSetEditor from '../../pages/Setting/Ratio/ModelRationNotSetEditor'; import UpstreamRatioSync from '../../pages/Setting/Ratio/UpstreamRatioSync'; import ModelOfficialPriceSettings from '../../pages/Setting/Ratio/ModelOfficialPriceSettings'; import ModelCostSettings from '../../pages/Setting/Ratio/ModelCostSettings'; import { API, isRoot, showError, toBoolean } from '../../helpers'; const RatioSetting = () => { const { t } = useTranslation(); let [inputs, setInputs] = useState({ ModelPrice: '', ModelRatio: '', CacheRatio: '', CompletionRatio: '', GroupRatio: '', GroupGroupRatio: '', ModelOfficialPrice: '', ImageRatio: '', AudioRatio: '', AudioCompletionRatio: '', AutoGroups: '', DefaultUseAutoGroup: false, ExposeRatioEnabled: false, UserUsableGroups: '', 'group_ratio_setting.group_special_usable_group': '', }); const [loading, setLoading] = useState(false); const [costVisited, setCostVisited] = useState(false); const getOptions = async () => { const res = await API.get('/api/option/'); const { success, message, data } = res.data; if (success) { let newInputs = {}; data.forEach((item) => { if (item.value.startsWith('{') || item.value.startsWith('[')) { try { item.value = JSON.stringify(JSON.parse(item.value), null, 2); } catch (e) { // 如果后端返回的不是合法 JSON,直接展示 } } if (['DefaultUseAutoGroup', 'ExposeRatioEnabled'].includes(item.key)) { newInputs[item.key] = toBoolean(item.value); } else { newInputs[item.key] = item.value; } }); setInputs(newInputs); } else { showError(message); } }; const onRefresh = async () => { try { setLoading(true); await getOptions(); } catch (error) { showError(t('刷新失败')); } finally { setLoading(false); } }; useEffect(() => { onRefresh(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( {/* 模型倍率设置以及可视化编辑器 */} { if (key === 'model_cost') setCostVisited(true); }} > {/* 原厂价 = 成本兜底基准、成本价 = 商业秘密:两个页签都只对 root 开放。 后端已分别由 delegationDeniedKeys 与整组 RootAuth 拦住,这里同步隐藏 入口——否则被下放 tab 的普通管理员会看到一个填了存不进去的页面。 */} {isRoot() && ( )} {isRoot() && ( {costVisited && } )} ); }; export default RatioSetting;