mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-31 05:16:12 +08:00
PC端支持对比工具修改配置文件
This commit is contained in:
parent
95e104dc9c
commit
ebc2e0e4b6
|
@ -1,4 +1,4 @@
|
||||||
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
import React, { PureComponent, useRef, useState, useEffect } from 'react';
|
||||||
import { Button, message, Modal } from 'antd';
|
import { Button, message, Modal } from 'antd';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
|
@ -14,6 +14,7 @@ const Crontab = () => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { headerStyle, isPhone } = useCtx();
|
const { headerStyle, isPhone } = useCtx();
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
|
const editorRef = useRef<any>(null);
|
||||||
|
|
||||||
const getConfig = () => {
|
const getConfig = () => {
|
||||||
request.get(`${config.apiPrefix}configs/config.sh`).then((data) => {
|
request.get(`${config.apiPrefix}configs/config.sh`).then((data) => {
|
||||||
|
@ -31,6 +32,20 @@ const Crontab = () => {
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateConfig = () => {
|
||||||
|
const content = editorRef.current
|
||||||
|
? editorRef.current.getModel().modified.getValue().replace(/\r\n/g, '\n')
|
||||||
|
: value;
|
||||||
|
|
||||||
|
request
|
||||||
|
.post(`${config.apiPrefix}configs/save`, {
|
||||||
|
data: { content, name: 'config.sh' },
|
||||||
|
})
|
||||||
|
.then((data: any) => {
|
||||||
|
message.success(data.message);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getConfig();
|
getConfig();
|
||||||
getSample();
|
getSample();
|
||||||
|
@ -44,6 +59,13 @@ const Crontab = () => {
|
||||||
header={{
|
header={{
|
||||||
style: headerStyle,
|
style: headerStyle,
|
||||||
}}
|
}}
|
||||||
|
extra={
|
||||||
|
!isPhone && [
|
||||||
|
<Button key="1" type="primary" onClick={updateConfig}>
|
||||||
|
保存
|
||||||
|
</Button>,
|
||||||
|
]
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{isPhone ? (
|
{isPhone ? (
|
||||||
<ReactDiffViewer
|
<ReactDiffViewer
|
||||||
|
@ -77,7 +99,6 @@ const Crontab = () => {
|
||||||
original={sample}
|
original={sample}
|
||||||
modified={value}
|
modified={value}
|
||||||
options={{
|
options={{
|
||||||
readOnly: true,
|
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
lineNumbersMinChars: 3,
|
lineNumbersMinChars: 3,
|
||||||
folding: false,
|
folding: false,
|
||||||
|
@ -85,6 +106,9 @@ const Crontab = () => {
|
||||||
wordWrap: 'on',
|
wordWrap: 'on',
|
||||||
}}
|
}}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
onMount={(editor) => {
|
||||||
|
editorRef.current = editor;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user