feat: add onTrigger to Actions component
This commit is contained in:
parent
2fd4e2fa61
commit
6b84446697
@ -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>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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}
|
||||||
|
@ -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}
|
||||||
|
Loading…
Reference in New Issue
Block a user