feat(table): action hook配置加入index参数

This commit is contained in:
roymondchen 2023-04-25 11:38:36 +08:00
parent af393e34fb
commit 26835f6a29
2 changed files with 8 additions and 7 deletions

View File

@ -6,7 +6,7 @@
v-show="display(action.display, scope.row) && !editState[scope.$index]"
class="action-btn"
text
type="primary"
:type="action.buttonType || 'primary'"
size="small"
:icon="action.icon"
:key="actionIndex"
@ -72,13 +72,13 @@ const formatter = (fuc: string | Function | undefined, row: any) => {
};
const actionHandler = async (action: ColumnActionConfig, row: any, index: number) => {
await action.before?.(row);
await action.before?.(row, index);
if (action.type === 'edit') {
props.editState[index] = row;
} else {
await action.handler?.(row);
await action.handler?.(row, index);
}
action.after?.(row);
action.after?.(row, index);
};
const save = async (index: number, config: ColumnConfig) => {

View File

@ -20,13 +20,14 @@ import { FormConfig, FormValue } from '@tmagic/form';
export interface ColumnActionConfig {
type?: 'delete' | 'copy' | 'edit';
buttonType: string;
display?: (row: any) => boolean;
text: string | ((row: any) => string);
name: string;
icon?: any;
handler?: (row: any) => Promise<any> | any;
before?: (row: any) => void;
after?: (row: any) => void;
handler?: (row: any, index: number) => Promise<any> | any;
before?: (row: any, index: number) => void;
after?: (row: any, index: number) => void;
action?: (data: { data: any }) => void;
}