Commit e0c9f02a by zhaochengxiang

资产属性关联元模型属性

parent baa4eb7b
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Form, TreeSelect, Select, Space, Button } from 'antd'; import { Modal, Form, TreeSelect, Select, Space, Button, Row, Col, } from 'antd';
import { dispatchLatest } from '../../../../model'; import { dispatch } from '../../../../model';
const MetaModelSelect = ({ value = {}, metaModelTreeData = [], onChange, ...restProps }) => {
const [ attributes, setAttributes ] = useState([]);
const [ loading, setLoading ] = useState(false);
useEffect(() => {
if ((value?.model||'') !== '') {
getAttributesByMetadataModel(value?.model);
} else {
setAttributes([]);
}
}, [value?.model])
const onTreeChange = (value, label, extra) => {
if ((label||[]).length > 0) {
triggerChange({ modelValue: value, model: label[0], attrName: '', attrCnName: '' });
} else {
triggerChange({ modelValue: '', model: '', attrName: '', attrCnName: '' });
}
}
const onAttributeChange = (value) => {
if ((value||'') === '') {
triggerChange({ attrName: '', attrCnName: '' });
return;
}
const index = (attributes||[]).findIndex(attribute => attribute.name===value);
if (index !== -1) {
triggerChange({ attrName: attributes[index]?.name, attrCnName: attributes[index]?.cnName });
}
}
const triggerChange = (changedValue) => {
onChange?.({
...value,
...changedValue,
});
};
const getAttributesByMetadataModel = (model) => {
setLoading(true);
dispatch({
type: 'assetmanage.getAttributesByMetadataModel',
payload: {
modelName: model
},
callback: data => {
setLoading(false);
setAttributes(data||[]);
},
error: () => {
setLoading(false);
}
});
}
//value有可能为空
value = value ? value: {};
return (
<Row gutter={10}>
<Col span={12}>
<TreeSelect
value={value.modelValue}
placeholder='请选择元模型'
treeData={metaModelTreeData}
onChange={onTreeChange}
allowClear
/>
</Col>
<Col span={12}>
<Select
onChange={(value) => { onAttributeChange && onAttributeChange(value) }}
value={value.attrName}
loading={loading}
placeholder='请选择属性'
allowClear
>
{
(attributes||[]).map((attribute, index) => {
return (
<Select.Option key={index} value={attribute.name||''}>
{ attribute.cnName||'' }
</Select.Option>
);
})
}
</Select>
</Col>
</Row>
);
}
const AttributeRelationModal = (props) => { const AttributeRelationModal = (props) => {
const { visible, onCancel } = props; const { visible, onCancel } = props;
...@@ -24,7 +119,7 @@ const AttributeRelationModal = (props) => { ...@@ -24,7 +119,7 @@ const AttributeRelationModal = (props) => {
}, [visible]) }, [visible])
const getMetadataModelTree = () => { const getMetadataModelTree = () => {
dispatchLatest({ dispatch({
type: 'assetmanage.getMetadataModelTree', type: 'assetmanage.getMetadataModelTree',
callback: data => { callback: data => {
let newData = [...data]; let newData = [...data];
...@@ -44,40 +139,19 @@ const AttributeRelationModal = (props) => { ...@@ -44,40 +139,19 @@ const AttributeRelationModal = (props) => {
recursion(newData); recursion(newData);
setMetadataModelTreeData(newData||[]); setMetadataModelTreeData(newData||[]);
if ((newData||[]).length > 0) { loadElementWithoutCustom();
let _currentModel = newData[0].nodeName||'';
setCurrentModel(_currentModel);
setCurrentTreeValue(newData[0].value||'');
getAttributesByMetadataModel(_currentModel);
}
},
error: () => {
}
});
}
const getAttributesByMetadataModel = (model) => {
dispatchLatest({
type: 'assetmanage.getAttributesByMetadataModel',
payload: {
modelName: model
},
callback: data => {
setAttributes(data||[]);
loadElementWithoutCustom(model);
}, },
error: () => { error: () => {
} }
}); });
} }
const loadElementWithoutCustom = (model) => { const loadElementWithoutCustom = () => {
dispatchLatest({ dispatch({
type: 'assetmanage.loadElementWithoutCustom', type: 'assetmanage.loadElementWithoutCustom',
callback: data => { callback: data => {
setElements(data||[]); setElements(data||[]);
getRelAttrByModel(model); getRelAttrByModel();
}, },
error: () => { error: () => {
...@@ -85,18 +159,13 @@ const AttributeRelationModal = (props) => { ...@@ -85,18 +159,13 @@ const AttributeRelationModal = (props) => {
}); });
} }
const getRelAttrByModel = (model = currentModel) => { const getRelAttrByModel = () => {
dispatchLatest({ dispatch({
type: 'assetmanage.getRelAttrByModel', type: 'assetmanage.getRelAttrByModel',
payload: {
params: {
model
}
},
callback: data => { callback: data => {
let _fieldsValue = {}; let _fieldsValue = {};
(data||[]).forEach(item => { (data||[]).forEach(item => {
_fieldsValue[item.elementId] = item.attrName||''; _fieldsValue[item.elementId] = {model: item.model, modelValue: item.model, attrName: item.attrName||'', attrCnName: item.attrCnName||''};
}) })
form.setFieldsValue(_fieldsValue); form.setFieldsValue(_fieldsValue);
...@@ -107,32 +176,22 @@ const AttributeRelationModal = (props) => { ...@@ -107,32 +176,22 @@ const AttributeRelationModal = (props) => {
}); });
} }
const onTreeChange = (value, label, extra) => {
setCurrentTreeValue(value);
if ((label||[]).length > 0) {
setCurrentModel(label[0]);
reset();
getAttributesByMetadataModel(label[0]);
}
}
const onOk = async() => { const onOk = async() => {
try { try {
const row = await form.validateFields(); const row = await form.validateFields();
let newRels = []; let newRels = [];
for (var key in row) { for (var key in row) {
if ((row[key]||'') !== '') { if ((row[key]||'') !== '') {
newRels.push({ elementId: key, attrName: row[key]||'' }); if ((row[key]?.model||'')!=='' && (row[key]?.attrName||'')!=='') {
newRels.push({ elementId: key, model: row[key]?.model, attrName: row[key]?.attrName||'', attrCnName: row[key]?.attrCnName||''});
}
} }
} }
setConfirmLoading(true); setConfirmLoading(true);
dispatchLatest({ dispatch({
type: 'assetmanage.saveEleAndAttrRel', type: 'assetmanage.saveEleAndAttrRel',
payload: { payload: {
params: { params: {
...@@ -193,13 +252,6 @@ const AttributeRelationModal = (props) => { ...@@ -193,13 +252,6 @@ const AttributeRelationModal = (props) => {
> >
<div style={{ maxHeight: 500, overflow: 'auto' }}> <div style={{ maxHeight: 500, overflow: 'auto' }}>
<Form form={form} {...formItemLayout}> <Form form={form} {...formItemLayout}>
<Form.Item label='元模型'>
<TreeSelect
value={currentTreeValue}
treeData={metadataModelTreeData}
onChange={onTreeChange}
/>
</Form.Item>
{ {
(elements||[]).map((element, index) => { (elements||[]).map((element, index) => {
return ( return (
...@@ -208,17 +260,9 @@ const AttributeRelationModal = (props) => { ...@@ -208,17 +260,9 @@ const AttributeRelationModal = (props) => {
name={element.id||''} name={element.id||''}
key={index} key={index}
> >
<Select allowClear> <MetaModelSelect
{ metaModelTreeData={metadataModelTreeData}
(attributes||[]).map((attribute, _index) => { />
return (
<Select.Option key={index} value={attribute.name||''}>
{ attribute.cnName||'' }
</Select.Option>
);
})
}
</Select>
</Form.Item> </Form.Item>
); );
}) })
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, Space, InputNumber, Button, Radio, Select } from 'antd'; import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
import { showMessage } from '../../../../util'; import { showMessage } from '../../../../util';
......
...@@ -23,7 +23,6 @@ const EditModel = (props) => { ...@@ -23,7 +23,6 @@ const EditModel = (props) => {
const [ historyAndVersionDrawerVisible, setHistoryAndVersionDrawerVisible ] = useState(false); const [ historyAndVersionDrawerVisible, setHistoryAndVersionDrawerVisible ] = useState(false);
const [ autoTabKey, setAutoTabKey ] = useState(null); const [ autoTabKey, setAutoTabKey ] = useState(null);
const mountRef = useRef(false);
const actionRef = useRef(''); const actionRef = useRef('');
const { action, catalogId, modelerId, hints, roughModelerData, permitCheckOut, editable, stateId, versionId, holder } = actionData; const { action, catalogId, modelerId, hints, roughModelerData, permitCheckOut, editable, stateId, versionId, holder } = actionData;
......
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