ChatsSetting.jsx 2.1 KB

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