Skip to content

Commit

Permalink
fix:crud不对table下发onEvent,避免事件重复监听&button二次确认问题 (#4595)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm-lv authored Jun 10, 2022
1 parent 077e4f2 commit 7b9182b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/renderers/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -913,25 +913,36 @@ export class ActionRenderer extends React.Component<ActionRendererProps> {
mergedData = createObject(data, action.args);
}

// 触发渲染器事件
const rendererEvent = await dispatchEvent(
e as React.MouseEvent<any> | string,
mergedData
);

// 阻止原有动作执行
if (rendererEvent?.prevented) {
return;
}

if (!ignoreConfirm && action.confirmText && env.confirm) {
let confirmed = await env.confirm(filter(action.confirmText, mergedData));
if (confirmed) {
// 触发渲染器事件
const rendererEvent = await dispatchEvent(
e as React.MouseEvent<any> | string,
mergedData
);

// 阻止原有动作执行
if (rendererEvent?.prevented) {
return;
}

await onAction(e, action, mergedData);
} else if (action.countDown) {
throw new Error('cancel');
}
} else {
// 触发渲染器事件
const rendererEvent = await dispatchEvent(
e as React.MouseEvent<any> | string,
mergedData
);

// 阻止原有动作执行
if (rendererEvent?.prevented) {
return;
}

await onAction(e, action, mergedData);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/renderers/CRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
autoGenerateFilter,
onSelect,
autoFillHeight,
onEvent,
...rest
} = this.props;

Expand Down

0 comments on commit 7b9182b

Please sign in to comment.