OperationSetting.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React, { useEffect, useState } from 'react';
  2. import { Card, Spin, Tabs } 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 ModelSettingsVisualEditor from '../pages/Setting/Operation/ModelSettingsVisualEditor.js';
  12. import GroupRatioSettings from '../pages/Setting/Operation/GroupRatioSettings.js';
  13. import ModelRatioSettings from '../pages/Setting/Operation/ModelRatioSettings.js';
  14. import { API, showError, showSuccess } from '../helpers';
  15. import SettingsChats from '../pages/Setting/Operation/SettingsChats.js';
  16. import { useTranslation } from 'react-i18next';
  17. const OperationSetting = () => {
  18. const { t } = useTranslation();
  19. let [inputs, setInputs] = useState({
  20. QuotaForNewUser: 0,
  21. QuotaForInviter: 0,
  22. QuotaForInvitee: 0,
  23. QuotaRemindThreshold: 0,
  24. PreConsumedQuota: 0,
  25. StreamCacheQueueLength: 0,
  26. ModelRatio: '',
  27. CompletionRatio: '',
  28. ModelPrice: '',
  29. GroupRatio: '',
  30. UserUsableGroups: '',
  31. TopUpLink: '',
  32. ChatLink: '',
  33. ChatLink2: '', // 添加的新状态变量
  34. QuotaPerUnit: 0,
  35. AutomaticDisableChannelEnabled: false,
  36. AutomaticEnableChannelEnabled: false,
  37. ChannelDisableThreshold: 0,
  38. LogConsumeEnabled: false,
  39. DisplayInCurrencyEnabled: false,
  40. DisplayTokenStatEnabled: false,
  41. CheckSensitiveEnabled: false,
  42. CheckSensitiveOnPromptEnabled: false,
  43. CheckSensitiveOnCompletionEnabled: '',
  44. StopOnSensitiveEnabled: '',
  45. SensitiveWords: '',
  46. MjNotifyEnabled: false,
  47. MjAccountFilterEnabled: false,
  48. MjModeClearEnabled: false,
  49. MjForwardUrlEnabled: false,
  50. MjActionCheckSuccessEnabled: false,
  51. DrawingEnabled: false,
  52. DataExportEnabled: false,
  53. DataExportDefaultTime: 'hour',
  54. DataExportInterval: 5,
  55. DefaultCollapseSidebar: false, // 默认折叠侧边栏
  56. RetryTimes: 0,
  57. Chats: "[]",
  58. });
  59. let [loading, setLoading] = useState(false);
  60. const getOptions = async () => {
  61. const res = await API.get('/api/option/');
  62. const { success, message, data } = res.data;
  63. if (success) {
  64. let newInputs = {};
  65. data.forEach((item) => {
  66. if (
  67. item.key === 'ModelRatio' ||
  68. item.key === 'GroupRatio' ||
  69. item.key === 'UserUsableGroups' ||
  70. item.key === 'CompletionRatio' ||
  71. item.key === 'ModelPrice'
  72. ) {
  73. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  74. }
  75. if (
  76. item.key.endsWith('Enabled') ||
  77. ['DefaultCollapseSidebar'].includes(item.key)
  78. ) {
  79. newInputs[item.key] = item.value === 'true' ? true : false;
  80. } else {
  81. newInputs[item.key] = item.value;
  82. }
  83. });
  84. setInputs(newInputs);
  85. } else {
  86. showError(message);
  87. }
  88. };
  89. async function onRefresh() {
  90. try {
  91. setLoading(true);
  92. await getOptions();
  93. // showSuccess('刷新成功');
  94. } catch (error) {
  95. showError('刷新失败');
  96. } finally {
  97. setLoading(false);
  98. }
  99. }
  100. useEffect(() => {
  101. onRefresh();
  102. }, []);
  103. return (
  104. <>
  105. <Spin spinning={loading} size='large'>
  106. {/* 通用设置 */}
  107. <Card style={{ marginTop: '10px' }}>
  108. <SettingsGeneral options={inputs} refresh={onRefresh} />
  109. </Card>
  110. {/* 绘图设置 */}
  111. <Card style={{ marginTop: '10px' }}>
  112. <SettingsDrawing options={inputs} refresh={onRefresh} />
  113. </Card>
  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. <SettingsDataDashboard options={inputs} refresh={onRefresh} />
  125. </Card>
  126. {/* 监控设置 */}
  127. <Card style={{ marginTop: '10px' }}>
  128. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  129. </Card>
  130. {/* 额度设置 */}
  131. <Card style={{ marginTop: '10px' }}>
  132. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  133. </Card>
  134. {/* 聊天设置 */}
  135. <Card style={{ marginTop: '10px' }}>
  136. <SettingsChats options={inputs} refresh={onRefresh} />
  137. </Card>
  138. {/* 分组倍率设置 */}
  139. <Card style={{ marginTop: '10px' }}>
  140. <GroupRatioSettings options={inputs} refresh={onRefresh} />
  141. </Card>
  142. {/* 合并模型倍率设置和可视化倍率设置 */}
  143. <Card style={{ marginTop: '10px' }}>
  144. <Tabs type="line">
  145. <Tabs.TabPane tab={t('模型倍率设置')} itemKey="model">
  146. <ModelRatioSettings options={inputs} refresh={onRefresh} />
  147. </Tabs.TabPane>
  148. <Tabs.TabPane tab={t('可视化倍率设置')} itemKey="visual">
  149. <ModelSettingsVisualEditor options={inputs} refresh={onRefresh} />
  150. </Tabs.TabPane>
  151. </Tabs>
  152. </Card>
  153. </Spin>
  154. </>
  155. );
  156. };
  157. export default OperationSetting;