OperationSetting.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React, { useEffect, useState } from 'react';
  2. import { Card, Spin } from '@douyinfe/semi-ui';
  3. import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js';
  4. import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js';
  5. import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js';
  6. import SettingsLog from '../pages/Setting/Operation/SettingsLog.js';
  7. import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js';
  8. import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js';
  9. import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.js';
  10. import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js';
  11. import { API, showError, showSuccess } from '../helpers';
  12. const OperationSetting = () => {
  13. let [inputs, setInputs] = useState({
  14. QuotaForNewUser: 0,
  15. QuotaForInviter: 0,
  16. QuotaForInvitee: 0,
  17. QuotaRemindThreshold: 0,
  18. PreConsumedQuota: 0,
  19. StreamCacheQueueLength: 0,
  20. ModelRatio: '',
  21. CompletionRatio: '',
  22. ModelPrice: '',
  23. GroupRatio: '',
  24. TopUpLink: '',
  25. ChatLink: '',
  26. ChatLink2: '', // 添加的新状态变量
  27. QuotaPerUnit: 0,
  28. AutomaticDisableChannelEnabled: false,
  29. AutomaticEnableChannelEnabled: false,
  30. ChannelDisableThreshold: 0,
  31. LogConsumeEnabled: false,
  32. DisplayInCurrencyEnabled: false,
  33. DisplayTokenStatEnabled: false,
  34. CheckSensitiveEnabled: false,
  35. CheckSensitiveOnPromptEnabled: false,
  36. CheckSensitiveOnCompletionEnabled: '',
  37. StopOnSensitiveEnabled: '',
  38. SensitiveWords: '',
  39. MjNotifyEnabled: false,
  40. MjAccountFilterEnabled: false,
  41. MjModeClearEnabled: false,
  42. MjForwardUrlEnabled: false,
  43. DrawingEnabled: false,
  44. DataExportEnabled: false,
  45. DataExportDefaultTime: 'hour',
  46. DataExportInterval: 5,
  47. DefaultCollapseSidebar: false, // 默认折叠侧边栏
  48. RetryTimes: 0,
  49. });
  50. let [loading, setLoading] = useState(false);
  51. const getOptions = async () => {
  52. const res = await API.get('/api/option/');
  53. const { success, message, data } = res.data;
  54. if (success) {
  55. let newInputs = {};
  56. data.forEach((item) => {
  57. if (
  58. item.key === 'ModelRatio' ||
  59. item.key === 'GroupRatio' ||
  60. item.key === 'CompletionRatio' ||
  61. item.key === 'ModelPrice'
  62. ) {
  63. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  64. }
  65. if (
  66. item.key.endsWith('Enabled') ||
  67. ['DefaultCollapseSidebar'].includes(item.key)
  68. ) {
  69. newInputs[item.key] = item.value === 'true' ? true : false;
  70. } else {
  71. newInputs[item.key] = item.value;
  72. }
  73. });
  74. setInputs(newInputs);
  75. } else {
  76. showError(message);
  77. }
  78. };
  79. async function onRefresh() {
  80. try {
  81. setLoading(true);
  82. await getOptions();
  83. showSuccess('刷新成功');
  84. } catch (error) {
  85. showError('刷新失败');
  86. } finally {
  87. setLoading(false);
  88. }
  89. }
  90. useEffect(() => {
  91. onRefresh();
  92. }, []);
  93. return (
  94. <>
  95. <Spin spinning={loading} size='large'>
  96. {/* 通用设置 */}
  97. <Card style={{ marginTop: '10px' }}>
  98. <SettingsGeneral options={inputs} refresh={onRefresh} />
  99. </Card>
  100. {/* 绘图设置 */}
  101. <Card style={{ marginTop: '10px' }}>
  102. <SettingsDrawing options={inputs} refresh={onRefresh} />
  103. </Card>
  104. {/* 屏蔽词过滤设置 */}
  105. <Card style={{ marginTop: '10px' }}>
  106. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  107. </Card>
  108. {/* 日志设置 */}
  109. <Card style={{ marginTop: '10px' }}>
  110. <SettingsLog options={inputs} refresh={onRefresh} />
  111. </Card>
  112. {/* 数据看板 */}
  113. <Card style={{ marginTop: '10px' }}>
  114. <SettingsDataDashboard options={inputs} refresh={onRefresh} />
  115. </Card>
  116. {/* 监控设置 */}
  117. <Card style={{ marginTop: '10px' }}>
  118. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  119. </Card>
  120. {/* 额度设置 */}
  121. <Card style={{ marginTop: '10px' }}>
  122. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  123. </Card>
  124. {/* 倍率设置 */}
  125. <Card style={{ marginTop: '10px' }}>
  126. <SettingsMagnification options={inputs} refresh={onRefresh} />
  127. </Card>
  128. </Spin>
  129. </>
  130. );
  131. };
  132. export default OperationSetting;