OperationSetting.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 SettingsGeneral from '../../pages/Setting/Operation/SettingsGeneral';
  18. import SettingsHeaderNavModules from '../../pages/Setting/Operation/SettingsHeaderNavModules';
  19. import SettingsSidebarModulesAdmin from '../../pages/Setting/Operation/SettingsSidebarModulesAdmin';
  20. import SettingsSensitiveWords from '../../pages/Setting/Operation/SettingsSensitiveWords';
  21. import SettingsLog from '../../pages/Setting/Operation/SettingsLog';
  22. import SettingsMonitoring from '../../pages/Setting/Operation/SettingsMonitoring';
  23. import SettingsCreditLimit from '../../pages/Setting/Operation/SettingsCreditLimit';
  24. import SettingsCheckin from '../../pages/Setting/Operation/SettingsCheckin';
  25. import { API, showError, toBoolean } from '../../helpers';
  26. const OperationSetting = () => {
  27. let [inputs, setInputs] = useState({
  28. /* 额度相关 */
  29. QuotaForNewUser: 0,
  30. PreConsumedQuota: 0,
  31. QuotaForInviter: 0,
  32. QuotaForInvitee: 0,
  33. 'quota_setting.enable_free_model_pre_consume': true,
  34. /* 通用设置 */
  35. TopUpLink: '',
  36. 'general_setting.docs_link': '',
  37. QuotaPerUnit: 0,
  38. USDExchangeRate: 0,
  39. RetryTimes: 0,
  40. 'general_setting.quota_display_type': 'USD',
  41. DisplayTokenStatEnabled: false,
  42. DefaultCollapseSidebar: false,
  43. DemoSiteEnabled: false,
  44. SelfUseModeEnabled: false,
  45. /* 顶栏模块管理 */
  46. HeaderNavModules: '',
  47. /* 左侧边栏模块管理(管理员) */
  48. SidebarModulesAdmin: '',
  49. /* 敏感词设置 */
  50. CheckSensitiveEnabled: false,
  51. CheckSensitiveOnPromptEnabled: false,
  52. SensitiveWords: '',
  53. /* 日志设置 */
  54. LogConsumeEnabled: false,
  55. /* 监控设置 */
  56. ChannelDisableThreshold: 0,
  57. QuotaRemindThreshold: 0,
  58. AutomaticDisableChannelEnabled: false,
  59. AutomaticEnableChannelEnabled: false,
  60. AutomaticDisableKeywords: '',
  61. AutomaticDisableStatusCodes: '401',
  62. AutomaticRetryStatusCodes: '100-199,300-399,401-407,409-499,500-503,505-523,525-599',
  63. 'monitor_setting.auto_test_channel_enabled': false,
  64. 'monitor_setting.auto_test_channel_minutes': 10 /* 签到设置 */,
  65. 'checkin_setting.enabled': false,
  66. 'checkin_setting.min_quota': 1000,
  67. 'checkin_setting.max_quota': 10000,
  68. });
  69. let [loading, setLoading] = useState(false);
  70. const getOptions = async () => {
  71. const res = await API.get('/api/option/');
  72. const { success, message, data } = res.data;
  73. if (success) {
  74. let newInputs = {};
  75. data.forEach((item) => {
  76. if (typeof inputs[item.key] === 'boolean') {
  77. newInputs[item.key] = toBoolean(item.value);
  78. } else {
  79. newInputs[item.key] = item.value;
  80. }
  81. });
  82. setInputs(newInputs);
  83. } else {
  84. showError(message);
  85. }
  86. };
  87. async function onRefresh() {
  88. try {
  89. setLoading(true);
  90. await getOptions();
  91. // showSuccess('刷新成功');
  92. } catch (error) {
  93. showError('刷新失败');
  94. } finally {
  95. setLoading(false);
  96. }
  97. }
  98. useEffect(() => {
  99. onRefresh();
  100. }, []);
  101. return (
  102. <>
  103. <Spin spinning={loading} size='large'>
  104. {/* 通用设置 */}
  105. <Card style={{ marginTop: '10px' }}>
  106. <SettingsGeneral options={inputs} refresh={onRefresh} />
  107. </Card>
  108. {/* 顶栏模块管理 */}
  109. <div style={{ marginTop: '10px' }}>
  110. <SettingsHeaderNavModules options={inputs} refresh={onRefresh} />
  111. </div>
  112. {/* 左侧边栏模块管理(管理员) */}
  113. <div style={{ marginTop: '10px' }}>
  114. <SettingsSidebarModulesAdmin options={inputs} refresh={onRefresh} />
  115. </div>
  116. {/* 屏蔽词过滤设置 */}
  117. <Card style={{ marginTop: '10px' }}>
  118. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  119. </Card>
  120. {/* 日志设置 */}
  121. <Card style={{ marginTop: '10px' }}>
  122. <SettingsLog options={inputs} refresh={onRefresh} />
  123. </Card>
  124. {/* 监控设置 */}
  125. <Card style={{ marginTop: '10px' }}>
  126. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  127. </Card>
  128. {/* 额度设置 */}
  129. <Card style={{ marginTop: '10px' }}>
  130. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  131. </Card>
  132. {/* 签到设置 */}
  133. <Card style={{ marginTop: '10px' }}>
  134. <SettingsCheckin options={inputs} refresh={onRefresh} />
  135. </Card>
  136. </Spin>
  137. </>
  138. );
  139. };
  140. export default OperationSetting;