///
import React from 'react';
import Sortable from 'sortablejs';
import { ITableStore, IScopedContext, SchemaExpression, RendererProps, SchemaNode, ActionObject } from 'fabos-amis-core';
import { BadgeObject, SpinnerExtraProps } from 'fabos-amis-ui';
import { TableCell } from './TableCell';
import type { AutoGenerateFilterObject } from '../CRUD';
import { BaseSchema, SchemaApi, SchemaClassName, SchemaObject, SchemaTokenizeableString, SchemaTpl } from '../../Schema';
import { SchemaPopOver } from '../PopOver';
import { SchemaQuickEdit } from '../QuickEdit';
import { SchemaCopyable } from '../Copyable';
import { SchemaRemark } from '../Remark';
import type { IColumn, IRow } from 'fabos-amis-core';
/**
* 表格列,不指定类型时默认为文本类型。
*/
export type TableColumnObject = {
/**
* 列标题
*/
label: string;
/**
* 配置是否固定当前列
*/
fixed?: 'left' | 'right' | 'none';
/**
* 绑定字段名
*/
name?: string;
/**
* 配置查看详情功能
*/
popOver?: SchemaPopOver;
/**
* 配置快速编辑功能
*/
quickEdit?: SchemaQuickEdit;
/**
* 作为表单项时,可以单独配置编辑时的快速编辑面板。
*/
quickEditOnUpdate?: SchemaQuickEdit;
/**
* 配置点击复制功能
*/
copyable?: SchemaCopyable;
/**
* 配置是否可以排序
*/
sortable?: boolean;
/**
* 是否可快速搜索
*/
searchable?: boolean | SchemaObject;
/**
* 配置是否默认展示
*/
toggled?: boolean;
/**
* 列宽度
*/
width?: number | string;
/**
* 列对齐方式
*/
align?: 'left' | 'right' | 'center' | 'justify';
/**
* 列样式表
*/
className?: string;
/**
* 单元格样式表达式
*/
classNameExpr?: string;
/**
* 列头样式表
*/
labelClassName?: string;
/**
* todo
*/
filterable?: boolean | {
source?: string;
options?: Array;
};
/**
* 结合表格的 footable 一起使用。
* 填写 *、xs、sm、md、lg指定 footable 的触发条件,可以填写多个用空格隔开
*/
breakpoint?: '*' | 'xs' | 'sm' | 'md' | 'lg';
/**
* 提示信息
*/
remark?: SchemaRemark;
/**
* 默认值, 只有在 inputTable 里面才有用
*/
value?: any;
/**
* 是否唯一, 只有在 inputTable 里面才有用
*/
unique?: boolean;
/**
* 表格列单元格是否可以获取父级数据域值,默认为true,该配置对当前列内单元格生效
*/
canAccessSuperData?: boolean;
/**
* 当一次性渲染太多列上有用,默认为 100,可以用来提升表格渲染性能
* @default 100
*/
lazyRenderAfter?: number;
/**
* 单元格内部组件自定义样式 style作为单元格自定义样式的配置
*/
innerStyle?: {
[propName: string]: any;
};
};
export type TableColumnWithType = SchemaObject & TableColumnObject;
export type TableColumn = TableColumnWithType | TableColumnObject;
type AutoFillHeightObject = Record<'height' | 'maxHeight', number>;
/**
* Table 表格渲染器。
* 文档:https://aisuda.bce.baidu.com/amis/zh-CN/components/table
*/
export interface TableSchema extends BaseSchema {
/**
* 指定为表格渲染器。
*/
type: 'table' | 'static-table';
/**
* 是否固定表头
*/
affixHeader?: boolean;
/**
* 是否固底
*/
affixFooter?: boolean;
/**
* 表格的列信息
*/
columns?: Array;
/**
* 展示列显示开关,自动即:列数量大于或等于5个时自动开启
*/
columnsTogglable?: boolean | 'auto';
/**
* 是否开启底部展示功能,适合移动端展示
*/
footable?: boolean | {
expand?: 'first' | 'all' | 'none';
/**
* 是否为手风琴模式
*/
accordion?: boolean;
};
/**
* 底部外层 CSS 类名
*/
footerClassName?: SchemaClassName;
/**
* 顶部外层 CSS 类名
*/
headerClassName?: SchemaClassName;
/**
* 占位符
*/
placeholder?: string | SchemaTpl;
/**
* 是否显示底部
*/
showFooter?: boolean;
/**
* 是否显示头部
*/
showHeader?: boolean;
/**
* 数据源:绑定当前环境变量
*/
source?: SchemaTokenizeableString;
/**
* 表格 CSS 类名
*/
tableClassName?: SchemaClassName;
/**
* 标题
*/
title?: string;
/**
* 工具栏 CSS 类名
*/
toolbarClassName?: SchemaClassName;
/**
* 合并单元格配置,配置数字表示从左到右的多少列自动合并单元格。
*/
combineNum?: number | SchemaExpression;
/**
* 合并单元格配置,配置从第几列开始合并。
*/
combineFromIndex?: number;
/**
* 顶部总结行
*/
prefixRow?: Array;
/**
* 底部总结行
*/
affixRow?: Array;
/**
* 是否可调整列宽
*/
resizable?: boolean;
/**
* 行样式表表达式
*/
rowClassNameExpr?: string;
/**
* 行角标
*/
itemBadge?: BadgeObject;
/**
* 开启查询区域,会根据列元素的searchable属性值,自动生成查询条件表单
*/
autoGenerateFilter?: AutoGenerateFilterObject | boolean;
/**
* 表格是否可以获取父级数据域值,默认为false
*/
canAccessSuperData?: boolean;
/**
* 表格自动计算高度
*/
autoFillHeight?: boolean | AutoFillHeightObject;
/**
* table layout
*/
tableLayout?: 'fixed' | 'auto';
/**
* 懒加载 API,当行数据中用 defer: true 标记了,则其孩子节点将会用这个 API 来拉取数据。
*/
deferApi?: SchemaApi;
}
export interface TableProps extends RendererProps, SpinnerExtraProps {
title?: string;
header?: SchemaNode;
footer?: SchemaNode;
actions?: ActionObject[];
className?: string;
headerClassName?: string;
footerClassName?: string;
store: ITableStore;
columns?: Array;
headingClassName?: string;
toolbarClassName?: string;
headerToolbarClassName?: string;
footerToolbarClassName?: string;
tableClassName?: string;
source?: string;
selectable?: boolean;
selected?: Array;
maxKeepItemSelectionLength?: number;
maxItemSelectionLength?: number;
valueField?: string;
draggable?: boolean;
columnsTogglable?: boolean | 'auto';
affixHeader?: boolean;
affixColumns?: boolean;
combineNum?: number | SchemaExpression;
combineFromIndex?: number;
footable?: boolean | {
expand?: 'first' | 'all' | 'none';
expandAll?: boolean;
accordion?: boolean;
};
expandConfig?: {
expand?: 'first' | 'all' | 'none';
expandAll?: boolean;
accordion?: boolean;
};
itemCheckableOn?: string;
itemDraggableOn?: string;
itemActions?: Array;
onSelect: (selectedItems: Array