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 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. import ModelRatioNotSetEditor from '../pages/Setting/Operation/ModelRationNotSetEditor.js';
  18. const OperationSetting = () => {
  19. const { t } = useTranslation();
  20. let [inputs, setInputs] = useState({
  21. QuotaForNewUser: 0,
  22. QuotaForInviter: 0,
  23. QuotaForInvitee: 0,
  24. QuotaRemindThreshold: 0,
  25. PreConsumedQuota: 0,
  26. StreamCacheQueueLength: 0,
  27. ModelRatio: '',
  28. CacheRatio: '',
  29. CompletionRatio: '',
  30. ModelPrice: '',
  31. GroupRatio: '',
  32. UserUsableGroups: '',
  33. TopUpLink: '',
  34. ChatLink: '',
  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 === 'UserUsableGroups' ||
  75. item.key === 'CompletionRatio' ||
  76. item.key === 'ModelPrice' ||
  77. item.key === 'CacheRatio'
  78. ) {
  79. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  80. }
  81. if (
  82. item.key.endsWith('Enabled') ||
  83. ['DefaultCollapseSidebar'].includes(item.key)
  84. ) {
  85. newInputs[item.key] = item.value === 'true' ? true : false;
  86. } else {
  87. newInputs[item.key] = item.value;
  88. }
  89. });
  90. setInputs(newInputs);
  91. } else {
  92. showError(message);
  93. }
  94. };
  95. async function onRefresh() {
  96. try {
  97. setLoading(true);
  98. await getOptions();
  99. // showSuccess('刷新成功');
  100. } catch (error) {
  101. showError('刷新失败');
  102. } finally {
  103. setLoading(false);
  104. }
  105. }
  106. useEffect(() => {
  107. onRefresh();
  108. }, []);
  109. return (
  110. <>
  111. <Spin spinning={loading} size='large'>
  112. {/* 通用设置 */}
  113. <Card style={{ marginTop: '10px' }}>
  114. <SettingsGeneral options={inputs} refresh={onRefresh} />
  115. </Card>
  116. {/* 绘图设置 */}
  117. <Card style={{ marginTop: '10px' }}>
  118. <SettingsDrawing options={inputs} refresh={onRefresh} />
  119. </Card>
  120. {/* 屏蔽词过滤设置 */}
  121. <Card style={{ marginTop: '10px' }}>
  122. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  123. </Card>
  124. {/* 日志设置 */}
  125. <Card style={{ marginTop: '10px' }}>
  126. <SettingsLog options={inputs} refresh={onRefresh} />
  127. </Card>
  128. {/* 数据看板 */}
  129. <Card style={{ marginTop: '10px' }}>
  130. <SettingsDataDashboard options={inputs} refresh={onRefresh} />
  131. </Card>
  132. {/* 监控设置 */}
  133. <Card style={{ marginTop: '10px' }}>
  134. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  135. </Card>
  136. {/* 额度设置 */}
  137. <Card style={{ marginTop: '10px' }}>
  138. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  139. </Card>
  140. {/* 聊天设置 */}
  141. <Card style={{ marginTop: '10px' }}>
  142. <SettingsChats options={inputs} refresh={onRefresh} />
  143. </Card>
  144. {/* 分组倍率设置 */}
  145. <Card style={{ marginTop: '10px' }}>
  146. <GroupRatioSettings options={inputs} refresh={onRefresh} />
  147. </Card>
  148. {/* 合并模型倍率设置和可视化倍率设置 */}
  149. <Card style={{ marginTop: '10px' }}>
  150. <Tabs type="line">
  151. <Tabs.TabPane tab={t('模型倍率设置')} itemKey="model">
  152. <ModelRatioSettings options={inputs} refresh={onRefresh} />
  153. </Tabs.TabPane>
  154. <Tabs.TabPane tab={t('可视化倍率设置')} itemKey="visual">
  155. <ModelSettingsVisualEditor options={inputs} refresh={onRefresh} />
  156. </Tabs.TabPane>
  157. <Tabs.TabPane tab={t('未设置倍率模型')} itemKey="unset_models">
  158. <ModelRatioNotSetEditor options={inputs} refresh={onRefresh} />
  159. </Tabs.TabPane>
  160. </Tabs>
  161. </Card>
  162. </Spin>
  163. </>
  164. );
  165. };
  166. export default OperationSetting;