Commit d3e7851b by zhaochengxiang

资产修改

parent 7a49b741
import React, { useEffect, useState, useContext, useMemo, useRef } from 'react'; import React, { useEffect, useState, useContext, useMemo, useRef } from 'react';
import { Form, Spin, Input, Descriptions, Space, Button, Tooltip, Select, Cascader, Table, Radio, Divider, Typography, Modal } from 'antd'; import { Form, Spin, Input, Descriptions, Space, Button, Tooltip, Select, Cascader, Table, Radio, Divider, Typography, Modal, Row, Col } from 'antd';
import { DownOutlined, UpOutlined } from '@ant-design/icons'; import { DownOutlined, UpOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import MetadataInfo from './MetadataInfo'; import MetadataInfo from './MetadataInfo';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
...@@ -27,6 +27,7 @@ const AssetAction = (props) => { ...@@ -27,6 +27,7 @@ const AssetAction = (props) => {
const [ currentAction, setCurrentAction ] = useState(action); const [ currentAction, setCurrentAction ] = useState(action);
const [ assetParams, setAssetParams ] = useState({ assets: {}, attributes: [], attributesFoldMap: {} }); const [ assetParams, setAssetParams ] = useState({ assets: {}, attributes: [], attributesFoldMap: {} });
const [ elements, setElements ] = useState([]); const [ elements, setElements ] = useState([]);
const [ wholeElements, setWholeElements ] = useState([]);
const [ metadataId, setMetadataId ] = useState(''); const [ metadataId, setMetadataId ] = useState('');
const [ loading, setLoading ] = useState(false); const [ loading, setLoading ] = useState(false);
const [ confirmLoading, setConfirmLoading ] = useState(false); const [ confirmLoading, setConfirmLoading ] = useState(false);
...@@ -44,7 +45,6 @@ const AssetAction = (props) => { ...@@ -44,7 +45,6 @@ const AssetAction = (props) => {
const [ loadingDepartments, setLoadingDepartments ] = useState(false); const [ loadingDepartments, setLoadingDepartments ] = useState(false);
const [ treeData, setTreeData ] = useState([]); const [ treeData, setTreeData ] = useState([]);
const [ treeDataMap, setTreeDataMap ] = useState(undefined); const [ treeDataMap, setTreeDataMap ] = useState(undefined);
const [ businessData, setBusinessData ] = useState(undefined);
const [currentDomainGroup, setCurrentDomainGroup] = useState(undefined); const [currentDomainGroup, setCurrentDomainGroup] = useState(undefined);
const [canEdit, setEdit] = useState(false); const [canEdit, setEdit] = useState(false);
const [metadata, setMetadata] = useState(undefined); const [metadata, setMetadata] = useState(undefined);
...@@ -178,10 +178,11 @@ const AssetAction = (props) => { ...@@ -178,10 +178,11 @@ const AssetAction = (props) => {
getTreeData(); getTreeData();
getDepartments(); getDepartments();
if (action === 'add') { if (action === 'add') {
getElements(); // getElements();
} else { } else {
setCurrentAction('detail'); setCurrentAction('detail');
if ((id||'')!=='') { if ((id||'')!=='') {
getElements();
getAssetPaths(); getAssetPaths();
getResourceRelations(); getResourceRelations();
checkDataAssetEditable(); checkDataAssetEditable();
...@@ -224,6 +225,52 @@ const AssetAction = (props) => { ...@@ -224,6 +225,52 @@ const AssetAction = (props) => {
return []; return [];
}, [metadataColumnList, standardList]) }, [metadataColumnList, standardList])
const businessData = useMemo(() => {
if (assetPaths?.length >0 && treeData?.length > 0) {
let newBusinessData = [];
treeData?.forEach(level1Item => {
const businessItem = {
label: level1Item.text,
value: level1Item.text,
children: []
};
let flag = false;
level1Item.children?.forEach(level2Item => {
const tempLevel2Item = {
label: level2Item.text,
value: level2Item.text,
children: []
};
level2Item.children?.forEach(level3Item => {
tempLevel2Item.children.push({
label: level3Item.text,
value: level3Item.text,
});
if (level3Item.nodeId === assetPaths[0].dirId) {
flag = true;
}
});
if (flag && tempLevel2Item.children.length !== 0) {
businessItem.children.push(tempLevel2Item);
}
});
if (flag && businessItem.children.length !== 0) {
newBusinessData.push(businessItem);
}
});
return newBusinessData;
}
return [];
}, [assetPaths, treeData])
const getAssetPaths = () => { const getAssetPaths = () => {
dispatch({ dispatch({
type: 'assetmanage.getAssetPaths', type: 'assetmanage.getAssetPaths',
...@@ -278,39 +325,6 @@ const AssetAction = (props) => { ...@@ -278,39 +325,6 @@ const AssetAction = (props) => {
newTreeDataMap[item.text] = item.children; newTreeDataMap[item.text] = item.children;
}) })
setTreeDataMap(newTreeDataMap); setTreeDataMap(newTreeDataMap);
let newBusinessData = [];
data?.forEach(level1Item => {
const businessItem = {
label: level1Item.text,
value: level1Item.text,
children: []
};
level1Item.children?.forEach(level2Item => {
const tempLevel2Item = {
label: level2Item.text,
value: level2Item.text,
children: []
};
level2Item.children?.forEach(level3Item => {
tempLevel2Item.children.push({
label: level3Item.text,
value: level3Item.text,
})
});
if (tempLevel2Item.children.length !== 0) {
businessItem.children.push(tempLevel2Item);
}
});
if (businessItem.children.length !== 0) {
newBusinessData.push(businessItem);
}
});
setBusinessData(newBusinessData);
} }
}) })
} }
...@@ -342,7 +356,6 @@ const AssetAction = (props) => { ...@@ -342,7 +356,6 @@ const AssetAction = (props) => {
} }
const getElements = ( cb = null ) => { const getElements = ( cb = null ) => {
setLoading(true);
dispatch({ dispatch({
type: (currentAction==='add')?'assetmanage.listElementsAndFillValue':'assetmanage.listElements', type: (currentAction==='add')?'assetmanage.listElementsAndFillValue':'assetmanage.listElements',
payload: (currentAction==='add')?{ payload: (currentAction==='add')?{
...@@ -351,44 +364,7 @@ const AssetAction = (props) => { ...@@ -351,44 +364,7 @@ const AssetAction = (props) => {
} }
}:undefined, }:undefined,
callback: data => { callback: data => {
setLoading(false); setWholeElements(data||[]);
setElements(data||[]);
onElementsChange && onElementsChange(data||[]);
const _attributes = [];
(data||[]).forEach(element => {
if (_attributes.indexOf(element.type) === -1) {
_attributes.push(element.type);
}
})
let newAttributesFoldMap = {...attributesFoldMap};
(_attributes||[]).forEach(attribute => {
if (newAttributesFoldMap[attribute]===undefined || newAttributesFoldMap[attribute]===null) {
newAttributesFoldMap[attribute] = true;
}
})
setAssetParams({ assets: {}, attributes: _attributes, attributesFoldMap: newAttributesFoldMap });
form?.resetFields();
if (currentAction==='add') {
let newFiledsValue = {};
(data||[]).forEach(element => {
if (element.defaultValue) {
newFiledsValue[element.name] = element.defaultValue
}
});
form?.setFieldsValue(newFiledsValue);
}
cb && cb();
},
error: () => {
setLoading(false);
} }
}) })
} }
...@@ -497,10 +473,10 @@ const AssetAction = (props) => { ...@@ -497,10 +473,10 @@ const AssetAction = (props) => {
const getMetadataAttributes = () => { const getMetadataAttributes = () => {
setMetadata(prevMetadata => { setMetadata(prevMetadata => {
setLoadingMetadataColumnList(true);
const ids = prevMetadata?.columnItems.map(item => item.metadataColumnId); const ids = prevMetadata?.columnItems.map(item => item.metadataColumnId);
if ((ids||[]).length > 0) { if ((ids||[]).length > 0) {
setLoadingMetadataColumnList(true);
dispatch({ dispatch({
type: 'assetmanage.getMetadataAttributes', type: 'assetmanage.getMetadataAttributes',
payload: { payload: {
...@@ -950,9 +926,15 @@ const AssetAction = (props) => { ...@@ -950,9 +926,15 @@ const AssetAction = (props) => {
<Divider orientation='left'>{attribute}</Divider> <Divider orientation='left'>{attribute}</Divider>
<Descriptions column={1} bordered> <Descriptions column={1} bordered>
{ {
elements?.map((element, index) => { wholeElements?.length>0 && elements?.map((element, index) => {
if (element.type!==attribute || element.name === '资产项') return null; if (element.type!==attribute || element.name === '资产项') return null;
let interpretation = null;
const filterElements = wholeElements?.filter(_element => _element.id === element.id);
if (filterElements.length>0) {
interpretation = filterElements[0].interpretation;
}
return ( return (
<Descriptions.Item <Descriptions.Item
key={index} key={index}
...@@ -967,14 +949,27 @@ const AssetAction = (props) => { ...@@ -967,14 +949,27 @@ const AssetAction = (props) => {
labelStyle={{ width: 180 }} labelStyle={{ width: 180 }}
> >
{ {
(currentAction==='add'||currentAction==='edit') ? <Form.Item (currentAction==='add'||currentAction==='edit') ?
label='' <Row gutter={8}>
name={element.name} <Col span={22}>
rules={[{ required: element.required }]} <Form.Item
style={{ width: 500, marginBottom: 0 }} label=''
> name={element.name}
{elementEditComponent(element)} rules={[{ required: element.required }]}
</Form.Item> : <React.Fragment> style={{ marginBottom: 0 }}
>
{elementEditComponent(element)}
</Form.Item>
</Col>
{
interpretation && <Col span={2}>
<Tooltip placement="left" title={interpretation}>
<QuestionCircleOutlined style={{ marginTop: 8, fontSize: 16 }} />
</Tooltip>
</Col>
}
</Row>
: <React.Fragment>
{ elementDetailComponent(element) } { elementDetailComponent(element) }
</React.Fragment> </React.Fragment>
} }
...@@ -996,11 +991,14 @@ const AssetAction = (props) => { ...@@ -996,11 +991,14 @@ const AssetAction = (props) => {
</div> </div>
<Space style={{ marginLeft: 'auto' }}> <Space style={{ marginLeft: 'auto' }}>
{ {/* {
(reference===AssetManageReference||canEdit) && <Button type='primary' onClick={() => { (reference===AssetManageReference||canEdit) && <Button type='primary' onClick={() => {
uploadRef.current?.chooseFile() uploadRef.current?.chooseFile()
}}>导入</Button> }}>导入</Button>
} } */}
<Button type='primary' onClick={() => {
uploadRef.current?.chooseFile()
}}>导入</Button>
<Button type='primary' onClick={onExportClick}>导出</Button> <Button type='primary' onClick={onExportClick}>导出</Button>
</Space> </Space>
......
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