import { RenderFunction, SetupContext, Ref } from 'vue' import { DefineVxeComponentApp, DefineVxeComponentOptions, DefineVxeComponentInstance, VxeComponentBaseOptions, VxeComponentEventParams, VxeComponentSizeType, ValueOf, VxeComponentIsVScrollbar } from '@vxe-ui/core' import { VxeContextMenuPropTypes, VxeContextMenuDefines } from './context-menu' import { VxeScrollbarProps } from './scrollbar' /* eslint-disable no-use-before-define,@typescript-eslint/ban-types */ export declare const VxeList: DefineVxeComponentApp export type VxeListComponent = DefineVxeComponentOptions export type VxeListInstance = DefineVxeComponentInstance, VxeListConstructor> export interface VxeListConstructor extends VxeComponentBaseOptions, VxeListMethods { props: VxeListProps context: SetupContext reactData: ListReactData internalData: ListInternalData getRefMaps(): ListPrivateRef getComputeMaps(): ListPrivateComputed renderVN: RenderFunction } export interface ListPrivateRef { refElem: Ref } export interface VxeListPrivateRef extends ListPrivateRef {} export namespace VxeListPropTypes { export type Size = VxeComponentSizeType export type Data = any[] export type Height = number | string export type MaxHeight = number | string export type Loading = boolean export type AutoResize = boolean export type ClassName = string | ((params: { $list: VxeListConstructor }) => string) export type SyncResize = boolean | string | number export type ShowSeq = boolean export type ShowRadio = boolean export type CheckRowKey = string | number | null export interface RadioConfig { strict?: boolean visibleMethod?: (params: { $list: VxeListConstructor; row: D }) => boolean checkMethod?: (params: { $list: VxeListConstructor; row: D }) => boolean highlight?: boolean showIcon?: boolean trigger?: '' | 'default' | 'row' } export type CheckRowKeys = (string | number | null)[] export type ShowCheckbox = boolean export interface CheckboxConfig { showHeader?: boolean headerTitle?: string | number highlight?: boolean visibleMethod?: (params: { $list: VxeListConstructor; row: D }) => boolean checkMethod?: (params: { $list: VxeListConstructor; row: D }) => boolean showIcon?: boolean trigger?: '' | 'default' | 'row' } export interface RowConfig { /** * 是否需要为每一行的 VNode 设置 key 属性 */ useKey?: boolean /** * 自定义行数据唯一主键的字段名(默认自动生成) */ keyField?: string /** * 显示字段 */ contentField?: string /** * 每一行的高度 */ height?: number | string /** * 给每一行的附加 className */ className?: string | ((params: { row: D; $list: VxeListConstructor }) => string) /** * 当鼠标移到每一行时,是否要高亮当前头 */ isHover?: boolean isCurrent?: boolean padding?: boolean currentMethod?: (params: { row: D }) => boolean } /** * 拖拽排序配置项 */ export interface DragConfig { /** * 是否启用 */ enabled?: boolean /** * 自定义图标 */ icon?: string /** * 是否显示拖拽按钮图标 */ showIcon?: boolean /** * 显示拖拽提示,拖拽过程中显示信息 */ showDragTip?: boolean /** * 触发拖拽方式 */ trigger?: 'default' | 'row' | '' | null /** * 是否显示拖拽辅助状态显示 */ showGuidesStatus?: boolean /** * 是否允许在不同列表之间进行拖拽 */ isCrossListDrag?: boolean /** * 是否显示拖拽动画,启用后由数据量的大小来影响渲染性能 */ animation?: boolean /** * 是否禁用拖拽按钮 */ disabledMethod?(params: { $list: VxeListConstructor; row: D }): boolean /** * 是否显示拖拽按钮 */ visibleMethod?(params: { $list: VxeListConstructor; row: D }): boolean /** * 自定义提示内容 */ tooltipMethod?(params: { $list: VxeListConstructor; row: D }): string | number | null /** * 拖拽开始时是否允许行拖拽调整顺序的方法,该方法的返回值用来决定是否允许被拖拽 */ dragStartMethod?(params: VxeListDefines.RowDragstartEventParams): boolean /** * 拖拽结束时是否允许行拖拽调整顺序的方法,该方法的返回值用来决定是否允许被拖拽调整顺序 */ dragEndMethod?(params: Omit, '_index'>): Promise | boolean } export interface MenuConfig { /** * 是否启用 */ enabled?: boolean /** * 菜单配置 */ options: VxeContextMenuPropTypes.Options /** * 该函数的返回值用来决定是否允许显示右键菜单(对于需要对菜单进行权限控制时可能会用到) */ visibleMethod?(params: { $list: VxeListConstructor; options: VxeContextMenuPropTypes.Options; row: D }): boolean } export interface VirtualYConfig { /** * 指定大于指定行时自动启动纵向虚拟滚动,如果为 0 则总是启用,如果为 -1 则关闭 */ gt?: number /** * 指定每次渲染的数据额外数据,额外数据越大渲染次数就越少,但每次渲染耗时就越久 */ oSize?: number /** * 指定行的 className */ sItem?: string /** * 是否启用 */ enabled?: boolean } /** * 已被 VirtualYConfig 替换 * @deprecated */ export interface ScrollY { /** * 指定大于指定行时自动启动纵向虚拟滚动,如果为 0 则总是启用,如果为 -1 则关闭 */ gt?: number /** * 指定每次渲染的数据额外数据,额外数据越大渲染次数就越少,但每次渲染耗时就越久 */ oSize?: number /** * 指定行的 className */ sItem?: string /** * 是否启用 */ enabled?: boolean } export type UseScrollbar = VxeComponentIsVScrollbar export interface ScrollbarConfig extends Pick { /** * 滚动条宽度 */ width?: number | string /** * 滚动条高度 */ height?: number | string } } export interface VxeListProps { size?: VxeListPropTypes.Size data?: D[] /** * 高度 */ height?: VxeListPropTypes.Height /** * 最大高度 */ maxHeight?: VxeListPropTypes.MaxHeight /** * 加载中 */ loading?: VxeListPropTypes.Loading autoResize?: VxeListPropTypes.AutoResize syncResize?: VxeListPropTypes.SyncResize className?: VxeListPropTypes.ClassName showSeq?: VxeListPropTypes.ShowSeq showRadio?: VxeListPropTypes.ShowRadio checkRowKey?: VxeListPropTypes.CheckRowKey radioConfig?: VxeListPropTypes.RadioConfig showCheckbox?: VxeListPropTypes.ShowCheckbox checkRowKeys?: VxeListPropTypes.CheckRowKeys checkboxConfig?: VxeListPropTypes.CheckboxConfig rowConfig?: VxeListPropTypes.RowConfig dragConfig?: VxeListPropTypes.DragConfig /** * 右键菜单配置项 */ menuConfig?: VxeListPropTypes.MenuConfig /** * 纵向虚拟滚动配置 */ virtualYConfig?: VxeListPropTypes.VirtualYConfig /** * 使用虚拟滚动条 */ useScrollbar?: VxeListPropTypes.UseScrollbar /** * 滚动条配置项 */ scrollbarConfig?: VxeListPropTypes.ScrollbarConfig /** * 已废弃,被 virtual-y-config 替换 * @deprecated */ scrollY?: VxeListPropTypes.ScrollY } export interface ListPrivateComputed {} export interface VxeListPrivateComputed extends ListPrivateComputed {} export interface ListReactData { scrollYLoad: boolean bodyHeight: number headHeight: number footHeight: number customHeight: number customMaxHeight: number parentHeight: number topSpaceHeight: number rowList: any[] selectRadioRow: any currRowFlag: number updateCheckboxFlag: number isAllChecked: boolean isAllIndeterminate: boolean // 滚动条 yThumbHeight: number xThumbWidth: number insertRowFlag: number removeRowFlag: number dragRow: any dragTipText: string isCrossDragRow: boolean } export interface ListInternalData { fullData: any[] afterList: any[] fullKeyMaps: Record rowMaps: Record resizeObserver?: ResizeObserver // 滚动条 scrollObserver?: ResizeObserver isThumbDrag?: boolean thumbDragOffset: number yThumbTop: number xThumbLeft: number lastScrollTop: number lastScrollLeft: number scrollYStore: { startIndex: number endIndex: number visibleSize: number offsetSize: number rowHeight: number } currentRow: any selectCheckboxMaps: Record insertRowMaps: Record removeRowMaps: Record prevDragRow?: any prevDragPos?: 'top' | 'bottom' | '' } export interface ListMethods { dispatchEvent(type: ValueOf, params: Record, evnt: Event | null): void /** * 获取滚动视图元素 */ getScrollViewElem(): HTMLElement | null | undefined /** * 加载数据 * @param data 列表数据 */ loadData(data: any[]): Promise /** * 加载数据 * @param data 列表数据 */ reloadData(data: any[]): Promise /** * 获取列表的全量数据 */ getFullData(): D[] /** * 重新计算列表 */ recalculate(): Promise /** * 如果有滚动条,则滚动到对应的位置 */ scrollTo( x: | { top?: number | null left?: number | null } | number | null | undefined, y?: number | null ): Promise /** * 刷新滚动操作,手动同步滚动相关位置 */ refreshScroll(): Promise /** * 手动清除滚动相关信息,还原到初始状态 */ clearScroll(): Promise /** * 获取主键 */ getRowKey(row: D): string /** * 判断主键是否相同 */ eqRowKey(rowKey1: string | number | null | undefined, rowKey2: string | number | null | undefined): boolean /** * 判断行是否相同 */ eqRow(row1: D, row2: D): boolean /** * 根据行判断主键是否相同 */ eqRowByKey(row1: D, rowKey2: string | number | null | undefined): boolean /** * 根据行查找 */ findRow(list: D[], row: D): D /** * 根据主键查找 */ findRowByKey(list: D[], rowKey: string | number | null | undefined): D /** * 根据行查找索引 */ findRowIndexOf(list: D[], row: D): number /** * 根据主键查找索引 */ findRowIndexOfByKey(list: D[], rowKey: string | number | null | undefined): number /** * 根据主键判断单选框行是否选中 */ isCheckedByRadioRowKey(rowKey: string | number | null | undefined): boolean /** * 判断单选框行是否选中 */ isCheckedByRadioRow(row: D): boolean /** * 根据主键判断复选框行是否选中 */ isCheckedByCheckboxRowKey(rowKey: string | number | null | undefined): boolean /** * 判断复选框行是否选中 */ isCheckedByCheckboxRow(row: D): boolean /** * 只对 row-config.isCurrent 有效,设置已选的当前行 */ setCurrentRow(row: D): Promise /** * 只对 show-radio 有效,根据主键设置当前行 */ setCurrentRowByKey(rowKey: string | number | null | undefined): Promise /** * 只对 show-radio 有效,获取当前行已选的行 */ getCurrentRow(): D | null /** * 只对 show-radio 有效,获取当前行已选的主键 */ getCurrentRowKey(): string | number | null /** * 只对 show-radio 有效,手动清空当前行 */ clearCurrentRow(): Promise /** * 只对 show-radio 有效,设置单选框已选的行 */ setRadioRow(row: D): Promise /** * 只对 show-radio 有效,根据主键设置单选 */ setRadioRowByKey(rowKey: string | number | null | undefined): Promise /** * 只对 show-radio 有效,获取单选框已选的行 */ getRadioRow(): D | null /** * 只对 show-radio 有效,获取单选框已选的主键 */ getRadioRowKey(): string | number | null /** * 只对 show-radio 有效,手动清空单选框 */ clearRadioRow(): Promise /** * 只对 show-checkbox 有效,设置复选框选中的行 */ setCheckboxRow(rows: D | D[], checked: boolean): Promise /** * 只对 show-checkbox 有效,根据主键设置复选框 */ setCheckboxRowByKey(rowKeys: string | number | null | undefined | (string | number | null | undefined)[], checked: boolean): Promise /** * 只对 show-checkbox 有效,获取复选框已选的行 */ getCheckboxRecords(): D[] /** * 只对 show-checkbox 有效,获取复选框已选的行 */ getCheckboxRows(): D[] /** * 只对 show-checkbox 有效,获取复选框已选的主键 */ getCheckboxRowKeys(): (string | number)[] /** * 只对 show-checkbox 有效,手动清空复选框 */ clearCheckboxRow(): Promise /** * 只对 show-checkbox 有效,设置所有行的选中状态 */ setAllCheckboxRow(checked: boolean): Promise /** * 往列表插入临时数据,从第一个行新增一个行或多个行新数据 */ insert(records: any): Promise<{ row: D; rows: D[] }> /** * 往列表指定行中插入临时数据 * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标行顶部 * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标行底部 * 如果 row 为有效行则插入到该行的位置 */ insertAt(records: any, targetRowOrRowKey?: any | -1 | null): Promise<{ row: D; rows: D[] }> /** * 用于 transform 模式,与 insertAt 行为一致,区别就是会插入指定目标的到下一行 */ insertNextAt(records: any, targetRowOrRowKey?: any | -1 | null): Promise<{ row: D; rows: D[] }> /** * 判断行是否为新增的临时数据 */ isInsertByRow(row: any | null): boolean /** * 用于 transform 模式,删除指定行数据,指定 row 或 [row, ...] 删除多条数据,如果为空则删除所有数据 */ remove(rows?: any | any[]): Promise<{ row: D; rows: D[] }> /** * 用于 transform 模式,获取新增的临时数据 */ getInsertRecords(): D[] /** * 用于 transform 模式,获取已删除的数据 */ getRemoveRecords(): D[] /** * 判断数据是否被删除 */ isRemoveByRow(row: any | null): boolean /** * 获取列表数据集 * 获取新增、删除的数据 */ getRecordset(): { insertRecords: D[] removeRecords: D[] } } export interface VxeListMethods extends ListMethods {} export interface ListPrivateMethods { /** * @private */ handleCrossListRowDragInsertEvent(evnt: DragEvent): void /** * @private */ handleCrossListRowDragCancelEvent(evnt: DragEvent): void /** * @private */ handleCrossListRowDragFinishEvent(evnt: DragEvent): void /** * @private */ handleCrossListRowDragoverEmptyEvent(evnt: DragEvent): void /** * @private */ hideCrossListRowDropClearStatus(): void } export interface VxeListPrivateMethods extends ListPrivateMethods {} export type VxeListEmits = ['update:checkRowKey', 'update:checkRowKeys', 'row-click', 'row-dblclick', 'current-change', 'radio-change', 'checkbox-change', 'checkbox-all', 'scroll', 'row-dragstart', 'row-dragover', 'row-dragend', 'row-remove-dragend', 'row-insert-dragend', 'row-menu', 'menu-click'] export namespace VxeListDefines { export interface RowCacheItem { item: any index: number $index: number _index: number } export interface ListEventParams extends VxeComponentEventParams { $list: VxeListConstructor } export interface RowClickParams { row: D } export interface RowClickEventParams extends ListEventParams, RowClickParams {} export interface RowDblclickEventParams extends RowClickEventParams {} export interface RowDragstartEventParams { row: D } export interface RowDragoverEventParams { oldRow: D targetRow: D dragRow: D dragPos: 'top' | 'bottom' offsetIndex: 0 | 1 } export interface RowDragendEventParams { newRow: D oldRow: D dragRow: D dragPos: 'top' | 'bottom' offsetIndex: 0 | 1 _index: { newIndex: number oldIndex: number } } export interface ScrollParams {} export interface ScrollEventParams extends ListEventParams, ScrollParams {} export interface MenuClickEventParams extends ListEventParams { row: D menu: VxeContextMenuDefines.MenuFirstOption | VxeContextMenuDefines.MenuChildOption } } export type VxeListEventProps = { onRowClick?: VxeListEvents.RowClick onRowDblclick?: VxeListEvents.RowDblclick onScroll?: VxeListEvents.Scroll onRowDragstart?: VxeListEvents.RowDragstart onRowDragover?: VxeListEvents.RowDragover onRowDragend?: VxeListEvents.RowDragend onMenuClick?: VxeListEvents.MenuClick } export interface VxeListListeners { rowClick?: VxeListEvents.RowClick rowDblclick?: VxeListEvents.RowDblclick scroll?: VxeListEvents.Scroll rowDragstart?: VxeListEvents.RowDragstart rowDragover?: VxeListEvents.RowDragover rowDragend?: VxeListEvents.RowDragend menuClick?: VxeListEvents.MenuClick } export namespace VxeListEvents { export type RowClick = (params: VxeListDefines.RowClickEventParams) => void export type RowDblclick = (params: VxeListDefines.RowDblclickEventParams) => void export type Scroll = (params: VxeListDefines.ScrollEventParams) => void export type RowDragstart = (params: VxeListDefines.RowDragstartEventParams) => void export type RowDragover = (params: VxeListDefines.RowDragoverEventParams) => void export type RowDragend = (params: VxeListDefines.RowDragendEventParams) => void export type MenuClick = (params: VxeListDefines.MenuClickEventParams) => void } export namespace VxeListSlotTypes { export interface DefaultSlotParams { $list: VxeListConstructor items: any[] } export interface HeaderSlotParams extends DefaultSlotParams {} export interface FooterSlotParams extends DefaultSlotParams {} export interface ContentSlotParams { row: D } export interface ExtraSlotParams extends ContentSlotParams {} export interface DragSlotParams { row: D } } export interface VxeListSlots { default?: (params: VxeListSlotTypes.DefaultSlotParams) => any header?: (params: VxeListSlotTypes.HeaderSlotParams) => any footer?: (params: VxeListSlotTypes.FooterSlotParams) => any content?: (params: VxeListSlotTypes.ContentSlotParams) => any extra?: (params: VxeListSlotTypes.ExtraSlotParams) => any tip?: (params: VxeListSlotTypes.DragSlotParams) => any } export const List: typeof VxeList export default VxeList