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

View File

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

View File

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

View File

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