Commit 42d01639 by zhaochengxiang

快速创建

parent 67d63047
import React from 'react'; import React from 'react';
import { Input } from 'antd'; import { Input, Row, Col, Descriptions } from 'antd';
class ImportExcelCopy extends React.Component { class ImportExcelCopy extends React.Component {
constructor() { constructor() {
super(); super();
this.state = { this.state = {
inputValue: '' inputValue: '',
translateValues: []
}; };
} }
componentDidUpdate(preProps, preState) { componentDidUpdate(preProps, preState) {
const { visible } = this.props; const { visible } = this.props;
if (!visible && visible !== preProps.visible) { if (!visible && visible !== preProps.visible) {
this.setState({ inputValue: '' }); this.setState({ inputValue: '', translateValues: [] });
} }
} }
onInputChange = (e) => { onInputChange = (e) => {
const { onChange } = this.props; const { onChange } = this.props;
this.setState({ inputValue: e.target.value }, () => { this.setState({ inputValue: e.target.value }, () => {
onChange && onChange(e.target.value.replace(/[,,,_ ]/g,'\n').split('\n').filter(value => value!==''&&value!==' ')); const _translateValues = e.target.value.replace(/[,,,_ ]/g,'\n').split('\n').filter(value => value!==''&&value!==' ');
onChange && onChange(_translateValues);
this.setState({ translateValues: _translateValues });
}); });
} }
render() { render() {
const { inputValue } = this.state; const { inputValue, translateValues } = this.state;
const _placeholder = '支持两种方式创建\n方式一: Excel内容复制粘贴(模型名称和中文字段名)\n方式二: 手动输入模型名称和中文字段'; const _placeholder = '支持两种方式创建\n方式一: Excel内容复制粘贴(模型名称和中文字段名)\n方式二: 手动输入模型名称和中文字段';
let _attrsStr = '';
translateValues.forEach((item, index) => {
if (index === 0) {
_attrsStr = '';
} else if (index === 1) {
_attrsStr = item;
} else {
_attrsStr += `,${item}`;
}
})
return ( return (
<Row gutter={(translateValues.length>0)?10: 0}>
<Col span={(translateValues.length>0)?14: 24}>
<Input.TextArea <Input.TextArea
value={inputValue||''} value={inputValue||''}
onChange={this.onInputChange} onChange={this.onInputChange}
...@@ -39,6 +55,22 @@ class ImportExcelCopy extends React.Component { ...@@ -39,6 +55,22 @@ class ImportExcelCopy extends React.Component {
placeholder={_placeholder} placeholder={_placeholder}
> >
</Input.TextArea> </Input.TextArea>
</Col>
{
(translateValues.length>0) && <Col span={10}>
<Descriptions className='excel-copy-descritpion' column={1} size='small'>
<Descriptions.Item label='模型名称'>
{ translateValues[0] }
</Descriptions.Item>
{
_attrsStr.length>0 && <Descriptions.Item label='字段名称'>
{ _attrsStr }
</Descriptions.Item>
}
</Descriptions>
</Col>
}
</Row>
) )
} }
} }
......
...@@ -8,15 +8,16 @@ import ImportExcelCopy from './ImportExcelCopy'; ...@@ -8,15 +8,16 @@ import ImportExcelCopy from './ImportExcelCopy';
import { dispatchLatest } from '../../../../model'; import { dispatchLatest } from '../../../../model';
const importModes = [ const importModes = [
{ name: '快速创建', key: 'excel-copy' },
{ name: '空白创建', key: 'no-condition' },
{ name: 'Word导入', key: 'word' }, { name: 'Word导入', key: 'word' },
{ name: 'Excel导入', key: 'excel' }, { name: 'Excel导入', key: 'excel' },
{ name: 'Excel复制粘贴', key: 'excel-copy' },
] ]
const ImportModal = (props) => { const ImportModal = (props) => {
const { view, catalogId, visible, onCancel, onCancelByWord } = props; const { view, catalogId, visible, onCancel, onCancelByWord } = props;
const [ modeKey, setModeKey ] = useState(''); const [ modeKey, setModeKey ] = useState('excel-copy');
const [ hints, setHints ] = useState([]); const [ hints, setHints ] = useState([]);
const [ confirmLoading, setConfirmLoading ] = useState(false); const [ confirmLoading, setConfirmLoading ] = useState(false);
...@@ -73,6 +74,9 @@ const ImportModal = (props) => { ...@@ -73,6 +74,9 @@ const ImportModal = (props) => {
reset(); reset();
onCancel && onCancel(false, true, hints||[]); onCancel && onCancel(false, true, hints||[]);
} else if (modeKey==='no-condition') {
reset();
onCancel && onCancel(false, true, []);
} }
} catch (errInfo) { } catch (errInfo) {
...@@ -87,8 +91,8 @@ const ImportModal = (props) => { ...@@ -87,8 +91,8 @@ const ImportModal = (props) => {
} }
const reset = () => { const reset = () => {
form.resetFields(); form.setFieldsValue({mode: 'excel-copy'});
setModeKey(''); setModeKey('excel-copy');
setHints([]); setHints([]);
setConfirmLoading(false); setConfirmLoading(false);
} }
...@@ -119,7 +123,7 @@ const ImportModal = (props) => { ...@@ -119,7 +123,7 @@ const ImportModal = (props) => {
forceRender forceRender
visible={visible} visible={visible}
title='新建模型' title='新建模型'
width={520} width={540}
onCancel={cancel} onCancel={cancel}
footer={footer} footer={footer}
> >
...@@ -133,6 +137,7 @@ const ImportModal = (props) => { ...@@ -133,6 +137,7 @@ const ImportModal = (props) => {
message: '请选择新建方式', message: '请选择新建方式',
}, },
]} ]}
initialValue={modeKey}
> >
<Radio.Group onChange={onModeChange} value={modeKey}> <Radio.Group onChange={onModeChange} value={modeKey}>
{ {
......
...@@ -39,3 +39,9 @@ ...@@ -39,3 +39,9 @@
color: #fff !important; color: #fff !important;
} }
} }
.excel-copy-descritpion {
.yy-descriptions-row > td {
padding-bottom: 0px !important;
}
}
\ No newline at end of file
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