Commit 1ee001e7 by zhaochengxiang

要素调整

parent 87d65c56
import React, { useEffect, useState } from 'react'; 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 { DownOutlined, UpOutlined } from '@ant-design/icons';
import MetadataInfo from './MetadataInfo'; import MetadataInfo from './MetadataInfo';
...@@ -103,6 +103,18 @@ const AssetAction = (props) => { ...@@ -103,6 +103,18 @@ const AssetAction = (props) => {
setAssetParams({ assets: {}, attributes: _attributes, attributesFoldMap: newAttributesFoldMap }); setAssetParams({ assets: {}, attributes: _attributes, attributesFoldMap: newAttributesFoldMap });
form?.resetFields(); form?.resetFields();
if (currentAction==='add') {
let newFiledsValue = {};
(data||[]).forEach(element => {
if (element.defaultValue) {
newFiledsValue[element.name] = element.defaultValue
}
});
form?.setFieldsValue(newFiledsValue);
}
cb && cb(); cb && cb();
}, },
error: () => { error: () => {
...@@ -357,6 +369,31 @@ const AssetAction = (props) => { ...@@ -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 ( return (
<div <div
className='flex' className='flex'
...@@ -523,7 +560,7 @@ const AssetAction = (props) => { ...@@ -523,7 +560,7 @@ const AssetAction = (props) => {
</div> </div>
<div className='px-common py-compact-common'> <div className='px-common py-compact-common'>
{ {
(currentAction==='add'||currentAction==='edit') ? <Form {...formItemLayout} form={form}> (currentAction==='add'||currentAction==='edit') ?
<AppContext.Consumer> <AppContext.Consumer>
{ {
value => { value => {
...@@ -541,22 +578,27 @@ const AssetAction = (props) => { ...@@ -541,22 +578,27 @@ const AssetAction = (props) => {
}); });
return ( return (
<Form {...formItemLayout} form={form}>
{
(sameAttributeElements||[]).map((element, _index) => { (sameAttributeElements||[]).map((element, _index) => {
return ( return (
<Form.Item <Form.Item
label={<div className='title-color'>{element.name||''}</div>} label={<div className='title-color'>{element.name||''}</div>}
name={element.name} name={element.name}
rules={[{ required: element.required }]}
key={_index} key={_index}
style={{ marginBottom: (_index===sameAttributeElements.length-1)? 0 : 15 }} style={{ marginBottom: (_index===sameAttributeElements.length-1)? 0 : 15 }}
> >
{ (element.name==='资产项') ? <MetadataInfo /> : <Input disabled={element.manualMaintain==='否'} /> } {elementComponent(element)}
</Form.Item> </Form.Item>
); );
}) })
}
</Form>
); );
}} }}
</AppContext.Consumer> </AppContext.Consumer>
</Form> : <Descriptions column={1}> : <Descriptions column={1}>
{ {
(sameAttributeElements||[]).map((item, index) => { (sameAttributeElements||[]).map((item, index) => {
return ( return (
...@@ -602,3 +644,29 @@ const AssetAction = (props) => { ...@@ -602,3 +644,29 @@ const AssetAction = (props) => {
} }
export default AssetAction; 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