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

113 lines
3.2 KiB
JavaScript
Raw Normal View History

2024-03-15 16:05:33 +08:00
import React, { useEffect, useState } from 'react';
import { Card, Spin } from '@douyinfe/semi-ui';
import SettingsGeneral from '../../pages/Setting/Operation/SettingsGeneral.js';
import SettingsSensitiveWords from '../../pages/Setting/Operation/SettingsSensitiveWords.js';
import SettingsLog from '../../pages/Setting/Operation/SettingsLog.js';
import SettingsMonitoring from '../../pages/Setting/Operation/SettingsMonitoring.js';
import SettingsCreditLimit from '../../pages/Setting/Operation/SettingsCreditLimit.js';
import { API, showError, toBoolean } from '../../helpers';
const OperationSetting = () => {
2024-03-15 16:05:33 +08:00
let [inputs, setInputs] = useState({
/* 额度相关 */
2024-03-15 16:05:33 +08:00
QuotaForNewUser: 0,
PreConsumedQuota: 0,
2024-03-15 16:05:33 +08:00
QuotaForInviter: 0,
QuotaForInvitee: 0,
/* 通用设置 */
2024-03-15 16:05:33 +08:00
TopUpLink: '',
'general_setting.docs_link': '',
2024-03-15 16:05:33 +08:00
QuotaPerUnit: 0,
RetryTimes: 0,
2024-05-08 14:57:36 +08:00
DisplayInCurrencyEnabled: false,
DisplayTokenStatEnabled: false,
DefaultCollapseSidebar: false,
DemoSiteEnabled: false,
SelfUseModeEnabled: false,
/* 敏感词设置 */
CheckSensitiveEnabled: false,
CheckSensitiveOnPromptEnabled: false,
SensitiveWords: '',
/* 日志设置 */
LogConsumeEnabled: false,
/* 监控设置 */
ChannelDisableThreshold: 0,
QuotaRemindThreshold: 0,
AutomaticDisableChannelEnabled: false,
AutomaticEnableChannelEnabled: false,
AutomaticDisableKeywords: '',
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-05-08 14:57:36 +08:00
if (
item.key.endsWith('Enabled') ||
['DefaultCollapseSidebar'].includes(item.key)
2024-05-08 14:57:36 +08:00
) {
newInputs[item.key] = toBoolean(item.value);
2024-05-08 14:57:36 +08:00
} 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('刷新成功');
2024-05-13 17:55:15 +08:00
} catch (error) {
showError('刷新失败');
} finally {
setLoading(false);
}
}
2024-03-15 16:05:33 +08:00
useEffect(() => {
2024-05-13 18:14:57 +08:00
onRefresh();
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' }}>
2024-05-13 18:14:57 +08:00
<SettingsGeneral options={inputs} refresh={onRefresh} />
2024-05-13 17:55:15 +08:00
</Card>
{/* 屏蔽词过滤设置 */}
<Card style={{ marginTop: '10px' }}>
2024-05-13 18:14:57 +08:00
<SettingsSensitiveWords options={inputs} refresh={onRefresh} />
2024-05-13 17:55:15 +08:00
</Card>
{/* 日志设置 */}
<Card style={{ marginTop: '10px' }}>
2024-05-13 18:14:57 +08:00
<SettingsLog options={inputs} refresh={onRefresh} />
2024-05-13 17:55:15 +08:00
</Card>
{/* 监控设置 */}
<Card style={{ marginTop: '10px' }}>
2024-05-13 18:14:57 +08:00
<SettingsMonitoring options={inputs} refresh={onRefresh} />
2024-05-13 17:55:15 +08:00
</Card>
{/* 额度设置 */}
<Card style={{ marginTop: '10px' }}>
2024-05-13 18:14:57 +08:00
<SettingsCreditLimit options={inputs} refresh={onRefresh} />
2024-05-13 17:55:15 +08:00
</Card>
</Spin>
2024-05-08 14:57:36 +08:00
</>
2024-03-23 21:24:39 +08:00
);
};
export default OperationSetting;