From ebc2e0e4b68987385ac649dd376f5eed49f0b879 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Fri, 6 Aug 2021 19:10:02 +0800 Subject: [PATCH] =?UTF-8?q?PC=E7=AB=AF=E6=94=AF=E6=8C=81=E5=AF=B9=E6=AF=94?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/diff/index.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pages/diff/index.tsx b/src/pages/diff/index.tsx index 89055486..43503406 100644 --- a/src/pages/diff/index.tsx +++ b/src/pages/diff/index.tsx @@ -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 config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; @@ -14,6 +14,7 @@ const Crontab = () => { const [loading, setLoading] = useState(true); const { headerStyle, isPhone } = useCtx(); const { theme } = useTheme(); + const editorRef = useRef(null); const getConfig = () => { request.get(`${config.apiPrefix}configs/config.sh`).then((data) => { @@ -31,6 +32,20 @@ const Crontab = () => { .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(() => { getConfig(); getSample(); @@ -44,6 +59,13 @@ const Crontab = () => { header={{ style: headerStyle, }} + extra={ + !isPhone && [ + , + ] + } > {isPhone ? ( { original={sample} modified={value} options={{ - readOnly: true, fontSize: 12, lineNumbersMinChars: 3, folding: false, @@ -85,6 +106,9 @@ const Crontab = () => { wordWrap: 'on', }} theme={theme} + onMount={(editor) => { + editorRef.current = editor; + }} /> )}