Commit ce74dbf3 by zhaochengxiang

资产新增

parent f144019f
import React, { useState } from 'react';
import { Modal, Form, Space, Button } from 'antd';
import { showMessage } from '../../../../util';
import { dispatch } from '../../../../model';
import AssetAction from './AssetAction';
import './AddAssetModel.less';
const AddAssetModel = (props) => {
const { onCancel, visible, nodeId } = props;
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ metadataId, setMetadataId ] = useState('');
const [ elements, setElements ] = useState([]);
const [ form ] = Form.useForm();
const onElementsChange = (value) => {
setElements(value);
}
const onMetadataChange = (value) => {
setMetadataId(value);
}
const onOk = async() => {
try {
const row = await form?.validateFields();
const newElements = [...elements];
(newElements||[]).forEach(element => {
if (row.hasOwnProperty(element.name)) {
element.value = row[element.name];
}
});
const params = {
dirId: nodeId,
}
if ((metadataId||'')!=='') {
params.metadataId = metadataId;
}
setConfirmLoading(true);
dispatch({
type: 'assetmanage.addOrUpdateDataAsset',
payload: {
params,
data: { elements: newElements }
},
callback: () => {
setConfirmLoading(false);
showMessage("success","新增成功");
onCancel && onCancel(true);
},
error: () => {
setConfirmLoading(false);
}
})
} catch (errInfo) {
console.log('Validate Failed:', errInfo);
setConfirmLoading(false);
}
}
return (
<Modal
forceRender
className='asset-add'
title='新增资产信息'
visible={ visible }
width={ 600 }
onCancel={() => { onCancel && onCancel(); } }
footer={
<Space>
<Button onClick={() => onCancel && onCancel() }>取消</Button>
<Button type="primary" onClick={ onOk } loading={ confirmLoading }>确定</Button>
</Space>
}
>
<AssetAction
form={form}
dirId={nodeId}
action='add'
onMetadataChange={onMetadataChange}
onElementsChange={onElementsChange}
/>
</Modal>
);
}
export default AddAssetModel;
\ No newline at end of file
.asset-edit { .asset-add {
.yy-form { .yy-modal-body {
max-height: 500px !important; max-height: 500px !important;
overflow: auto !important; overflow: auto !important;
} }
......
...@@ -11,8 +11,7 @@ import { AppContext } from '../../../../App'; ...@@ -11,8 +11,7 @@ import { AppContext } from '../../../../App';
import Tag from '../../Tag'; import Tag from '../../Tag';
const AssetAction = (props) => { const AssetAction = (props) => {
const { id, dirId, action, terms, onChange, readOnly = false, form, onMetadataChange, onElementsChange } = props;
const { id, dirId, action, terms, onChange, readOnly = false } = 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: {} });
...@@ -24,8 +23,6 @@ const AssetAction = (props) => { ...@@ -24,8 +23,6 @@ const AssetAction = (props) => {
const { assets, attributes, attributesFoldMap } = assetParams; const { assets, attributes, attributesFoldMap } = assetParams;
const [ form ] = Form.useForm();
useEffect(() => { useEffect(() => {
if (action === 'add') { if (action === 'add') {
getElements(); getElements();
...@@ -45,6 +42,7 @@ const AssetAction = (props) => { ...@@ -45,6 +42,7 @@ const AssetAction = (props) => {
callback: data => { callback: data => {
setLoading(false); setLoading(false);
setElements(data||[]); setElements(data||[]);
onElementsChange && onElementsChange(data||[]);
if (action === 'add') { if (action === 'add') {
const _attributes = []; const _attributes = [];
...@@ -84,6 +82,7 @@ const AssetAction = (props) => { ...@@ -84,6 +82,7 @@ const AssetAction = (props) => {
callback: data => { callback: data => {
setLoading(false); setLoading(false);
setMetadataId(data?.mid||''); setMetadataId(data?.mid||'');
onMetadataChange && onMetadataChange(data?.mid||'');
const _attributes = []; const _attributes = [];
(data?.elements||[]).forEach(element => { (data?.elements||[]).forEach(element => {
...@@ -139,7 +138,7 @@ const AssetAction = (props) => { ...@@ -139,7 +138,7 @@ const AssetAction = (props) => {
const onOk = async() => { const onOk = async() => {
try { try {
const row = await form.validateFields(); const row = await form?.validateFields();
const newElements = [...elements]; const newElements = [...elements];
(newElements||[]).forEach(element => { (newElements||[]).forEach(element => {
...@@ -208,7 +207,7 @@ const AssetAction = (props) => { ...@@ -208,7 +207,7 @@ const AssetAction = (props) => {
_fieldsValue[element.name] = element.value; _fieldsValue[element.name] = element.value;
}) })
form.setFieldsValue(_fieldsValue); form?.setFieldsValue(_fieldsValue);
} }
}) })
} }
...@@ -240,7 +239,7 @@ const AssetAction = (props) => { ...@@ -240,7 +239,7 @@ const AssetAction = (props) => {
}} }}
> >
{ {
!readOnly && <div (!readOnly&&action!=='add') && <div
className='flex px-3' className='flex px-3'
style={{ style={{
height: 52, height: 52,
...@@ -259,23 +258,24 @@ const AssetAction = (props) => { ...@@ -259,23 +258,24 @@ const AssetAction = (props) => {
</Space> </Space>
</div> </div>
} }
{
<div style={{ padding: 10 }}> (action!=='add') && <div style={{ padding: 10 }}>
<Descriptions column={1}> <Descriptions column={1}>
{ {
(assets.currentPath||'')!=='' && <Descriptions.Item label='路径' style={{ paddingBottom: 10 }}> (assets.currentPath||'')!=='' && <Descriptions.Item label='路径' style={{ paddingBottom: 10 }}>
<a onClick={()=>{jumpToPath();}}> <a onClick={()=>{jumpToPath();}}>
{assets.currentPath||''} {assets.currentPath||''}
</a> </a>
</Descriptions.Item>
}
<Descriptions.Item label='标签' style={{ paddingBottom: 0 }}>
{
(currentAction==='add'||currentAction==='edit')?<Tag styleType='complex' id={id} />:<Tag id={id} />
}
</Descriptions.Item> </Descriptions.Item>
} </Descriptions>
<Descriptions.Item label='标签' style={{ paddingBottom: 0 }}> </div>
{ }
(currentAction==='add'||currentAction==='edit')?<Tag styleType='complex' id={id} />:<Tag id={id} />
}
</Descriptions.Item>
</Descriptions>
</div>
<div <div
style={{ style={{
...@@ -297,7 +297,7 @@ const AssetAction = (props) => { ...@@ -297,7 +297,7 @@ const AssetAction = (props) => {
sameAttributeElements = (assets?.elements||[]).filter(element => element.type===attribute); sameAttributeElements = (assets?.elements||[]).filter(element => element.type===attribute);
} }
if (attributesFoldMap[attribute]) { if (currentAction!=='add' && !fullScreen && attributesFoldMap[attribute]) {
sameAttributeElements = (sameAttributeElements||[]).filter(element => unfoldedElements.indexOf(element?.name||'')!==-1); sameAttributeElements = (sameAttributeElements||[]).filter(element => unfoldedElements.indexOf(element?.name||'')!==-1);
} }
...@@ -311,11 +311,14 @@ const AssetAction = (props) => { ...@@ -311,11 +311,14 @@ const AssetAction = (props) => {
padding: '0 15px', padding: '0 15px',
backgroundColor: '#106baa', backgroundColor: '#106baa',
color: '#fff', color: '#fff',
height: 32
}} }}
> >
<div>{attribute||''}</div> <div>{attribute||''}</div>
{ {
attributesFoldMap[attribute] ? <Button type='text' style={{ padding: 0, color: '#fff' }} onClick={() => { onFoldButtonClick(attribute, false) }}>展开<DownOutlined /></Button> : <Button type='text' style={{ padding: 0, color: '#fff' }} onClick={() => { onFoldButtonClick(attribute, true) }}>收起<UpOutlined /></Button> currentAction!=='add'&&!fullScreen && (
attributesFoldMap[attribute] ? <Button type='text' style={{ padding: 0, color: '#fff' }} onClick={() => { onFoldButtonClick(attribute, false) }}>展开<DownOutlined /></Button> : <Button type='text' style={{ padding: 0, color: '#fff' }} onClick={() => { onFoldButtonClick(attribute, true) }}>收起<UpOutlined /></Button>
)
} }
</div> </div>
<div style={{ padding: 10 }}> <div style={{ padding: 10 }}>
...@@ -327,6 +330,8 @@ const AssetAction = (props) => { ...@@ -327,6 +330,8 @@ const AssetAction = (props) => {
value?.onGlobalStateChange&&value?.onGlobalStateChange((state, prev) => { value?.onGlobalStateChange&&value?.onGlobalStateChange((state, prev) => {
if (state.message === 'data-govern-show-metadata-list-callback-message') { if (state.message === 'data-govern-show-metadata-list-callback-message') {
setMetadataId(state.data?.metadataId||''); setMetadataId(state.data?.metadataId||'');
onMetadataChange && onMetadataChange(state.data?.metadataId||'');
form?.setFieldsValue({ '资产项': state.data?.metadataInfoJson||'' }); form?.setFieldsValue({ '资产项': state.data?.metadataInfoJson||'' });
if ((state.data?.metadataId||'') !== '') { if ((state.data?.metadataId||'') !== '') {
......
import React from 'react'; import React from 'react';
import { Drawer } from 'antd'; import { Drawer, Form } from 'antd';
import AssetAction from './AssetAction'; import AssetAction from './AssetAction';
const AssetDetailDrawer = (props) => { const AssetDetailDrawer = (props) => {
const { onCancel, visible, id, dirId } = props; const { onCancel, visible, id, dirId } = props;
const [ form ] = Form.useForm();
return ( return (
<Drawer <Drawer
...@@ -18,7 +20,7 @@ const AssetDetailDrawer = (props) => { ...@@ -18,7 +20,7 @@ const AssetDetailDrawer = (props) => {
onCancel && onCancel(); onCancel && onCancel();
}} }}
> >
<AssetAction id={id} dirId={dirId} action='detail' readOnly /> <AssetAction form={form} id={id} dirId={dirId} action='detail' readOnly />
</Drawer> </Drawer>
) )
} }
......
import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, Space, Button } from 'antd';
import { showMessage } from '../../../../util';
import { dispatch } from '../../../../model';
import { AppContext } from '../../../../App';
import MetadataInfo from './MetadataInfo';
import './AssetEdit.less';
const AssetEdit = (props) => {
const { onCancel, visible, action, id, nodeId } = props;
const [ form ] = Form.useForm();
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ elements, setElements ] = useState([]);
const [ asset, setAsset ] = useState('');
const [ metadataId, setMetadataId ] = useState('');
useEffect(() => {
if (visible) {
if (action === 'add') {
getAllElements();
} else if (id) {
getAllElements(() => {
getAsset();
});
}
} else {
setMetadataId('');
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [ visible, action, id ])
const getAllElements = ( cb = null ) => {
dispatch({
type: 'assetmanage.listElements',
callback: data => {
setElements(data||[]);
if (action === 'add') {
let _fieldsValue = {};
(data||[]).forEach(element => {
if (element.manualMaintain === '是') {
_fieldsValue[element.name] = '';
}
})
form.setFieldsValue(_fieldsValue);
}
cb && cb();
}
})
}
const getAsset = () => {
dispatch({
type: 'assetmanage.getDataAssetDetail',
payload: {
dataAssetId: id
},
callback: data => {
setAsset(data);
setMetadataId(data.mid||'');
let _fieldsValue = {};
(data.elements||[]).forEach(element => {
_fieldsValue[element.name] = element.value;
})
form.setFieldsValue(_fieldsValue);
}
})
}
//选中元数据后 内容回填.
const fillElementValueBeforeCreate = (mid = metadataId) => {
dispatch({
type: 'assetmanage.fillElementValueBeforeCreate',
payload: {
params: {
metadataIds: mid
}
},
callback: data => {
let _fieldsValue = {};
(data||[]).forEach(element => {
_fieldsValue[element.name] = element.value;
})
form.setFieldsValue(_fieldsValue);
}
})
}
const onOk = async() => {
try {
const row = await form.validateFields();
const newElements = [...elements];
(newElements||[]).forEach(element => {
if (row.hasOwnProperty(element.name)) {
element.value = row[element.name];
}
});
const params = {
dirId: nodeId,
}
if ((metadataId||'')!=='') {
params.metadataId = metadataId;
}
setConfirmLoading(true);
dispatch({
type: 'assetmanage.addOrUpdateDataAsset',
payload: {
params,
data: action==='add' ? { elements: newElements } : { ...asset, elements: newElements }
},
callback: () => {
setConfirmLoading(false);
onCancel && onCancel(true);
showMessage("success",(action==='add')?"新增成功":"修改成功");
},
error: () => {
setConfirmLoading(false);
}
})
} catch (errInfo) {
console.log('Validate Failed:', errInfo);
setConfirmLoading(false);
}
}
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 5 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 17 },
},
};
return (
<Modal
forceRender
className='asset-edit'
title='资产信息'
visible={ visible }
width={ 600 }
onCancel={() => { onCancel && onCancel(); } }
footer={
<Space>
<Button onClick={() => onCancel && onCancel() }>取消</Button>
<Button type="primary" onClick={ onOk } loading={ confirmLoading }>确定</Button>
</Space>
}
>
<Form {...formItemLayout} form={form}>
<AppContext.Consumer>
{
value => {
value?.onGlobalStateChange&&value?.onGlobalStateChange((state, prev) => {
if (state.message === 'data-govern-show-metadata-list-callback-message') {
setMetadataId(state.data?.metadataId||'');
form?.setFieldsValue({ '资产项': state.data?.metadataInfoJson||'' });
if ((state.data?.metadataId||'') !== '') {
fillElementValueBeforeCreate(state.data?.metadataId||'');
}
}
});
return (
<>
{ (elements||[]).map((element, index) => {
return (
<Form.Item
label={element.name}
name={element.name}
key={index}
>
{ (element.name==='资产项') ? <MetadataInfo /> : <Input disabled={element.manualMaintain==='否'} /> }
</Form.Item>
)
})}
</>
);
}}
</AppContext.Consumer>
</Form>
</Modal>
);
}
export default AssetEdit;
\ No newline at end of file
...@@ -7,7 +7,7 @@ import { Resizable } from 'react-resizable'; ...@@ -7,7 +7,7 @@ import { Resizable } from 'react-resizable';
import FilterElementModal from './FilterElementModal'; import FilterElementModal from './FilterElementModal';
import AssetMount from '../../AssetRecycle/Component/AssetMount'; import AssetMount from '../../AssetRecycle/Component/AssetMount';
import ImportAssetDrawer from './ImportAssetDrawer'; import ImportAssetDrawer from './ImportAssetDrawer';
import AssetEdit from './AssetEdit'; import AssetEdit from './AddAssetModel';
import AssetDetailDrawer from "./AssetDetailDrawer"; import AssetDetailDrawer from "./AssetDetailDrawer";
import { dispatch, dispatchLatestHomepage } from '../../../../model'; import { dispatch, dispatchLatestHomepage } from '../../../../model';
import { showMessage, showNotifaction, getQueryParam, inputWidth, isSzseEnv } from '../../../../util'; import { showMessage, showNotifaction, getQueryParam, inputWidth, isSzseEnv } from '../../../../util';
...@@ -61,7 +61,6 @@ const AssetTable = (props) => { ...@@ -61,7 +61,6 @@ const AssetTable = (props) => {
const [ assetMountVisible, setAssetMountVisible ] = useState(false); const [ assetMountVisible, setAssetMountVisible ] = useState(false);
const [ assetDetailDrawerVisible, setAssetDetailDrawerVisible ] = useState(false); const [ assetDetailDrawerVisible, setAssetDetailDrawerVisible ] = useState(false);
// const [ currentAssetId, setCurrentAssetId ] = useState(''); // const [ currentAssetId, setCurrentAssetId ] = useState('');
const [ assetEditAction, setAssetEditAction ] = useState('');
const [ pagination, setPagination ] = useState( { pageNum: 1, pageSize: 20 } ); const [ pagination, setPagination ] = useState( { pageNum: 1, pageSize: 20 } );
const { pageNum, pageSize } = pagination; const { pageNum, pageSize } = pagination;
const [ keyword, setKeyword ] = useState(''); const [ keyword, setKeyword ] = useState('');
...@@ -326,7 +325,6 @@ const AssetTable = (props) => { ...@@ -326,7 +325,6 @@ const AssetTable = (props) => {
} }
const addAsset =()=>{ const addAsset =()=>{
setAssetEditAction('add');
setAssetEditVisible(true); setAssetEditVisible(true);
} }
...@@ -578,7 +576,6 @@ const AssetTable = (props) => { ...@@ -578,7 +576,6 @@ const AssetTable = (props) => {
<AssetEdit <AssetEdit
visible={assetEditVisible} visible={assetEditVisible}
action={assetEditAction}
nodeId={nodeId} nodeId={nodeId}
onCancel={onAssetEditCancel} onCancel={onAssetEditCancel}
/> />
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { Form } from 'antd';
import { CaretLeftOutlined, CaretRightOutlined } from '@ant-design/icons'; import { CaretLeftOutlined, CaretRightOutlined } from '@ant-design/icons';
import AssetTree from './Component/AssetTree'; import AssetTree from './Component/AssetTree';
...@@ -22,6 +23,7 @@ const AssetManage = (props) => { ...@@ -22,6 +23,7 @@ const AssetManage = (props) => {
const [ directoryChanged, setDirectoryChanged ] = useState(false); const [ directoryChanged, setDirectoryChanged ] = useState(false);
const [ elementsChanged, setElementsChanged ] = useState(false); const [ elementsChanged, setElementsChanged ] = useState(false);
const [ assetActionChanged, setAssetActionChanged ] = useState(false); const [ assetActionChanged, setAssetActionChanged ] = useState(false);
const [ form ] = Form.useForm();
const { assetId, assetDirId } = assetParams; const { assetId, assetDirId } = assetParams;
...@@ -74,7 +76,7 @@ const AssetManage = (props) => { ...@@ -74,7 +76,7 @@ const AssetManage = (props) => {
<AssetTable nodeId={nodeId} reference={AssetManageReference} elementsChanged={elementsChanged} assetActionChanged={assetActionChanged} onSelect={onTableSelect} onCountChange={onAssetCountChange} {...props} /> <AssetTable nodeId={nodeId} reference={AssetManageReference} elementsChanged={elementsChanged} assetActionChanged={assetActionChanged} onSelect={onTableSelect} onCountChange={onAssetCountChange} {...props} />
</div> </div>
<div className='right'> <div className='right'>
<AssetAction id={assetId} dirId={assetDirId} action='detail' onChange={onAssetActionChange} /> <AssetAction form={form} id={assetId} dirId={assetDirId} action='detail' onChange={onAssetActionChange} />
</div> </div>
</div> </div>
) )
......
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