Files
new-api/web/src/components/OperationSetting.js

148 lines
4.4 KiB
JavaScript
Raw Normal View History

2024-03-15 16:05:33 +08:00
import React, { useEffect, useState } from 'react';
import { Divider, Form, Grid, Header } from 'semantic-ui-react';
2024-05-13 17:55:15 +08:00
import { Card, Spin } from '@douyinfe/semi-ui';
import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js';
import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js';
import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js';
2024-05-11 14:06:32 +08:00
import SettingsLog from '../pages/Setting/Operation/SettingsLog.js';
import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js';
2024-05-11 17:20:18 +08:00
import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js';
2024-05-11 17:48:05 +08:00
import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.js';
2024-05-13 17:55:15 +08:00
import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js';
2024-03-23 21:24:39 +08:00
import {
API,
showError,
showSuccess,
timestamp2string,
verifyJSON,
} from '../helpers';
const OperationSetting = () => {
2024-03-15 16:05:33 +08:00
let [inputs, setInputs] = useState({
QuotaForNewUser: 0,
QuotaForInviter: 0,
QuotaForInvitee: 0,
QuotaRemindThreshold: 0,
PreConsumedQuota: 0,
2024-03-20 20:15:32 +08:00
StreamCacheQueueLength: 0,
2024-03-15 16:05:33 +08:00
ModelRatio: '',
CompletionRatio: '',
2024-03-15 16:05:33 +08:00
ModelPrice: '',
GroupRatio: '',
TopUpLink: '',
ChatLink: '',
ChatLink2: '', // 添加的新状态变量
QuotaPerUnit: 0,
2024-05-11 17:20:18 +08:00
AutomaticDisableChannelEnabled: false,
AutomaticEnableChannelEnabled: false,
2024-03-15 16:05:33 +08:00
ChannelDisableThreshold: 0,
2024-05-11 14:06:32 +08:00
LogConsumeEnabled: false,
2024-05-08 14:57:36 +08:00
DisplayInCurrencyEnabled: false,
DisplayTokenStatEnabled: false,
2024-05-11 14:06:32 +08:00
CheckSensitiveEnabled: false,
CheckSensitiveOnPromptEnabled: false,
2024-03-20 17:07:42 +08:00
CheckSensitiveOnCompletionEnabled: '',
StopOnSensitiveEnabled: '',
SensitiveWords: '',
2024-05-11 14:06:32 +08:00
MjNotifyEnabled: false,
MjAccountFilterEnabled: false,
MjModeClearEnabled: false,
MjForwardUrlEnabled: false,
DrawingEnabled: false,
DataExportEnabled: false,
2024-03-15 16:05:33 +08:00
DataExportDefaultTime: 'hour',
DataExportInterval: 5,
2024-05-08 14:57:36 +08:00
DefaultCollapseSidebar: false, // 默认折叠侧边栏
2024-03-23 21:24:39 +08:00
RetryTimes: 0,
2024-03-15 16:05:33 +08:00
});
2024-05-13 17:55:15 +08:00
2024-03-15 16:05:33 +08:00
let [loading, setLoading] = useState(false);
2024-03-15 16:05:33 +08:00
const getOptions = async () => {
const res = await API.get('/api/option/');
const { success, message, data } = res.data;
if (success) {
let newInputs = {};
data.forEach((item) => {
2024-03-23 21:24:39 +08:00
if (
item.key === 'ModelRatio' ||
item.key === 'GroupRatio' ||
item.key === 'CompletionRatio' ||
2024-03-23 21:24:39 +08:00
item.key === 'ModelPrice'
) {
2024-03-15 16:05:33 +08:00
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
}
2024-05-08 14:57:36 +08:00
if (
item.key.endsWith('Enabled') ||
['DefaultCollapseSidebar'].includes(item.key)
) {
newInputs[item.key] = item.value === 'true' ? true : false;
} else {
newInputs[item.key] = item.value;
}
2024-03-15 16:05:33 +08:00
});
2024-05-08 14:57:36 +08:00
2024-03-15 16:05:33 +08:00
setInputs(newInputs);
} else {
showError(message);
}
};
2024-05-13 17:55:15 +08:00
async function onRefresh() {
try {
setLoading(true);
await getOptions();
showSuccess('刷新成功');
} catch (error) {
showError('刷新失败');
} finally {
setLoading(false);
}
}
2024-03-15 16:05:33 +08:00
useEffect(() => {
2024-05-13 17:55:15 +08:00
getOptions();
2024-03-15 16:05:33 +08:00
}, []);
2024-03-15 16:05:33 +08:00
return (
2024-05-08 14:57:36 +08:00
<>
2024-05-13 17:55:15 +08:00
<Spin spinning={loading} size='large'>
{/* 通用设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsGeneral options={inputs} />
</Card>
{/* 绘图设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsDrawing options={inputs} />
</Card>
{/* 屏蔽词过滤设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsSensitiveWords options={inputs} />
</Card>
{/* 日志设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsLog options={inputs} />
</Card>
{/* 数据看板 */}
<Card style={{ marginTop: '10px' }}>
<SettingsDataDashboard options={inputs} />
</Card>
{/* 监控设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsMonitoring options={inputs} />
</Card>
{/* 额度设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsCreditLimit options={inputs} />
</Card>
{/* 倍率设置 */}
<Card style={{ marginTop: '10px' }}>
<SettingsMagnification options={inputs} />
</Card>
</Spin>
2024-05-08 14:57:36 +08:00
</>
2024-03-23 21:24:39 +08:00
);
};
export default OperationSetting;