feat: add onTrigger to Actions component

This commit is contained in:
chenos 2020-12-11 15:11:45 +08:00
parent 2fd4e2fa61
commit 6b84446697
4 changed files with 45 additions and 9 deletions

View File

@ -1,16 +1,20 @@
import React, { useRef } from 'react';
import { Button } from 'antd';
import { Button, Popconfirm } from 'antd';
import ViewFactory from '@/components/views';
export function Destroy(props) {
console.log(props);
const { title, viewId } = props.schema;
const { onTrigger } = props;
const { title, viewId, isBulk = true } = props.schema;
const drawerRef = useRef<any>();
return (
<>
<Button type={'primary'} onClick={() => {
}}>{title}</Button>
<Popconfirm title="确认删除吗?" onConfirm={() => {
console.log('destroy', onTrigger);
onTrigger && onTrigger();
}}>
<Button type={'primary'}>{title}</Button>
</Popconfirm>
</>
)
}

View File

@ -25,15 +25,23 @@ export function Action(props) {
const { schema = {} } = props;
// cnsole.log(schema);
const { type } = schema;
const Action = getAction(type);
return Action && <Action {...props}/>;
const Component = getAction(type);
return Component && <Component {...props}/>;
}
export function Actions(props) {
const { style, schema, actions = [] } = props;
const { onTrigger = {}, style, schema, actions = [], ...restProps } = props;
console.log(onTrigger);
return actions.length > 0 && (
<Space style={style}>
{actions.map(action => <Action {...props} view={schema} schema={action}/>)}
{actions.map(action => (
<Action
{...restProps}
view={schema}
schema={action}
onTrigger={onTrigger[action.name]}
/>
))}
</Space>
);
}

View File

@ -71,6 +71,18 @@ export function SimpleTable(props: SimpleTableProps) {
onFinish={() => {
refresh();
}}
onTrigger={{
async destroy() {
await api.resource(name).destroy({
associatedKey,
filter: {
[`${rowKey}.in`]: selectedRowKeys,
},
});
await refresh();
console.log('destroy.onTrigger', selectedRowKeys);
}
}}
/>
<ViewFactory
{...props}

View File

@ -87,6 +87,18 @@ export function Table(props: TableProps) {
onFinish={() => {
refresh();
}}
onTrigger={{
async destroy() {
await api.resource(name).destroy({
associatedKey,
filter: {
[`${rowKey}.in`]: selectedRowKeys,
},
});
await refresh();
console.log('destroy.onTrigger', selectedRowKeys);
}
}}
/>
<AntdTable
rowKey={rowKey}