Commit c890010c authored by XieZhiXiong's avatar XieZhiXiong

feat: 调整布局

parent ccc45f48
...@@ -3,26 +3,21 @@ import styled from 'styled-components' ...@@ -3,26 +3,21 @@ import styled from 'styled-components'
import { toArr } from '@formily/shared'; import { toArr } from '@formily/shared';
import { SchemaField, FormPath } from '@formily/antd'; import { SchemaField, FormPath } from '@formily/antd';
import { Button } from 'antd'; import { Button } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
// 由于自增列表里 无法进行mega布局, 所以只能在该组件下 重写样式 // 由于自增列表里 无法进行mega布局, 所以只能在该组件下 重写样式
const RowStyleLayout = styled(props => <div {...props} />)` const RowStyleLayout = styled(({ style, ...restProps }) => <div {...restProps} style={{ paddingRight: 56, position: 'relative', ...style, }} />)`
.ant-btn {
margin-right: 16px;
}
.ant-form-item {
display: inline-flex;
margin-right: 16px;
margin-bottom: 16px;
}
> .ant-form-item { > .ant-form-item {
margin-bottom: 20px; width: 100%;
margin-right: 20px; flex: 1;
} }
> .ant-form-item:last-child { .schema-wrap {
margin-right: 0; width: 100%;
} }
.ant-form-item-control { .btn-remove {
max-width: none; position: absolute;
top: 0;
right: 0;
} }
` `
...@@ -34,17 +29,21 @@ const CustomAddArray = (props) => { ...@@ -34,17 +29,21 @@ const CustomAddArray = (props) => {
const onRemove = index => mutators.remove(index) const onRemove = index => mutators.remove(index)
return ( return (
<div> <div style={{ width: '100%', flex: 1 }}>
{toArr(value).map((item, index, arr) => ( {toArr(value).map((item, index, arr) => (
<RowStyleLayout {...componentProps} key={index}> <RowStyleLayout {...componentProps} key={index}>
<SchemaField path={FormPath.parse(path).concat(index)} onlyRenderProperties/> <SchemaField path={FormPath.parse(path).concat(index)} onlyRenderProperties/>
<Button onClick={onAdd.bind(null, index)} type='primary'>+</Button> <Button className="btn-remove" onClick={onRemove.bind(null, index)}>-</Button>
<Button onClick={onRemove.bind(null, index)}>-</Button>
</RowStyleLayout> </RowStyleLayout>
))} ))}
{(!value || !value.length) && ( <Button
<Button onClick={onAdd} type='primary'>+</Button> onClick={onAdd}
)} type="dashed"
icon={<PlusOutlined />}
block
>
添加
</Button>
</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