Commit 1ee001e7 by zhaochengxiang

要素调整

parent 87d65c56
import React, { useEffect, useState } from 'react';
import { Form, Spin, Input, Descriptions, Space, Button, Tooltip } from 'antd';
import { Form, Spin, Input, Descriptions, Space, Button, Tooltip, Select } from 'antd';
import { DownOutlined, UpOutlined } from '@ant-design/icons';
import MetadataInfo from './MetadataInfo';
......@@ -103,6 +103,18 @@ const AssetAction = (props) => {
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: () => {
......@@ -357,6 +369,31 @@ const AssetAction = (props) => {
},
};
const elementComponent = (element) => {
if (element.name==='资产项') return <MetadataInfo />
if (element.selectMode==='单选') {
return (
<Select
allowClear
disabled={element.manualMaintain==='否'}
>
{
element.optional?.split(',').map((value, index) => {
return <Select.Option key={index} value={value}>
{value}
</Select.Option>
})
}
</Select>
)
}
if (element.selectMode==='多选') return <MultipleSelect element={element} />
return <Input disabled={element.manualMaintain==='否'} />
}
return (
<div
className='flex'
......@@ -523,7 +560,7 @@ const AssetAction = (props) => {
</div>
<div className='px-common py-compact-common'>
{
(currentAction==='add'||currentAction==='edit') ? <Form {...formItemLayout} form={form}>
(currentAction==='add'||currentAction==='edit') ?
<AppContext.Consumer>
{
value => {
......@@ -541,22 +578,27 @@ const AssetAction = (props) => {
});
return (
(sameAttributeElements||[]).map((element, _index) => {
return (
<Form.Item
label={<div className='title-color'>{element.name||''}</div>}
name={element.name}
key={_index}
style={{ marginBottom: (_index===sameAttributeElements.length-1)? 0 : 15 }}
>
{ (element.name==='资产项') ? <MetadataInfo /> : <Input disabled={element.manualMaintain==='否'} /> }
</Form.Item>
);
})
<Form {...formItemLayout} form={form}>
{
(sameAttributeElements||[]).map((element, _index) => {
return (
<Form.Item
label={<div className='title-color'>{element.name||''}</div>}
name={element.name}
rules={[{ required: element.required }]}
key={_index}
style={{ marginBottom: (_index===sameAttributeElements.length-1)? 0 : 15 }}
>
{elementComponent(element)}
</Form.Item>
);
})
}
</Form>
);
}}
</AppContext.Consumer>
</Form> : <Descriptions column={1}>
: <Descriptions column={1}>
{
(sameAttributeElements||[]).map((item, index) => {
return (
......@@ -601,4 +643,30 @@ const AssetAction = (props) => {
)
}
export default AssetAction;
\ No newline at end of file
export default AssetAction;
const MultipleSelect = ({ value = null, element, onChange }) => {
const handleChange = (values) => {
onChange?.(values?.join(','))
}
return (
<Select
allowClear
value={value?value?.split(','):[]}
mode='multiple'
disabled={element.manualMaintain==='否'}
onChange={handleChange}
>
{
element.optional?.split(',').map((value, index) => {
return <Select.Option key={index} value={value}>
{value}
</Select.Option>
})
}
</Select>
)
}
\ No newline at end of file
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