优化代码

This commit is contained in:
smallchill 2019-01-24 22:14:52 +08:00
parent e3967744f1
commit 203d28c260

View File

@ -100,9 +100,8 @@ export default class Grid extends PureComponent {
const selectKey = row[pkField] || row[childPkField]; const selectKey = row[pkField] || row[childPkField];
if (`${selectKey}`.indexOf(',') > 0) { if (`${selectKey}`.indexOf(',') > 0) {
return `${selectKey}`.split(','); return `${selectKey}`.split(',');
} else {
return selectKey;
} }
return selectKey;
}); });
}; };
@ -199,9 +198,7 @@ export default class Grid extends PureComponent {
} = this.props; } = this.props;
let { columns } = this.props; let { columns } = this.props;
const actionButtons = buttons.filter(button => { const actionButtons = buttons.filter(button => button.action === 2 || button.action === 3);
return button.action === 2 || button.action === 3;
});
if (columns && Array.isArray(columns) && actionButtons.length > 0) { if (columns && Array.isArray(columns) && actionButtons.length > 0) {
const key = pkField || rowKey || 'id'; const key = pkField || rowKey || 'id';
@ -210,23 +207,21 @@ export default class Grid extends PureComponent {
{ {
title: formatMessage({ id: 'table.columns.action' }), title: formatMessage({ id: 'table.columns.action' }),
width: actionColumnWidth || 200, width: actionColumnWidth || 200,
render: (text, record) => { render: (text, record) => (
return ( <Fragment>
<Fragment> {actionButtons.map((button, index) => (
{actionButtons.map((button, index) => ( <Fragment key={button.code}>
<Fragment key={button.code}> {index > 0 ? <Divider type="vertical" /> : null}
{index > 0 ? <Divider type="vertical" /> : null} <a
<a title={formatMessage({ id: `button.${button.alias}.name` })}
title={formatMessage({ id: `button.${button.alias}.name` })} onClick={() => this.handelClick(button, [record[childPkField || key]])}
onClick={() => this.handelClick(button, [record[childPkField || key]])} >
> <FormattedMessage id={`button.${button.alias}.name`} />
<FormattedMessage id={`button.${button.alias}.name`} /> </a>
</a> </Fragment>
</Fragment> ))}
))} </Fragment>
</Fragment> ),
);
},
}, },
]; ];
} }