59 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-04-22 20:39:27 +08:00
import React, { useEffect, useState } from 'react';
import { Header, Segment } from 'semantic-ui-react';
import { API, showError } from '../../helpers';
import { marked } from 'marked';
const About = () => {
const [about, setAbout] = useState('');
const [aboutLoaded, setAboutLoaded] = useState(false);
2023-04-22 20:39:27 +08:00
const displayAbout = async () => {
setAbout(localStorage.getItem('about') || '');
2023-04-22 20:39:27 +08:00
const res = await API.get('/api/about');
const { success, message, data } = res.data;
if (success) {
let aboutContent = data;
if (!data.startsWith('https://')) {
aboutContent = marked.parse(data);
}
setAbout(aboutContent);
localStorage.setItem('about', aboutContent);
2023-04-22 20:39:27 +08:00
} else {
showError(message);
setAbout('加载关于内容失败...');
}
setAboutLoaded(true);
2023-04-22 20:39:27 +08:00
};
useEffect(() => {
displayAbout().then();
}, []);
return (
<>
{
aboutLoaded && about === '' ? <>
<Segment>
2023-04-22 20:39:27 +08:00
<Header as='h3'>关于</Header>
<p>可在设置页面设置关于内容支持 HTML & Markdown</p>
2023-09-12 03:17:26 +08:00
魔改版项目仓库地址
<a href='https://github.com/Calcium-Ion/one-api'>
https://github.com/Calcium-Ion/one-api
2023-04-22 20:39:27 +08:00
</a>
</Segment>
</> : <>
{
about.startsWith('https://') ? <iframe
src={about}
style={{ width: '100%', height: '100vh', border: 'none' }}
/> : <div style={{ fontSize: 'larger' }} dangerouslySetInnerHTML={{ __html: about }}></div>
}
</>
}
2023-04-22 20:39:27 +08:00
</>
);
};
export default About;