Files
monkey-ai-web/src/pages/About/index.jsx
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

122 lines
3.4 KiB
React

import { useEffectEvent } from '../../hooks/common/useEffectEvent';
import React, { useContext, useEffect, useState } from 'react';
import { API, getSystemName, showError } from '../../helpers';
import { StatusContext } from '../../context/Status';
import { marked } from 'marked';
import { Empty } from '@/components/ui';
import {
IllustrationConstruction,
IllustrationConstructionDark,
} from '../../components/common/illustrations';
import { useTranslation } from 'react-i18next';
const About = () => {
const { t } = useTranslation();
const [statusState] = useContext(StatusContext);
const [about, setAbout] = useState('');
const [aboutLoaded, setAboutLoaded] = useState(false);
const currentYear = new Date().getFullYear();
const officialWebsite = (statusState?.status?.official_website || '').trim();
const systemName = getSystemName();
const displayAbout = async () => {
setAbout(localStorage.getItem('about') || '');
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);
} else {
showError(message);
setAbout(t('加载关于内容失败...'));
}
setAboutLoaded(true);
};
const onMount = useEffectEvent(() => {
displayAbout().then();
});
useEffect(() => onMount(), [onMount]);
const emptyStyle = {
padding: '24px',
};
const customDescription = (
<div style={{ textAlign: 'center' }}>
<p>{t('可在设置页面设置关于内容,支持 HTML & Markdown')}</p>
{officialWebsite && (
<>
{t('官网:')}
<a
href={officialWebsite}
target='_blank'
rel='noopener noreferrer'
className='!text-ui-color-primary'
>
{officialWebsite}
</a>
</>
)}
<p>
{officialWebsite ? (
<a
href={officialWebsite}
target='_blank'
rel='noopener noreferrer'
className='!text-ui-color-primary'
>
{systemName}
</a>
) : (
systemName
)}{' '}
{t('© {{currentYear}}', { currentYear })}
</p>
</div>
);
return (
<div className='mt-[60px] px-2'>
{aboutLoaded && about === '' ? (
<div className='flex justify-center items-center h-screen p-8'>
<Empty
image={
<IllustrationConstruction style={{ width: 150, height: 150 }} />
}
darkModeImage={
<IllustrationConstructionDark
style={{ width: 150, height: 150 }}
/>
}
description={t('管理员暂时未设置任何关于内容')}
style={emptyStyle}
>
{customDescription}
</Empty>
</div>
) : (
<>
{about.startsWith('https://') ? (
<iframe
src={about}
style={{ width: '100%', height: '100vh', border: 'none' }}
/>
) : (
<div
style={{ fontSize: 'larger' }}
dangerouslySetInnerHTML={{ __html: about }}
></div>
)}
</>
)}
</div>
);
};
export default About;