DashboardSetting.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { useEffect, useState } from 'react';
  2. import { Card, Spin } from '@douyinfe/semi-ui';
  3. import { API, showError } from '../../helpers';
  4. import SettingsAPIInfo from '../../pages/Setting/Dashboard/SettingsAPIInfo.js';
  5. const DashboardSetting = () => {
  6. let [inputs, setInputs] = useState({
  7. ApiInfo: '',
  8. });
  9. let [loading, setLoading] = useState(false);
  10. const getOptions = async () => {
  11. const res = await API.get('/api/option/');
  12. const { success, message, data } = res.data;
  13. if (success) {
  14. let newInputs = {};
  15. data.forEach((item) => {
  16. if (item.key in inputs) {
  17. newInputs[item.key] = item.value;
  18. }
  19. });
  20. setInputs(newInputs);
  21. } else {
  22. showError(message);
  23. }
  24. };
  25. async function onRefresh() {
  26. try {
  27. setLoading(true);
  28. await getOptions();
  29. } catch (error) {
  30. showError('刷新失败');
  31. console.error(error);
  32. } finally {
  33. setLoading(false);
  34. }
  35. }
  36. useEffect(() => {
  37. onRefresh();
  38. }, []);
  39. return (
  40. <>
  41. <Spin spinning={loading} size='large'>
  42. {/* API信息管理 */}
  43. <Card style={{ marginTop: '10px' }}>
  44. <SettingsAPIInfo options={inputs} refresh={onRefresh} />
  45. </Card>
  46. </Spin>
  47. </>
  48. );
  49. };
  50. export default DashboardSetting;