Commit 837b3fbe by zhaochengxiang

模型编辑详情

parent b57146c3
...@@ -85,8 +85,9 @@ export const SetSource = function (source) { ...@@ -85,8 +85,9 @@ export const SetSource = function (source) {
} }
const callback = resp => { const callback = resp => {
if (resp.status === 401) { if (resp.status === 401) {
showMessage('warn', "session过期,请重新登录!"); showMessage('warn', 'session过期,请重新登录!');
//外网 //外网
window.location.href="/center-home/view/login" window.location.href="/center-home/view/login"
//内网 //内网
...@@ -94,7 +95,11 @@ const callback = resp => { ...@@ -94,7 +95,11 @@ const callback = resp => {
return null; return null;
} }
else if (resp.status !== 200) { else if (resp.status !== 200) {
throw resp.data if (resp && resp.data && resp.data.ApiError && resp.data.ApiError.cnMessage) {
showMessage('warn', resp.data.ApiError.cnMessage||'');
}
return null;
} }
return resp.data || resp; return resp.data || resp;
......
...@@ -10,7 +10,7 @@ import { dispatchLatest, dispatch } from '../../../../model'; ...@@ -10,7 +10,7 @@ import { dispatchLatest, dispatch } from '../../../../model';
const { Option } = Select; const { Option } = Select;
const ImportAction = (props) => { const ImportAction = (props) => {
const { action, hints, onChange, form } = props; const { action, hints, onChange, form, modelerId } = props;
const [ constraints, setConstraints ] = useState([]); const [ constraints, setConstraints ] = useState([]);
const [ constraint, setConstraint ] = useState({}); const [ constraint, setConstraint ] = useState({});
...@@ -25,16 +25,23 @@ const ImportAction = (props) => { ...@@ -25,16 +25,23 @@ const ImportAction = (props) => {
if (mountRef.current) { if (mountRef.current) {
mountRef.current = false; mountRef.current = false;
dispatchLatest({ if (action === 'detail') {
type: 'datamodel.getAllConstraints', getCurrentDataModel();
callback: data => { } else {
setConstraints(data||[]); dispatchLatest({
setConstraint((data||[]).length>0?data[0]:{}); type: 'datamodel.getAllConstraints',
getDraft((data||[]).length>0?data[0]:{}, hints); callback: data => {
} setConstraints(data||[]);
}) if (action === 'add') {
setConstraint((data||[]).length>0?data[0]:{});
getDraft((data||[]).length>0?data[0]:{}, hints);
} else if(action === 'edit') {
getCurrentDataModel();
}
}
})
}
} }
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
...@@ -60,6 +67,28 @@ const ImportAction = (props) => { ...@@ -60,6 +67,28 @@ const ImportAction = (props) => {
}) })
} }
const getCurrentDataModel = () => {
dispatchLatest({
type: 'datamodel.getDataModel',
payload: {
id: modelerId||''
},
callback: data => {
setModelerData(data||{});
onChange && onChange(data||{});
getSupportedDatatypes();
if (action === 'edit') {
form.setFieldsValue({
cnName: data.cnName||'',
name: data.name||'',
remark: data.remark||'',
});
}
}
})
}
const onConstraintChange = (value) => { const onConstraintChange = (value) => {
let currentConstraint = null, _hints = []; let currentConstraint = null, _hints = [];
...@@ -96,17 +125,19 @@ const ImportAction = (props) => { ...@@ -96,17 +125,19 @@ const ImportAction = (props) => {
return ( return (
<> <>
<div className='d-flex mb-3'> {
<Select value={constraint.id?constraint.id:''} style={{ marginLeft: 'auto' }} onChange={onConstraintChange}> action!=='detail' && <div className='d-flex mb-3'>
{ <Select value={constraint.id?constraint.id:null} placeholder='请选择规则' style={{ marginLeft: 'auto', minWidth: 100 }} onChange={onConstraintChange}>
(constraints||[]).map((constraint, index) => { {
return ( (constraints||[]).map((constraint, index) => {
<Option key={index} value={constraint.id}>{ constraint.cnName||'' }</Option> return (
) <Option key={index} value={constraint.id}>{ constraint.cnName||'' }</Option>
}) )
} })
</Select> }
</div> </Select>
</div>
}
<ImportActionHeader <ImportActionHeader
form={form} form={form}
editable={action!=='detail'} editable={action!=='detail'}
......
import React from 'react'; import React from 'react';
import { Form, Input, Row, Col } from 'antd'; import { Form, Input, Row, Col, Descriptions } from 'antd';
const ImportActionHeader = (props) => { const ImportActionHeader = (props) => {
const { editable, modelerData, form } = props; const { editable, form, modelerData } = props;
const formItemLayout = { const formItemLayout = {
labelCol: { labelCol: {
...@@ -16,52 +16,54 @@ const ImportActionHeader = (props) => { ...@@ -16,52 +16,54 @@ const ImportActionHeader = (props) => {
}; };
return ( return (
<Form editable ? (
form={form} <Form
{...formItemLayout} form={form}
name="basic" {...formItemLayout}
initialValues={{ >
cnName: modelerData.cnName||'', <Row gutter={10}>
name: modelerData.name||'', <Col span={12}>
remark: modelerData.remark||'', <Form.Item
}} label="中文名称"
> name="cnName"
<Row gutter={10}> labelAlign="left"
<Col span={12}> rules={[{ required: true, message: '请输入中文名称!' }]}
<Form.Item >
label="中文名称" <Input disabled={!editable} />
name="cnName" </Form.Item>
labelAlign="left" </Col>
rules={[{ required: true, message: '请输入中文名称!' }]} <Col span={12}>
> <Form.Item
<Input disabled={!editable} /> label="英文名称"
</Form.Item> name="name"
</Col> labelAlign="left"
<Col span={12}> rules={[{ required: true, message: '请输入英文名称!' }]}
<Form.Item >
label="英文名称" <Input disabled={!editable} />
name="name" </Form.Item>
labelAlign="left" </Col>
rules={[{ required: true, message: '请输入英文名称!' }]} </Row>
> <Row gutter={10}>
<Input disabled={!editable} /> <Col span={12}>
</Form.Item> <Form.Item
</Col> label="描述"
</Row> name="remark"
<Row gutter={10}> labelAlign="left"
<Col span={12}> disabled={!editable}
<Form.Item rules={[{ required: true, message: '请输入描述!' }]}
label="描述" >
name="remark" <Input disabled={!editable} />
labelAlign="left" </Form.Item>
disabled={!editable} </Col>
rules={[{ required: true, message: '请输入描述!' }]} </Row>
> </Form>
<Input disabled={!editable} /> ) : (
</Form.Item> <Descriptions>
</Col> <Descriptions.Item label="中文名称">{modelerData.cnName||''}</Descriptions.Item>
</Row> <Descriptions.Item label="英文名称">{modelerData.name||''}</Descriptions.Item>
</Form> <Descriptions.Item label="描述">{modelerData.remark||''}</Descriptions.Item>
</Descriptions>
)
) )
} }
......
...@@ -367,6 +367,10 @@ const ImportActionTable = (props) => { ...@@ -367,6 +367,10 @@ const ImportActionTable = (props) => {
dataIndex: 'remark', dataIndex: 'remark',
editable: true, editable: true,
}, },
];
const editableColumn = [
...columns,
{ {
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
...@@ -394,25 +398,49 @@ const ImportActionTable = (props) => { ...@@ -394,25 +398,49 @@ const ImportActionTable = (props) => {
); );
}, },
}, },
]; ]
const mergedColumns = columns.map((col) => { const mergedColumns = () => {
if (!col.editable) { if (editable) {
return col; return editableColumn.map((col) => {
if (!col.editable) {
return col;
}
return {
...col,
onCell: (record) => ({
record,
inputType: 'text',
dataIndex: col.dataIndex,
title: col.title,
editing: isEditing(record),
datatypes: supportedDatatypes,
}),
};
});
} }
return { return columns;
...col, }
onCell: (record) => ({
record, // const mergedColumns = columns.map((col) => {
inputType: 'text', // if (!col.editable) {
dataIndex: col.dataIndex, // return col;
title: col.title, // }
editing: isEditing(record),
datatypes: supportedDatatypes, // return {
}), // ...col,
}; // onCell: (record) => ({
}); // record,
// inputType: 'text',
// dataIndex: col.dataIndex,
// title: col.title,
// editing: isEditing(record),
// datatypes: supportedDatatypes,
// }),
// };
// });
const moveRow = useCallback( const moveRow = useCallback(
(dragIndex, hoverIndex) => { (dragIndex, hoverIndex) => {
...@@ -458,7 +486,7 @@ const ImportActionTable = (props) => { ...@@ -458,7 +486,7 @@ const ImportActionTable = (props) => {
} }
}} }}
dataSource={data||[]} dataSource={data||[]}
columns={mergedColumns} columns={mergedColumns()}
size='small' size='small'
rowKey='iid' rowKey='iid'
rowClassName="editable-row" rowClassName="editable-row"
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Modal, Radio, Button, Form } from 'antd'; import { Modal, Radio, Button, Form } from 'antd';
// import ImportLog from './ImportLog'; // import ImportLog from './ImportLog';
...@@ -28,7 +28,7 @@ const modes = [ ...@@ -28,7 +28,7 @@ const modes = [
] ]
const ImportModal = (props) => { const ImportModal = (props) => {
const { catalogId, visible, onCancel, action } = props; const { catalogId, visible, onCancel, action, modelerId } = props;
const [ step, setStep ] = useState(0); const [ step, setStep ] = useState(0);
const [ radioValue, setRadioValue ] = useState(''); const [ radioValue, setRadioValue ] = useState('');
const [ excelFiles, setExcelFiles ] = useState([]); const [ excelFiles, setExcelFiles ] = useState([]);
...@@ -38,6 +38,18 @@ const ImportModal = (props) => { ...@@ -38,6 +38,18 @@ const ImportModal = (props) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
useEffect(() => {
if (visible) {
if (action === 'add') {
setStep(0);
} else {
setStep(2);
}
}
}, [visible, catalogId, action])
const onRadioChange = e => { const onRadioChange = e => {
setRadioValue(e.target.value); setRadioValue(e.target.value);
}; };
...@@ -81,6 +93,11 @@ const ImportModal = (props) => { ...@@ -81,6 +93,11 @@ const ImportModal = (props) => {
setStep(step+1); setStep(step+1);
} }
const cancel = () => {
reset();
onCancel && onCancel(true);
}
const save = async () => { const save = async () => {
try { try {
const row = await form.validateFields(); const row = await form.validateFields();
...@@ -138,12 +155,78 @@ const ImportModal = (props) => { ...@@ -138,12 +155,78 @@ const ImportModal = (props) => {
} }
let title = ''; let title = '';
if (step === 0) { if (action === 'add') {
title = '创建方式'; if (step === 0) {
} else if (step === 1 && radioValue===0) { title = '创建方式';
title = 'excel导入'; } else if (step === 1 && radioValue===0) {
} else if (step === 2 && radioValue===0) { title = 'excel导入';
title = '模型创建-excel导入'; } else if (step === 2 && radioValue===0) {
title = '模型创建-excel导入';
}
} else if (action === 'edit') {
title = '模型编辑';
} else if (action === 'detail') {
title = '模型详情';
}
let footer = null;
if (action === 'add') {
footer = [
<Button
key="0"
type="primary"
style={{ display: (step!==0)?'':'none' }}
onClick={prev}
>
上一步
</Button>,
<Button
key="1"
type="primary"
loading={confirmLoading}
style={{ display: (step<2)?'':'none' }}
onClick={next}
>
下一步
</Button>,
<Button
key="2"
type="primary"
loading={confirmLoading}
style={{ display: (step===2)?'':'none' }}
onClick={save}
>
保存
</Button>
];
} else if (action === 'edit') {
footer = [
<Button
key="1"
type="primary"
onClick={cancel}
>
取消
</Button>,
<Button
key="2"
type="primary"
loading={confirmLoading}
onClick={save}
>
保存
</Button>
];
} else if (action === 'detail') {
footer = [
<Button
key="1"
type="primary"
onClick={cancel}
>
取消
</Button>
];
} }
return ( return (
...@@ -158,34 +241,7 @@ const ImportModal = (props) => { ...@@ -158,34 +241,7 @@ const ImportModal = (props) => {
reset(); reset();
onCancel && onCancel(); onCancel && onCancel();
}} }}
footer={[ footer={footer}
<Button
key="0"
type="primary"
style={{ display: (step!==0)?'':'none' }}
onClick={prev}
>
上一步
</Button>,
<Button
key="1"
type="primary"
loading={confirmLoading}
style={{ display: (step<2)?'':'none' }}
onClick={next}
>
下一步
</Button>,
<Button
key="2"
type="primary"
loading={confirmLoading}
style={{ display: (step===2)?'':'none' }}
onClick={save}
>
保存
</Button>
]}
> >
<> <>
{ {
...@@ -220,7 +276,7 @@ const ImportModal = (props) => { ...@@ -220,7 +276,7 @@ const ImportModal = (props) => {
step===1 && radioValue===4 && <></> step===1 && radioValue===4 && <></>
} }
{ {
step===2 && <ImportAction hints={hints} onChange={onActionChange} action={action} form={form} /> step===2 && <ImportAction hints={hints} onChange={onActionChange} action={action} modelerId={modelerId} form={form} />
} }
</> </>
</Modal> </Modal>
......
...@@ -8,7 +8,7 @@ import './ModelTable.less'; ...@@ -8,7 +8,7 @@ import './ModelTable.less';
const ModelTable = (props) => { const ModelTable = (props) => {
const { data, onChange, loading } = props; const { data, onChange, loading, onItemAction } = props;
const [ selectedRowKeys, setSelectedRowKeys ] = useState([]); const [ selectedRowKeys, setSelectedRowKeys ] = useState([]);
const [modal, contextHolder] = Modal.useModal(); const [modal, contextHolder] = Modal.useModal();
...@@ -33,7 +33,7 @@ const ModelTable = (props) => { ...@@ -33,7 +33,7 @@ const ModelTable = (props) => {
return ( return (
<Space size='small'> <Space size='small'>
<Tooltip placement='bottom' title={'修改'}> <Tooltip placement='bottom' title={'修改'}>
<Button icon={<EditOutlined />} size='small' /> <Button icon={<EditOutlined />} size='small' onClick={() => { editItem(record); }} />
</Tooltip> </Tooltip>
<Tooltip placement='bottom' title={'详情'}> <Tooltip placement='bottom' title={'详情'}>
<Button icon={<ReconciliationOutlined />} size='small' onClick={() => { detailItem(record); }} /> <Button icon={<ReconciliationOutlined />} size='small' onClick={() => { detailItem(record); }} />
...@@ -50,8 +50,12 @@ const ModelTable = (props) => { ...@@ -50,8 +50,12 @@ const ModelTable = (props) => {
} }
]; ];
const editItem = (record) => {
onItemAction && onItemAction(record.id||'', 'edit');
}
const detailItem = (record) => { const detailItem = (record) => {
onItemAction && onItemAction(record.id||'', 'detail');
} }
const deleteItem = (record) => { const deleteItem = (record) => {
......
...@@ -48,6 +48,10 @@ class Model extends React.Component { ...@@ -48,6 +48,10 @@ class Model extends React.Component {
}) })
} }
onTableItemAction = (id, action) => {
this.setState({ importModalVisible: true, importModalAction: action, modelerId: id });
}
onImportBtnClick = () => { onImportBtnClick = () => {
const { catalogId } = this.state; const { catalogId } = this.state;
if (!catalogId || catalogId==='') { if (!catalogId || catalogId==='') {
...@@ -72,7 +76,7 @@ class Model extends React.Component { ...@@ -72,7 +76,7 @@ class Model extends React.Component {
} }
render() { render() {
const { importModalVisible, exportModalVisible, catalogId, importModalAction, tableData, loadingTableData } = this.state; const { importModalVisible, exportModalVisible, catalogId, importModalAction, tableData, loadingTableData, modelerId } = this.state;
return ( return (
<div style={{ backgroundColor: '#ECEEF3', height: '100%' }}> <div style={{ backgroundColor: '#ECEEF3', height: '100%' }}>
...@@ -96,7 +100,7 @@ class Model extends React.Component { ...@@ -96,7 +100,7 @@ class Model extends React.Component {
<Button type="primary" className='ml-3' onClick={this.onExportBtnClick}>模型导出</Button> <Button type="primary" className='ml-3' onClick={this.onExportBtnClick}>模型导出</Button>
</div> </div>
<div className='p-3'> <div className='p-3'>
<ModelTable loading={loadingTableData} data={tableData} onChange={this.onTableChange} /> <ModelTable loading={loadingTableData} data={tableData} onChange={this.onTableChange} onItemAction={this.onTableItemAction} />
</div> </div>
</div> </div>
</Col> </Col>
...@@ -107,6 +111,7 @@ class Model extends React.Component { ...@@ -107,6 +111,7 @@ class Model extends React.Component {
action={importModalAction} action={importModalAction}
onCancel={this.onImportModalCancel} onCancel={this.onImportModalCancel}
catalogId={catalogId} catalogId={catalogId}
modelerId={modelerId}
/> />
<ExportModal <ExportModal
......
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