重构平台判断代码

This commit is contained in:
hanhh
2021-08-02 15:19:20 +08:00
parent 5d846beabd
commit dc5b4de5fa
9 changed files with 250 additions and 252 deletions
+4 -45
View File
@@ -6,16 +6,14 @@ import { request } from '@/utils/http';
import './index.less';
import { DiffEditor } from '@monaco-editor/react';
import ReactDiffViewer from 'react-diff-viewer';
import { useCtx, useTheme } from '@/utils/hooks';
const Crontab = () => {
const [width, setWidth] = useState('100%');
const [marginLeft, setMarginLeft] = useState(0);
const [marginTop, setMarginTop] = useState(-72);
const [value, setValue] = useState('');
const [sample, setSample] = useState('');
const [loading, setLoading] = useState(true);
const [theme, setTheme] = useState<string>('');
const [isPhone, setIsPhone] = useState(false);
const { headerStyle, isPhone } = useCtx();
const { theme } = useTheme();
const getConfig = () => {
request.get(`${config.apiPrefix}configs/config.sh`).then((data) => {
@@ -34,54 +32,17 @@ const Crontab = () => {
};
useEffect(() => {
if (document.body.clientWidth < 768) {
setWidth('auto');
setMarginLeft(0);
setMarginTop(0);
setIsPhone(true);
} else {
setWidth('100%');
setMarginLeft(0);
setMarginTop(-72);
setIsPhone(false);
}
getConfig();
getSample();
}, []);
useEffect(() => {
const media = window.matchMedia('(prefers-color-scheme: dark)');
const storageTheme = localStorage.getItem('qinglong_dark_theme');
const isDark =
(media.matches && storageTheme !== 'light') || storageTheme === 'dark';
setTheme(isDark ? 'vs-dark' : 'vs');
media.addEventListener('change', (e) => {
if (storageTheme === 'auto' || !storageTheme) {
if (e.matches) {
setTheme('vs-dark');
} else {
setTheme('vs');
}
}
});
}, []);
return (
<PageContainer
className="ql-container-wrapper"
title="对比工具"
loading={loading}
header={{
style: {
padding: '4px 16px 4px 15px',
position: 'sticky',
top: 0,
left: 0,
zIndex: 20,
marginTop,
width,
marginLeft,
},
style: headerStyle,
}}
>
{isPhone ? (
@@ -118,11 +79,9 @@ const Crontab = () => {
options={{
readOnly: true,
fontSize: 12,
minimap: { enabled: width === '100%' },
lineNumbersMinChars: 3,
folding: false,
glyphMargin: false,
renderSideBySide: width === '100%',
wordWrap: 'on',
}}
theme={theme}