Commit 78f2d2d1 by zhaochengxiang

版本对比

parent 0b62b68b
import React from 'react'; import React from 'react';
import { Drawer, Tabs } from 'antd'; import { Drawer, Tabs, Space, Checkbox, Button } from 'antd';
import VersionHistory from './VersionHistory'; import VersionHistory from './VersionHistory';
import VersionCompare from './VersionCompare'; import VersionCompare from './VersionCompare';
...@@ -8,6 +8,17 @@ const { TabPane } = Tabs; ...@@ -8,6 +8,17 @@ const { TabPane } = Tabs;
const HistoryAndVersionDrawer = (props) => { const HistoryAndVersionDrawer = (props) => {
const { onCancel, visible, id } = props; const { onCancel, visible, id } = props;
const [activeKey, setActiveKey] = React.useState('1')
const [onlyShowChange, setOnlyShowChange] = React.useState(false)
const [alterTrigger, setAlterTrigger] = React.useState(false)
const onOnlyShowChange = (e) => {
setOnlyShowChange(e.target.checked);
}
const onAlterClick = () => {
setAlterTrigger(!alterTrigger)
}
return ( return (
<Drawer <Drawer
...@@ -16,17 +27,25 @@ const HistoryAndVersionDrawer = (props) => { ...@@ -16,17 +27,25 @@ const HistoryAndVersionDrawer = (props) => {
closable={true} closable={true}
width={'90%'} width={'90%'}
onClose={() => { onClose={() => {
setActiveKey('1');
onCancel && onCancel(); onCancel && onCancel();
}} }}
visible={visible} visible={visible}
> >
{ {
visible && <Tabs defaultActiveKey="1" type="card" size='small'> visible && <Tabs activeKey={activeKey} type="card" size='small' tabBarExtraContent={
activeKey==='2'?<Space>
<Checkbox onChange={onOnlyShowChange} checked={onlyShowChange}>仅显示差异</Checkbox>
<Button size='small' onClick={onAlterClick}>生成ALTER</Button>
</Space>:null
}
onChange={(val) => { setActiveKey(val) }}
>
<TabPane tab="版本历史" key="1"> <TabPane tab="版本历史" key="1">
<VersionHistory id={id} /> <VersionHistory id={id} />
</TabPane> </TabPane>
<TabPane tab="版本对比" key="2"> <TabPane tab="版本对比" key="2">
<VersionCompare id={id} /> <VersionCompare id={id} onlyShowChange={onlyShowChange} alterTrigger={alterTrigger} />
</TabPane> </TabPane>
</Tabs> </Tabs>
} }
......
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { Form, Select, Spin, Tooltip, Checkbox, Typography, Space, Button } from 'antd'; import { Form, Select, Spin, Tooltip, Checkbox, Typography, Space, Button, Row, Col } from 'antd';
import { dispatch, dispatchLatest } from '../../../../model'; import { dispatch, dispatchLatest } from '../../../../model';
import { formatVersionDate, showMessage } from '../../../../util'; import { formatVersionDate, showMessage } from '../../../../util';
...@@ -15,7 +15,7 @@ const { Option } = Select; ...@@ -15,7 +15,7 @@ const { Option } = Select;
const VersionCompare = (props) => { const VersionCompare = (props) => {
const { id } = props; const { id, onlyShowChange, alterTrigger } = props;
const [ basicVersion, setBasicVersion ] = useState(''); const [ basicVersion, setBasicVersion ] = useState('');
const [ basicVersions, setBasicVersions ] = useState([]); const [ basicVersions, setBasicVersions ] = useState([]);
...@@ -24,7 +24,6 @@ const VersionCompare = (props) => { ...@@ -24,7 +24,6 @@ const VersionCompare = (props) => {
const [ loading, setLoading ] = useState(false); const [ loading, setLoading ] = useState(false);
const [ compareData, setCompareData ] = useState(null); const [ compareData, setCompareData ] = useState(null);
const [ loadingCompare, setLoadingCompare ] = useState(false); const [ loadingCompare, setLoadingCompare ] = useState(false);
const [ onlyShowChange, setOnlyShowChange ] = useState(true);
const [ddlAlterParams, setAlterParams] = useState({ const [ddlAlterParams, setAlterParams] = useState({
visible: false, visible: false,
id: undefined, id: undefined,
...@@ -33,6 +32,8 @@ const VersionCompare = (props) => { ...@@ -33,6 +32,8 @@ const VersionCompare = (props) => {
incVersion: undefined, incVersion: undefined,
}) })
const mountRef = React.useRef(false)
useEffect(() => { useEffect(() => {
if ((id||'') !== '') { if ((id||'') !== '') {
getVersions(); getVersions();
...@@ -41,6 +42,26 @@ const VersionCompare = (props) => { ...@@ -41,6 +42,26 @@ const VersionCompare = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [ id ]) }, [ id ])
useEffect(() => {
if (basicVersion!=='' && incVersion!=='') {
getCompare(basicVersion, incVersion, onlyShowChange);
}
}, [onlyShowChange])
useEffect(() => {
if (mountRef.current) {
setAlterParams({
visible: true,
id,
versions: basicVersions,
defaultBasicVersion: basicVersion,
defaultIncVersion: incVersion,
})
}
mountRef.current = true
}, [alterTrigger])
const getVersions = () => { const getVersions = () => {
setLoading(true); setLoading(true);
dispatch({ dispatch({
...@@ -133,68 +154,51 @@ const VersionCompare = (props) => { ...@@ -133,68 +154,51 @@ const VersionCompare = (props) => {
}) })
} }
const onAlterClick = () => {
setAlterParams({
visible: true,
id,
versions: basicVersions,
defaultBasicVersion: basicVersion,
defaultIncVersion: incVersion,
})
}
const onOnlyShowChange = (e) => {
setOnlyShowChange(e.target.checked);
if (basicVersion!=='' && incVersion!=='') {
getCompare(basicVersion, incVersion, e.target.checked);
}
}
return ( return (
<div className='model-version-compare'> <div className='model-version-compare'>
<Form layout='inline'> <Form>
<Form.Item label='基线版本'> <Row gutter={15}>
<Select loading={loading} value={basicVersion} style={{ width: 300 }} onChange={onBasicChange} > <Col span={12}>
{ <Form.Item label='基线版本' style={{ marginBottom: 0 }}>
(basicVersions||[]).map((version, index) => { <Select loading={loading} value={basicVersion} style={{ width: '100%' }} onChange={onBasicChange} >
{
if (index === 0) { (basicVersions||[]).map((version, index) => {
return (
<Option key={index} value={version.id||''} disabled={true}> if (index === 0) {
<Tooltip title={'最近版本只能在增量版本中被选中'}> return (
<Option key={index} value={version.id||''} disabled={true}>
<Tooltip title={'最近版本只能在增量版本中被选中'}>
{version.name||''}
</Tooltip>
</Option>
)
};
return (
<Option key={index} value={version.id||''}>
{version.name||''} {version.name||''}
</Tooltip> </Option>
</Option> );
)
}; })
}
return ( </Select>
<Option key={index} value={version.id||''}> </Form.Item>
{version.name||''} </Col>
</Option> <Col span={12}>
); <Form.Item label='增量版本' style={{ marginBottom: 0 }}>
<Select value={incVersion} style={{ width: '100%' }} disabled={basicVersion===''} onChange={onIncChange}>
}) {
} (incVersions||[]).map((version, index) => {
</Select> return (
</Form.Item> <Option key={index} value={version.id||''}>{version.name||''}</Option>
<Form.Item label='增量版本'> );
<Select value={incVersion} style={{ width: 300 }} disabled={basicVersion===''} onChange={onIncChange}> })
{ }
(incVersions||[]).map((version, index) => { </Select>
return ( </Form.Item>
<Option key={index} value={version.id||''}>{version.name||''}</Option> </Col>
); </Row>
})
}
</Select>
</Form.Item>
<Form.Item>
<Space>
<Checkbox onChange={onOnlyShowChange} checked={onlyShowChange}>仅显示差异</Checkbox>
<Button onClick={onAlterClick}>生成ALTER</Button>
</Space>
</Form.Item>
</Form> </Form>
<div className='py-5'> <div className='py-5'>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment