OperationSetting.jsx 4.6 KB

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