Commit 21c03651 by zhaochengxiang

模型增加模版

parent 7ba19260
......@@ -70,8 +70,11 @@ export function* extractExcelContent(payload) {
return yield call(datamodelerService.extractExcelContent, payload);
}
export function* getAllConstraints() {
return yield call(datamodelerService.constraints);
export function* getAllConstraintsAndTemplates() {
const constraints = yield call(datamodelerService.constraints);
const templates = yield call(datamodelerService.templates);
return { constraints, templates };
}
//获取初稿
......
......@@ -31,6 +31,11 @@ export function constraints() {
return GetJSON("/datamodeler/easyDataModelerConstraint/constraints");
}
//模版
export function templates() {
return GetJSON("/datamodeler/easyDataModelerConstraint/templates");
}
//创建初稿
export function draft(payload) {
return PostJSON("/datamodeler/easyDataModelerDesign/draft", payload);
......
......@@ -14,6 +14,8 @@ const ImportAction = (props) => {
const [ constraints, setConstraints ] = useState([]);
const [ constraint, setConstraint ] = useState({});
const [ templates, setTemplates ] = useState([]);
const [ template, setTemplate ] = useState({});
const [ modelerData, setModelerData ] = useState(null);
const [ supportedDatatypes, setSupportedDatatypes ] = useState([]);
......@@ -37,12 +39,14 @@ const ImportAction = (props) => {
getCurrentDataModel();
} else {
dispatchLatest({
type: 'datamodel.getAllConstraints',
type: 'datamodel.getAllConstraintsAndTemplates',
callback: data => {
setConstraints(data||[]);
setConstraints(data.constraints||[]);
setTemplates(data.templates||[]);
if (action === 'add') {
setConstraint((data||[]).length>0?data[0]:{});
getDraft((data||[]).length>0?data[0]:{}, hints);
setConstraint((data.constraints||[]).length>0?data.constraints[0]:{});
setTemplate((data.templates||[]).length>0?data.templates[0]:{});
getDraft((data.constraints||[]).length>0?data.constraints[0]:{}, (data.templates||[]).length>0?data.templates[0]:{} ,hints);
} else if(action === 'edit') {
getCurrentDataModel();
}
......@@ -52,13 +56,14 @@ const ImportAction = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [action, hints, modelerId ]);
const getDraft = (_constraint, _hints) => {
const getDraft = (_constraint, _template, _hints) => {
dispatchLatest({
type: 'datamodel.getDraft',
payload: {
data: {
hints: _hints,
modelerModelingConstraint: _constraint
modelerModelingConstraint: _constraint,
easyDataModelerModelingTemplate: _template
}
},
callback: data => {
......@@ -112,7 +117,26 @@ const ImportAction = (props) => {
});
setConstraint(currentConstraint);
getDraft(currentConstraint, _hints);
getDraft(currentConstraint, template, _hints);
}
const onTemplateChange = (value) => {
let currentTemplate = null, _hints = [];
(templates||[]).forEach((_template, index) => {
if (_template.id === value) {
currentTemplate = _template;
}
});
(modelerData.easyDataModelerDataModelAttributes||[]).forEach((_attribute, index) => {
if (_attribute.name && _attribute.name!=='') {
_hints.push(_attribute.cnName);
}
});
setTemplate(currentTemplate);
getDraft(constraint, currentTemplate, _hints);
}
const getSupportedDatatypes = () => {
......@@ -145,6 +169,15 @@ const ImportAction = (props) => {
})
}
</Select>
<Select className='ml-3' value={template.id?template.id:null} placeholder='请选择模版' style={{ minWidth: 100 }} onChange={onTemplateChange}>
{
(templates||[]).map((template, index) => {
return (
<Option key={index} value={template.id}>{ template.cnName||'' }</Option>
)
})
}
</Select>
</div>
}
<ImportActionHeader
......
import React, { useState, useCallback, useRef, useEffect } from 'react';
import { Table, Input, InputNumber, Form, Typography, Radio, Divider, Button, Popconfirm, Select, Row, Col } from 'antd';
import { Table, Input, InputNumber, Form, Typography, Radio, Divider, Button, Popconfirm, Select, Row, Col, Descriptions } from 'antd';
import { DndProvider, useDrag, useDrop } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import update from 'immutability-helper';
......@@ -424,24 +424,6 @@ const ImportActionTable = (props) => {
return columns;
}
// const mergedColumns = columns.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,
// }),
// };
// });
const moveRow = useCallback(
(dragIndex, hoverIndex) => {
......@@ -505,7 +487,7 @@ const ImportActionTable = (props) => {
suggests && suggests.map((suggest, index) => {
return (
<Radio key={index} value={index} className='mt-3' style={{ display: 'block' }}>
{`${suggest.name||''}`}
{`中文名称: ${suggest.cnName||''} 英文名称: ${suggest.name||''} 描述: ${suggest.remark||''}`}
</Radio>
)
})
......
......@@ -17,7 +17,7 @@ const ModelTable = (props) => {
setSelectedRowKeys([]);
onSelect && onSelect([]);
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [ catalogId ]);
......@@ -82,6 +82,14 @@ const ModelTable = (props) => {
callback: () => {
showMessage('success', '模型删除成功');
onChange && onChange();
const index = selectedRowKeys.findIndex((rowKey) => rowKey === record.id);
if (index !== -1) {
const newSelectedRowKeys = [...selectedRowKeys];
newSelectedRowKeys.splice(index, 1);
setSelectedRowKeys(newSelectedRowKeys);
onSelect && onSelect(newSelectedRowKeys);
}
}
})
}
......
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