OperationSetting.jsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 'monitor_setting.auto_test_channel_enabled': false,
  62. 'monitor_setting.auto_test_channel_minutes': 10 /* 签到设置 */,
  63. 'checkin_setting.enabled': false,
  64. 'checkin_setting.min_quota': 1000,
  65. 'checkin_setting.max_quota': 10000,
  66. });
  67. let [loading, setLoading] = useState(false);
  68. const getOptions = async () => {
  69. const res = await API.get('/api/option/');
  70. const { success, message, data } = res.data;
  71. if (success) {
  72. let newInputs = {};
  73. data.forEach((item) => {
  74. if (typeof inputs[item.key] === 'boolean') {
  75. newInputs[item.key] = toBoolean(item.value);
  76. } else {
  77. newInputs[item.key] = item.value;
  78. }
  79. });
  80. setInputs(newInputs);
  81. } else {
  82. showError(message);
  83. }
  84. };
  85. async function onRefresh() {
  86. try {
  87. setLoading(true);
  88. await getOptions();
  89. // showSuccess('刷新成功');
  90. } catch (error) {
  91. showError('刷新失败');
  92. } finally {
  93. setLoading(false);
  94. }
  95. }
  96. useEffect(() => {
  97. onRefresh();
  98. }, []);
  99. return (
  100. <>
  101. <Spin spinning={loading} size='large'>
  102. {/* 通用设置 */}
  103. <Card style={{ marginTop: '10px' }}>
  104. <SettingsGeneral options={inputs} refresh={onRefresh} />
  105. </Card>
  106. {/* 顶栏模块管理 */}
  107. <div style={{ marginTop: '10px' }}>
  108. <SettingsHeaderNavModules options={inputs} refresh={onRefresh} />
  109. </div>
  110. {/* 左侧边栏模块管理(管理员) */}
  111. <div style={{ marginTop: '10px' }}>
  112. <SettingsSidebarModulesAdmin options={inputs} refresh={onRefresh} />
  113. </div>
  114. {/* 屏蔽词过滤设置 */}
  115. <Card style={{ marginTop: '10px' }}>
  116. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  117. </Card>
  118. {/* 日志设置 */}
  119. <Card style={{ marginTop: '10px' }}>
  120. <SettingsLog options={inputs} refresh={onRefresh} />
  121. </Card>
  122. {/* 监控设置 */}
  123. <Card style={{ marginTop: '10px' }}>
  124. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  125. </Card>
  126. {/* 额度设置 */}
  127. <Card style={{ marginTop: '10px' }}>
  128. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  129. </Card>
  130. {/* 签到设置 */}
  131. <Card style={{ marginTop: '10px' }}>
  132. <SettingsCheckin options={inputs} refresh={onRefresh} />
  133. </Card>
  134. </Spin>
  135. </>
  136. );
  137. };
  138. export default OperationSetting;