Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

190 строки
6.4 KiB

  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState } from 'react';
  16. import { Card, Spin } from '@douyinfe/semi-ui';
  17. import { useTranslation } from 'react-i18next';
  18. import SettingsGeneral from '../../pages/Setting/Operation/SettingsGeneral';
  19. import SettingsHeaderNavModules from '../../pages/Setting/Operation/SettingsHeaderNavModules';
  20. import SettingsSidebarModulesAdmin from '../../pages/Setting/Operation/SettingsSidebarModulesAdmin';
  21. import SettingsSensitiveWords from '../../pages/Setting/Operation/SettingsSensitiveWords';
  22. import SettingsLog from '../../pages/Setting/Operation/SettingsLog';
  23. import SettingsMonitoring from '../../pages/Setting/Operation/SettingsMonitoring';
  24. import SettingsCreditLimit from '../../pages/Setting/Operation/SettingsCreditLimit';
  25. import SettingsCheckin from '../../pages/Setting/Operation/SettingsCheckin';
  26. import SettingsRegionSync from '../../pages/Setting/Operation/SettingsRegionSync';
  27. import { API, showError, toBoolean } from '../../helpers';
  28. const OperationSetting = () => {
  29. const { t } = useTranslation();
  30. let [inputs, setInputs] = useState({
  31. /* 额度相关 */
  32. QuotaForNewUser: 0,
  33. PreConsumedQuota: 0,
  34. QuotaForInviter: 0,
  35. QuotaForInvitee: 0,
  36. 'quota_setting.enable_free_model_pre_consume': true,
  37. /* 通用设置 */
  38. TopUpLink: '',
  39. 'general_setting.docs_link': '',
  40. QuotaPerUnit: 0,
  41. USDExchangeRate: 0,
  42. RetryTimes: 0,
  43. 'general_setting.quota_display_type': 'USD',
  44. DisplayTokenStatEnabled: false,
  45. DefaultCollapseSidebar: false,
  46. DemoSiteEnabled: false,
  47. SelfUseModeEnabled: false,
  48. /* 顶栏模块管理 */
  49. HeaderNavModules: '',
  50. /* 左侧边栏模块管理(管理员) */
  51. SidebarModulesAdmin: '',
  52. /* 敏感词设置 */
  53. CheckSensitiveEnabled: false,
  54. CheckSensitiveOnPromptEnabled: false,
  55. SensitiveWords: '',
  56. /* 日志设置 */
  57. LogConsumeEnabled: false,
  58. /* 监控设置 */
  59. ChannelDisableThreshold: 0,
  60. QuotaRemindThreshold: 0,
  61. AutomaticDisableChannelEnabled: false,
  62. AutomaticEnableChannelEnabled: false,
  63. AutomaticDisableKeywords: '',
  64. AutomaticDisableStatusCodes: '401',
  65. AutomaticRetryStatusCodes:
  66. '100-199,300-399,401-407,409-499,500-503,505-523,525-599',
  67. 'monitor_setting.auto_test_channel_enabled': false,
  68. 'monitor_setting.auto_test_channel_minutes': 10 /* 签到设置 */,
  69. 'checkin_setting.enabled': false,
  70. 'checkin_setting.min_quota': 1000,
  71. 'checkin_setting.max_quota': 10000,
  72. /* 跨区域同步设置 */
  73. 'region_sync.enabled': false,
  74. 'region_sync.region_id': '',
  75. 'region_sync.is_master': false,
  76. 'region_sync.master_endpoint': '',
  77. 'region_sync.slave_endpoints': '',
  78. 'region_sync.sync_api_key': '',
  79. 'region_sync.min_balance_threshold': 100000,
  80. 'region_sync.sync_interval_seconds': 60,
  81. 'region_sync.max_retry_count': 3,
  82. 'region_sync.sync_batch_size': 100,
  83. 'region_sync.quota_sync_interval_seconds': 300,
  84. 'region_sync.disable_cached_consume': false,
  85. /* 令牌设置 */
  86. 'token_setting.max_user_tokens': 1000,
  87. });
  88. let [loading, setLoading] = useState(false);
  89. const getOptions = async () => {
  90. const res = await API.get('/api/option/');
  91. const { success, message, data } = res.data;
  92. if (success) {
  93. let apiInputs = {};
  94. data.forEach((item) => {
  95. // 只处理已知字段,避免添加未知字段
  96. if (inputs.hasOwnProperty(item.key)) {
  97. if (typeof inputs[item.key] === 'boolean') {
  98. apiInputs[item.key] = toBoolean(item.value);
  99. } else if (typeof inputs[item.key] === 'number') {
  100. apiInputs[item.key] = parseFloat(item.value) || 0;
  101. } else {
  102. apiInputs[item.key] = item.value;
  103. }
  104. }
  105. });
  106. // 合并 API 数据和初始默认值
  107. setInputs((prevInputs) => ({ ...prevInputs, ...apiInputs }));
  108. } else {
  109. showError(message);
  110. }
  111. };
  112. async function onRefresh() {
  113. try {
  114. setLoading(true);
  115. await getOptions();
  116. // showSuccess('刷新成功');
  117. } catch (error) {
  118. showError(t('刷新失败'));
  119. } finally {
  120. setLoading(false);
  121. }
  122. }
  123. useEffect(() => {
  124. onRefresh();
  125. }, []);
  126. return (
  127. <>
  128. <Spin spinning={loading} size='large'>
  129. {/* 通用设置 */}
  130. <Card style={{ marginTop: '10px' }}>
  131. <SettingsGeneral options={inputs} refresh={onRefresh} />
  132. </Card>
  133. {/* 顶栏模块管理 */}
  134. <div style={{ marginTop: '10px' }}>
  135. <SettingsHeaderNavModules options={inputs} refresh={onRefresh} />
  136. </div>
  137. {/* 左侧边栏模块管理(管理员) */}
  138. <div style={{ marginTop: '10px' }}>
  139. <SettingsSidebarModulesAdmin options={inputs} refresh={onRefresh} />
  140. </div>
  141. {/* 屏蔽词过滤设置 */}
  142. <Card style={{ marginTop: '10px' }}>
  143. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  144. </Card>
  145. {/* 日志设置 */}
  146. <Card style={{ marginTop: '10px' }}>
  147. <SettingsLog options={inputs} refresh={onRefresh} />
  148. </Card>
  149. {/* 监控设置 */}
  150. <Card style={{ marginTop: '10px' }}>
  151. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  152. </Card>
  153. {/* 额度设置 */}
  154. <Card style={{ marginTop: '10px' }}>
  155. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  156. </Card>
  157. {/* 签到设置 */}
  158. <Card style={{ marginTop: '10px' }}>
  159. <SettingsCheckin options={inputs} refresh={onRefresh} />
  160. </Card>
  161. {/* 跨区域同步设置 */}
  162. <Card style={{ marginTop: '10px' }}>
  163. <SettingsRegionSync options={inputs} refresh={onRefresh} />
  164. </Card>
  165. </Spin>
  166. </>
  167. );
  168. };
  169. export default OperationSetting;