测试内容获取

This commit is contained in:
hanhh 2021-08-03 18:06:40 +08:00
parent 5fd79173d6
commit eba78ca84f

View File

@ -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 { Button, message, Modal, TreeSelect } 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';
@ -15,6 +15,7 @@ const Config = () => {
const [data, setData] = useState<any[]>([]); const [data, setData] = useState<any[]>([]);
const { headerStyle, isPhone } = useCtx(); const { headerStyle, isPhone } = useCtx();
const { theme } = useTheme(); const { theme } = useTheme();
const editorRef = useRef<any>(null);
const getConfig = (name: string) => { const getConfig = (name: string) => {
request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => { request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => {
@ -33,9 +34,11 @@ const Config = () => {
}; };
const updateConfig = () => { const updateConfig = () => {
const content = editorRef.current.getValue(1);
request request
.post(`${config.apiPrefix}configs/save`, { .post(`${config.apiPrefix}configs/save`, {
data: { content: value, name: select }, data: { content, name: select },
}) })
.then((data: any) => { .then((data: any) => {
message.success(data.message); message.success(data.message);
@ -101,8 +104,8 @@ const Config = () => {
folding: false, folding: false,
glyphMargin: false, glyphMargin: false,
}} }}
onChange={(val) => { onMount={(editor) => {
setValue((val as string).replace(/\r\n/g, '\n')); editorRef.current = editor;
}} }}
/> />
)} )}