Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

83 строки
2.4 KiB

  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 { useTranslation } from 'react-i18next';
  18. import SettingsPerformance from '../../pages/Setting/Performance/SettingsPerformance';
  19. import { API, showError, toBoolean } from '../../helpers';
  20. const PerformanceSetting = () => {
  21. const { t } = useTranslation();
  22. let [inputs, setInputs] = useState({
  23. 'performance_setting.disk_cache_enabled': false,
  24. 'performance_setting.disk_cache_threshold_mb': 10,
  25. 'performance_setting.disk_cache_max_size_mb': 1024,
  26. 'performance_setting.disk_cache_path': '',
  27. });
  28. let [loading, setLoading] = useState(false);
  29. const getOptions = async () => {
  30. const res = await API.get('/api/option/');
  31. const { success, message, data } = res.data;
  32. if (success) {
  33. let newInputs = {};
  34. data.forEach((item) => {
  35. if (typeof inputs[item.key] === 'boolean') {
  36. newInputs[item.key] = toBoolean(item.value);
  37. } else {
  38. newInputs[item.key] = item.value;
  39. }
  40. });
  41. setInputs(newInputs);
  42. } else {
  43. showError(message);
  44. }
  45. };
  46. async function onRefresh() {
  47. try {
  48. setLoading(true);
  49. await getOptions();
  50. } catch (error) {
  51. showError(t('刷新失败'));
  52. } finally {
  53. setLoading(false);
  54. }
  55. }
  56. useEffect(() => {
  57. onRefresh();
  58. }, []);
  59. return (
  60. <>
  61. <Spin spinning={loading} size='large'>
  62. {/* 性能设置 */}
  63. <Card style={{ marginTop: '10px' }}>
  64. <SettingsPerformance options={inputs} refresh={onRefresh} />
  65. </Card>
  66. </Spin>
  67. </>
  68. );
  69. };
  70. export default PerformanceSetting;