From eba78ca84f92a61ca84a2c6e844601cc92422c39 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Tue, 3 Aug 2021 18:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=86=85=E5=AE=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/config/index.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/config/index.tsx b/src/pages/config/index.tsx index 74542ec6..d021c01e 100644 --- a/src/pages/config/index.tsx +++ b/src/pages/config/index.tsx @@ -1,4 +1,4 @@ -import React, { PureComponent, Fragment, useState, useEffect } from 'react'; +import React, { PureComponent, Fragment, useState, useEffect, useRef } from 'react'; import { Button, message, Modal, TreeSelect } from 'antd'; import config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; @@ -15,6 +15,7 @@ const Config = () => { const [data, setData] = useState([]); const { headerStyle, isPhone } = useCtx(); const { theme } = useTheme(); + const editorRef = useRef(null); const getConfig = (name: string) => { request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => { @@ -33,9 +34,11 @@ const Config = () => { }; const updateConfig = () => { + const content = editorRef.current.getValue(1); + request .post(`${config.apiPrefix}configs/save`, { - data: { content: value, name: select }, + data: { content, name: select }, }) .then((data: any) => { message.success(data.message); @@ -101,8 +104,8 @@ const Config = () => { folding: false, glyphMargin: false, }} - onChange={(val) => { - setValue((val as string).replace(/\r\n/g, '\n')); + onMount={(editor) => { + editorRef.current = editor; }} /> )}