yanzhen-design-vue
Version:
101 lines (100 loc) • 2.79 kB
JavaScript
import { useSlots, toRefs, unref, computed, readonly } from "vue";
import { useVxeTableMethods } from "./hooks/use-vxe-table-methods.mjs";
import { useVxeTableObserver } from "./hooks/use-vxe-table-observer.mjs";
import { provideVxeTableConfig } from "./hooks/use-vxe-table-config.mjs";
import { handleVxeTableProps } from "./utils/handleTableProps.mjs";
function useVxeTable(props, emit) {
const $slots = useSlots();
const { tag, ...config } = toRefs(props);
const {
tableRef,
expose: tableExpose,
elTableProps,
aTableProps,
vxeTableProps,
columnSlotRecordRef,
hiddenCellClassName,
virtualRef,
loading,
dataSource,
isElTableTag,
isATableTag,
...otherMethods
} = useVxeTableMethods(props);
const { onTableScroll, tableWrapper } = useVxeTableObserver(tableRef, {
scroll: {
debounce: 300
},
onResizeBodyColRecord(record) {
unref(columnSlotRecordRef).cellNodeRect.updateNodeRect(record);
unref(virtualRef).virtualNodeRect.updateNodeRect(record);
},
onResizeBodyRowRecord(record) {
unref(columnSlotRecordRef).cellNodeRect.updateRowNodeRect(record);
},
onTableResizeObserver(tableWrapper2) {
unref(virtualRef).onVirtualScroll(unref(tableWrapper2), false);
unref(columnSlotRecordRef).cellNodeRect.updateRowsNodeRect(
unref(tableWrapper2).tbody
);
},
onScroll(tableWrapper2) {
unref(virtualRef).onVirtualScroll(unref(tableWrapper2), false);
unref(columnSlotRecordRef).cellNodeRect.updateRowsNodeRect(
unref(tableWrapper2).tbody
);
}
});
const tableProps = computed(() => {
switch (true) {
case unref(isATableTag):
return unref(aTableProps);
case unref(isElTableTag):
return unref(elTableProps);
default:
return handleVxeTableProps(
unref(vxeTableProps),
unref(tableExpose),
{
rowClassName: ({ isEdit }) => {
return isEdit ? "is-row-edit" : "row-1212121";
},
cellClassName: unref(virtualRef).virtualCellClassName,
rowStyle: unref(columnSlotRecordRef).cellNodeRect.tableCellStyle
},
{
cellClassName: hiddenCellClassName
}
);
}
});
provideVxeTableConfig({
config: readonly({ ...config, data: dataSource }),
data: dataSource,
tag,
table: tableExpose
});
const ctx = {
...otherMethods,
tableWrapperRef: tableWrapper,
tableRef,
tableExpose,
loading,
dataSource,
$slots,
tableProps,
isElTableTag,
isATableTag
};
const methods = {
...otherMethods,
handleTableScroll: onTableScroll
};
return {
ctx,
methods
};
}
export {
useVxeTable
};