From feb22f25b847f4468386defe5719339ac3d6ed66 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Wed, 29 Sep 2021 22:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=AF=94=E5=B7=A5=E5=85=B7=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AF=B9=E6=AF=94config=E7=9B=AE=E5=BD=95=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/diff/index.less | 6 +++ src/pages/diff/index.tsx | 86 ++++++++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/src/pages/diff/index.less b/src/pages/diff/index.less index dbea084e..41aeb935 100644 --- a/src/pages/diff/index.less +++ b/src/pages/diff/index.less @@ -11,3 +11,9 @@ .d2h-code-side-line { padding: 0 0.5em; } + +.diff-switch-file { + .ant-form-item { + margin-bottom: 8px; + } +} diff --git a/src/pages/diff/index.tsx b/src/pages/diff/index.tsx index 93cdbc48..8993f6a3 100644 --- a/src/pages/diff/index.tsx +++ b/src/pages/diff/index.tsx @@ -1,5 +1,5 @@ import React, { PureComponent, useRef, useState, useEffect } from 'react'; -import { Button, message, Modal } from 'antd'; +import { Button, message, Select, Form, Row, Col } from 'antd'; import config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; import { request } from '@/utils/http'; @@ -7,46 +7,72 @@ import './index.less'; import { DiffEditor } from '@monaco-editor/react'; import ReactDiffViewer from 'react-diff-viewer'; +const { Option } = Select; + const Diff = ({ headerStyle, isPhone, theme }: any) => { - const [value, setValue] = useState(''); - const [sample, setSample] = useState(''); + const [origin, setOrigin] = useState('config.sample.sh'); + const [current, setCurrent] = useState('config.sh'); + const [originValue, setOriginValue] = useState(''); + const [currentValue, setCurrentValue] = useState(''); const [loading, setLoading] = useState(true); + const [files, setFiles] = useState([]); const editorRef = useRef(null); const getConfig = () => { - request.get(`${config.apiPrefix}configs/config.sh`).then((data) => { - setValue(data.data); + request.get(`${config.apiPrefix}configs/${current}`).then((data) => { + setCurrentValue(data.data); }); }; const getSample = () => { - setLoading(true); - request - .get(`${config.apiPrefix}configs/config.sample.sh`) - .then((data) => { - setSample(data.data); - }) - .finally(() => setLoading(false)); + request.get(`${config.apiPrefix}configs/${origin}`).then((data) => { + setOriginValue(data.data); + }); }; const updateConfig = () => { const content = editorRef.current ? editorRef.current.getModel().modified.getValue().replace(/\r\n/g, '\n') - : value; + : currentValue; request .post(`${config.apiPrefix}configs/save`, { - data: { content, name: 'config.sh' }, + data: { content, name: current }, }) .then((data: any) => { message.success(data.message); }); }; + const getFiles = () => { + setLoading(true); + request + .get(`${config.apiPrefix}configs/files`) + .then((data: any) => { + setFiles(data.data); + }) + .finally(() => setLoading(false)); + }; + + const originFileChange = (value: string) => { + setOrigin(value); + }; + + const currentFileChange = (value: string) => { + setCurrent(value); + }; + + useEffect(() => { + getFiles(); + }, []); + + useEffect(() => { + getSample(); + }, [origin]); + useEffect(() => { getConfig(); - getSample(); - }, []); + }, [current]); return ( { ] } > + + + + + + + + + + + + {isPhone ? ( { wordBreak: 'break-word', }, }} - oldValue={value} - newValue={sample} + oldValue={originValue} + newValue={currentValue} splitView={true} leftTitle="config.sh" rightTitle="config.sample.sh" @@ -93,8 +139,8 @@ const Diff = ({ headerStyle, isPhone, theme }: any) => { ) : (