OperationSetting.js 3.9 KB

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