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

View File

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