chore: table2 修复ts报错问题 (#5259)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>
This commit is contained in:
wanglinfang2014 2022-08-30 10:32:25 +08:00 committed by RUNZE LU
parent 6f9a5082cf
commit e206e821b1
3 changed files with 26 additions and 27 deletions

View File

@ -74,7 +74,7 @@ export interface RowSelectionOptionProps {
export interface RowSelectionProps {
type: string;
rowClick: boolean; // 点击复选框选中还是点击整行选中
rowClick?: boolean; // 点击复选框选中还是点击整行选中
fixed: boolean; // 只能固定在左边
selectedRowKeys: Array<string | number>;
keyField?: string; // 默认是key可自定义

View File

@ -26,8 +26,8 @@ export interface HeadCellSearchProps extends RendererProps {
onSearch?: (values: object) => void;
onAction?: Function;
store: ITableStore2;
sortable: boolean;
label: string;
sortable?: boolean;
label?: string;
orderBy: string;
orderDir: string;
popOverContainer?: any;

View File

@ -30,8 +30,6 @@ import {Icon, Table, Spinner, BadgeObject} from 'amis-ui';
import type {
SortProps,
ColumnProps,
RowSelectionProps,
ExpandableProps,
OnRowProps,
SummaryProps
} from 'amis-ui/lib/components/table';
@ -252,7 +250,7 @@ export interface TableSchema2 extends BaseSchema {
/**
*
*/
columnsTogglable?: boolean | string | SchemaObject;
columnsTogglable?: 'auto' | boolean | SchemaObject;
/**
*
@ -324,11 +322,6 @@ export interface TableSchema2 extends BaseSchema {
*/
showHeader?: boolean;
/**
*
*/
className?: string;
/**
*
*/
@ -375,15 +368,15 @@ export type Table2RendererEvent =
export type Table2RendererAction = 'selectAll' | 'clearAll' | 'select';
export interface Table2Props extends RendererProps, Omit<TableSchema2, 'type'> {
export interface Table2Props extends RendererProps {
title?: string;
columns: Array<ColumnSchema | ColumnProps>;
onSelect?: Function;
reUseRow?: boolean;
getEntryId?: Function;
getEntryId?: (entry: any, index: number) => string;
store: ITableStore2;
rowSelection?: RowSelectionSchema | RowSelectionProps;
expandable?: ExpandableSchema | ExpandableProps;
rowSelection?: RowSelectionSchema;
expandable?: ExpandableSchema;
classnames: ClassNamesFn;
onSave?: Function;
onSaveOrder?: Function;
@ -483,10 +476,13 @@ export default class Table2 extends React.Component<Table2Props, object> {
// selectedRowKeysExpr比selectedRowKeys优先级高
if (props.rowSelection && props.rowSelection.selectedRowKeysExpr) {
rows.forEach((row: any, index: number) => {
const flag = evalExpression(props.rowSelection.selectedRowKeysExpr, {
record: row,
rowIndex: index
});
const flag = evalExpression(
props.rowSelection?.selectedRowKeysExpr || '',
{
record: row,
rowIndex: index
}
);
if (flag) {
selectedRowKeys.push(row[props?.rowSelection?.keyField || 'key']);
}
@ -496,16 +492,19 @@ export default class Table2 extends React.Component<Table2Props, object> {
}
if (updateRows && selectedRowKeys.length > 0) {
store.updateSelected(selectedRowKeys, props.rowSelection.keyField);
store.updateSelected(selectedRowKeys, props.rowSelection?.keyField);
}
let expandedRowKeys: Array<string | number> = [];
if (props.expandable && props.expandable.expandedRowKeysExpr) {
rows.forEach((row: any, index: number) => {
const flag = evalExpression(props.expandable.expandedRowKeysExpr, {
record: row,
rowIndex: index
});
const flag = evalExpression(
props.expandable?.expandedRowKeysExpr || '',
{
record: row,
rowIndex: index
}
);
if (flag) {
expandedRowKeys.push(row[props?.expandable?.keyField || 'key']);
}
@ -515,7 +514,7 @@ export default class Table2 extends React.Component<Table2Props, object> {
}
if (updateRows && expandedRowKeys.length > 0) {
store.updateExpanded(expandedRowKeys, props.expandable.keyField);
store.updateExpanded(expandedRowKeys, props.expandable?.keyField);
}
return updateRows;
@ -1061,7 +1060,7 @@ export default class Table2 extends React.Component<Table2Props, object> {
return rendererEvent?.prevented;
}
store.updateSelected(selectedRowKeys, rowSelection.keyField);
store.updateSelected(selectedRowKeys, rowSelection?.keyField);
onSelect && onSelect(selectedRows, unSelectedRows);
}
@ -1185,7 +1184,7 @@ export default class Table2 extends React.Component<Table2Props, object> {
record: item,
rowIndex
});
if (flag) {
if (flag && keyField) {
selected.push(item[keyField]);
}
});