OperationSetting.js 6.1 KB

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