mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
|
import { Button, notification, Modal } from 'antd';
|
|
import config from '@/utils/config';
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
import { Controlled as CodeMirror } from 'react-codemirror2';
|
|
import { request } from '@/utils/http';
|
|
|
|
const Crontab = () => {
|
|
const [width, setWdith] = useState('100%');
|
|
const [marginLeft, setMarginLeft] = useState(0);
|
|
const [marginTop, setMarginTop] = useState(-72);
|
|
const [value, setValue] = useState('');
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
const getConfig = () => {
|
|
setLoading(true);
|
|
request
|
|
.get(`${config.apiPrefix}config/shareCode`)
|
|
.then((data) => {
|
|
setValue(data.content);
|
|
})
|
|
.finally(() => setLoading(false));
|
|
};
|
|
|
|
const updateConfig = () => {
|
|
request
|
|
.post(`${config.apiPrefix}save`, {
|
|
data: { content: value, name: 'diy.sh' },
|
|
})
|
|
.then((data) => {
|
|
notification.success({
|
|
message: data.msg,
|
|
});
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (document.body.clientWidth < 768) {
|
|
setWdith('auto');
|
|
setMarginLeft(0);
|
|
setMarginTop(0);
|
|
} else {
|
|
setWdith('100%');
|
|
setMarginLeft(0);
|
|
setMarginTop(-72);
|
|
}
|
|
getConfig();
|
|
}, []);
|
|
|
|
return (
|
|
<PageContainer
|
|
className="code-mirror-wrapper"
|
|
title="互助码"
|
|
loading={loading}
|
|
extra={[
|
|
<Button key="1" type="primary" onClick={updateConfig}>
|
|
保存
|
|
</Button>,
|
|
]}
|
|
header={{
|
|
style: {
|
|
padding: '4px 16px 4px 15px',
|
|
position: 'sticky',
|
|
top: 0,
|
|
left: 0,
|
|
zIndex: 20,
|
|
marginTop,
|
|
width,
|
|
marginLeft,
|
|
},
|
|
}}
|
|
style={{
|
|
height: '100vh',
|
|
}}
|
|
>
|
|
<CodeMirror
|
|
value={value}
|
|
options={{
|
|
lineNumbers: true,
|
|
lineWrapping: true,
|
|
styleActiveLine: true,
|
|
matchBrackets: true,
|
|
mode: 'shell',
|
|
theme: 'dracula',
|
|
readOnly: 'nocursor',
|
|
}}
|
|
onBeforeChange={(editor, data, value) => {
|
|
setValue(value);
|
|
}}
|
|
onChange={(editor, data, value) => {}}
|
|
/>
|
|
</PageContainer>
|
|
);
|
|
};
|
|
|
|
export default Crontab;
|