2023-05-13 21:27:49 +08:00
|
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2023-04-23 20:00:47 +08:00
|
|
|
|
import { Card, Grid, Header, Segment } from 'semantic-ui-react';
|
|
|
|
|
|
import { API, showError, showNotice, timestamp2string } from '../../helpers';
|
|
|
|
|
|
import { StatusContext } from '../../context/Status';
|
2023-05-13 21:27:49 +08:00
|
|
|
|
import { marked } from 'marked';
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
|
|
const Home = () => {
|
2023-04-23 20:00:47 +08:00
|
|
|
|
const [statusState, statusDispatch] = useContext(StatusContext);
|
2023-05-13 21:27:49 +08:00
|
|
|
|
const [homePageContent, setHomePageContent] = useState('');
|
2023-04-23 20:00:47 +08:00
|
|
|
|
|
2023-04-22 20:39:27 +08:00
|
|
|
|
const displayNotice = async () => {
|
|
|
|
|
|
const res = await API.get('/api/notice');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
let oldNotice = localStorage.getItem('notice');
|
|
|
|
|
|
if (data !== oldNotice && data !== '') {
|
|
|
|
|
|
showNotice(data);
|
|
|
|
|
|
localStorage.setItem('notice', data);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-13 21:27:49 +08:00
|
|
|
|
const displayHomePageContent = async () => {
|
|
|
|
|
|
const res = await API.get('/api/home_page_content');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
let HTMLContent = marked.parse(data);
|
|
|
|
|
|
localStorage.setItem('home_page_content', HTMLContent);
|
|
|
|
|
|
setHomePageContent(HTMLContent);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
setHomePageContent('加载首页内容失败...');
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-04-23 20:00:47 +08:00
|
|
|
|
const getStartTimeString = () => {
|
|
|
|
|
|
const timestamp = statusState?.status?.start_time;
|
|
|
|
|
|
return timestamp2string(timestamp);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-04-22 20:39:27 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
displayNotice().then();
|
2023-05-13 21:27:49 +08:00
|
|
|
|
displayHomePageContent().then();
|
2023-04-22 20:39:27 +08:00
|
|
|
|
}, []);
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Segment>
|
2023-05-13 21:27:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
homePageContent === '' ? <>
|
|
|
|
|
|
<Header as='h3'>系统状况</Header>
|
|
|
|
|
|
<Grid columns={2} stackable>
|
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
|
<Card fluid>
|
|
|
|
|
|
<Card.Content>
|
|
|
|
|
|
<Card.Header>系统信息</Card.Header>
|
|
|
|
|
|
<Card.Meta>系统信息总览</Card.Meta>
|
|
|
|
|
|
<Card.Description>
|
|
|
|
|
|
<p>名称:{statusState?.status?.system_name}</p>
|
|
|
|
|
|
<p>版本:{statusState?.status?.version}</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
源码:
|
|
|
|
|
|
<a
|
|
|
|
|
|
href='https://github.com/songquanpeng/one-api'
|
|
|
|
|
|
target='_blank'
|
|
|
|
|
|
>
|
|
|
|
|
|
https://github.com/songquanpeng/one-api
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>启动时间:{getStartTimeString()}</p>
|
|
|
|
|
|
</Card.Description>
|
|
|
|
|
|
</Card.Content>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
|
<Card fluid>
|
|
|
|
|
|
<Card.Content>
|
|
|
|
|
|
<Card.Header>系统配置</Card.Header>
|
|
|
|
|
|
<Card.Meta>系统配置总览</Card.Meta>
|
|
|
|
|
|
<Card.Description>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
邮箱验证:
|
|
|
|
|
|
{statusState?.status?.email_verification === true
|
|
|
|
|
|
? '已启用'
|
|
|
|
|
|
: '未启用'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
GitHub 身份验证:
|
|
|
|
|
|
{statusState?.status?.github_oauth === true
|
|
|
|
|
|
? '已启用'
|
|
|
|
|
|
: '未启用'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
微信身份验证:
|
|
|
|
|
|
{statusState?.status?.wechat_login === true
|
|
|
|
|
|
? '已启用'
|
|
|
|
|
|
: '未启用'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
Turnstile 用户校验:
|
|
|
|
|
|
{statusState?.status?.turnstile_check === true
|
|
|
|
|
|
? '已启用'
|
|
|
|
|
|
: '未启用'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</Card.Description>
|
|
|
|
|
|
</Card.Content>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
</> : <>
|
|
|
|
|
|
<div dangerouslySetInnerHTML={{ __html: homePageContent}}></div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
}
|
2023-04-22 20:39:27 +08:00
|
|
|
|
</Segment>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default Home;
|