@aplus-frontend/ui
Version:
147 lines (146 loc) • 5.49 kB
TypeScript
import { CSSProperties, StyleValue, VNodeChild } from 'vue';
import { AgGridColumnType, AgGridExpose, AgGridProps, AgGridRowSelection, AgGridSlots } from '../../ag-grid';
import { CreateModalFuncProps } from '../../ap-modal';
import { Recordable } from '../../type';
import { GridApi } from './hooks/use-ag-grid-instance';
export type GetRowKey<TableRowType> = ((record: TableRowType) => string | number) | string;
export type UpdatePropsFn<T> = (props: Partial<AgGridPreviewModalProps<T>> | ((props: AgGridPreviewModalProps<T>) => Partial<AgGridPreviewModalProps<T>>)) => void;
export type UpdateSelectPropsFn<T> = (props: Partial<AgGridSelectModalProps<T>> | ((props: AgGridSelectModalProps<T>) => Partial<AgGridSelectModalProps<T>>)) => void;
/** AgGridModal 基础类型 */
export interface AgGridModalBasicProps<TableRowType = any> {
title?: VNodeChild;
width?: string | number;
modalProps?: Omit<CreateModalFuncProps, 'content'>;
columns: AgGridColumnType<TableRowType, any>[];
getRowKey: GetRowKey<TableRowType>;
api?: (params: any) => Promise<RequestReturn<TableRowType>>;
/** 渲染头部信息 */
renderHeader?: (gridApi: Omit<GridApi, 'setInstance'>, modalApi: {
updateProps: UpdatePropsFn<TableRowType>;
}) => VNodeChild;
rowHeight?: number;
height?: CSSProperties['height'];
}
/** 刷新方式 */
export type RefreshType = 'reset' | 'submit' | 'submitWith';
/** 只读模式 */
export interface AgGridPreviewModalProps<RowType = any> extends AgGridModalBasicProps<RowType> {
/** ag-grid 插槽 */
gridSlots?: AgGridSlots<RowType>;
/** ag-grid 额外配置 */
gridProps?: Omit<AgGridProps<RowType>, 'rowHeight' | 'rowKey'>;
}
/** 只读模式返回值 */
export interface PreviewModalReturnType<RowType = any> {
/** 打开弹框 */
open(opt?: OpenOptions): void;
/** 刷新表格数据 */
refresh: (type: RefreshType) => void;
/** 获取ag-grid实例 */
getAgGridInstance: () => AgGridExpose | undefined;
/** 修改hook的props */
updateProps: UpdatePropsFn<RowType>;
}
export interface OpenOptions {
/** 发起网络请求携带的额外参数 */
extraParams?: Recordable;
}
/** 可选模式 */
export interface AgGridSelectModalProps<RowType = any> extends AgGridModalBasicProps<RowType> {
/** ag-grid 插槽 */
gridSlots?: AgGridSlots<RowType>;
/**
* 选择模式
* - radio: 单选模式
* - checkbox: 多选模式
* @default 'checkbox'
*/
mode?: 'radio' | 'checkbox';
/**
* 合并规则
* - old 老数据优先
* - new 新数据优先
* @default 'old'
*/
mergeRule?: 'old' | 'new';
/** 点击确认后执行的回调 */
finishCallback?: (data: OpenReturnType<RowType>) => void;
/** 最多选择多少条 */
maxCount?: number;
/** 禁用选项 */
disabledCheckbox?: boolean | ((record: RowType, actions: Omit<GridApi, 'setInstance'>) => boolean);
/** 额外的rowSelection配置 */
rowSelection?: Omit<AgGridRowSelection<RowType>, 'disabled'>;
/** modal标题插槽 */
modalTitleSlots?: ModalTitleSlots;
/** 在finishCallback执行前执行,返回reject终止后续执行 */
beforeOk?: (data: OpenReturnType<RowType>) => Promise<any> | void;
/** 设置是否是复杂布局 */
modalLayout?: ModalLayoutConfig<RowType>;
/** ag-grid 额外配置 */
gridProps?: Omit<AgGridProps<RowType>, 'rowSelection' | 'rowKey'>;
}
export interface SelectModalReturnType<T = any> {
/** 打开弹框 */
open: (selectRows?: T[], options?: OpenOptions, isAsync?: boolean) => Promise<OpenReturnType<T>> | undefined;
/** 异步打开弹框 */
asyncOpen: (selectRows?: T[], options?: OpenOptions) => Promise<OpenReturnType<T>>;
/** 刷新表格数据 */
refresh: (type?: RefreshType) => void;
/** 获取表格实例 */
getAgGridInstance: () => AgGridExpose | undefined;
/** 获取原子化内容 */
genContent: (selectedRows?: T[]) => VNodeChild;
/** 获取数据并校验 */
validate: () => Promise<OpenReturnType<T>>;
/** 修改hook的props */
updateProps: UpdateSelectPropsFn<T>;
}
export interface RequestReturn<T = any> {
records: T[];
total: number;
}
/** open打开方法返回的值的类型 */
export interface OpenReturnType<RowType> {
keys: (string | number)[];
rows: RowType[];
}
/** modal-title slots */
export interface ModalTitleSlots {
/** 标题 suffix 插槽 */
default: (props: {
maxCount: number;
count: number;
}) => VNodeChild;
}
/** 弹框布局props */
export interface ModalLayoutProps {
/** 左侧标题 */
leftTitle?: string | VNodeChild;
/** 右侧内容样式 */
rightContentStyle?: StyleValue;
/** 中间分割线向上偏移量 */
dividerOffset?: number;
/** 是否有边框 */
bordered?: boolean;
}
/** modal-layout配置 */
export interface ModalLayoutConfig<T = any> extends ModalLayoutProps {
/** 右侧标题插槽 */
rightTitle?: (selectedCount: number) => any;
/** 右侧底部插槽 */
rightBottom?: (props: {
records: T[];
actions: {
deleteItem: (record: T) => void;
};
}) => any;
/** 已经选择item渲染, 选择项渲染插槽 */
renderSelectedItem: (props: {
record: T;
actions: {
deleteItem: (record: T) => void;
deleteCurrent: () => void;
};
}) => any;
}