From 9e4b41ce48cc5da90976635790e12b497859ea84 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Tue, 3 Aug 2021 19:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/config.ts | 2 +- src/pages/log/index.tsx | 3 --- src/pages/script/editModal.tsx | 9 +++++---- src/pages/script/index.tsx | 3 --- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/back/api/config.ts b/back/api/config.ts index 1c4afb2a..b05f97f7 100644 --- a/back/api/config.ts +++ b/back/api/config.ts @@ -59,7 +59,7 @@ export default (app: Router) => { celebrate({ body: Joi.object({ name: Joi.string().required(), - content: Joi.string().required(), + content: Joi.string().allow('').optional(), }), }), async (req: Request, res: Response, next: NextFunction) => { diff --git a/src/pages/log/index.tsx b/src/pages/log/index.tsx index 6506eb14..2479061b 100644 --- a/src/pages/log/index.tsx +++ b/src/pages/log/index.tsx @@ -179,9 +179,6 @@ const Log = () => { glyphMargin: false, wordWrap: 'on', }} - onChange={(val, ev) => { - setValue((val as string).replace(/\r\n/g, '\n')); - }} /> )} diff --git a/src/pages/script/editModal.tsx b/src/pages/script/editModal.tsx index 58b07df5..4c450c8f 100644 --- a/src/pages/script/editModal.tsx +++ b/src/pages/script/editModal.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { Drawer, Button, Tabs, Badge, Select, TreeSelect } from 'antd'; import { request } from '@/utils/http'; import config from '@/utils/config'; @@ -44,6 +44,7 @@ const EditModal = ({ const [isNewFile, setIsNewFile] = useState(false); const [log, setLog] = useState(''); const { theme } = useTheme(); + const editorRef = useRef(null); const cancel = () => { handleCancel(); @@ -164,8 +165,8 @@ const EditModal = ({ lineNumbersMinChars: 3, glyphMargin: false, }} - onChange={(val) => { - setValue((val as string).replace(/\r\n/g, '\n')); + onMount={(editor) => { + editorRef.current = editor; }} />
@@ -178,7 +179,7 @@ const EditModal = ({ setSaveModalVisible(false); }} isNewFile={isNewFile} - file={{ content: value, filename: fileName }} + file={{ content: editorRef.current.getValue(1), filename: fileName }} /> { folding: false, glyphMargin: false, }} - onChange={(val) => { - setValue((val as string).replace(/\r\n/g, '\n')); - }} /> )}