Skip to content

Commit

Permalink
chore(perf): perf the format
Browse files Browse the repository at this point in the history
  • Loading branch information
electroluxcode committed Mar 22, 2024
1 parent 68a212d commit 3bacb9e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions components/vc-table/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default defineComponent<CellProps>({
'transformCellText',
] as any,
setup(props, { slots }) {

const hoverRef = ref(null)
const contextSlots = useInjectSlots();
const { onHover, startRow, endRow } = useInjectHover();
Expand All @@ -122,6 +121,10 @@ export default defineComponent<CellProps>({
(props.additionalProps?.rowspan as number)
);
});
const hovering = eagerComputed(() => {
const { index } = props;
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
});
const supportSticky = useInjectSticky();

// ====================== Hover =======================
Expand Down Expand Up @@ -201,6 +204,7 @@ export default defineComponent<CellProps>({
renderIndex,
column: column.__originColumn__,
});

if (isRenderCell(renderData)) {
if (process.env.NODE_ENV !== 'production') {
warning(
Expand All @@ -214,6 +218,7 @@ export default defineComponent<CellProps>({
childNode = renderData;
}
}

if (
!(INTERNAL_COL_DEFINE in column) &&
cellType === 'body' &&
Expand Down Expand Up @@ -274,7 +279,6 @@ export default defineComponent<CellProps>({
} = cellProps || {};
const mergedColSpan = (cellColSpan !== undefined ? cellColSpan : colSpan.value) ?? 1;
const mergedRowSpan = (cellRowSpan !== undefined ? cellRowSpan : rowSpan.value) ?? 1;

if (mergedColSpan === 0 || mergedRowSpan === 0) {
return null;
}
Expand All @@ -299,6 +303,7 @@ export default defineComponent<CellProps>({
if (align) {
alignStyle.textAlign = align;
}

// ====================== Render ======================
let title: string;
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
Expand All @@ -311,10 +316,6 @@ export default defineComponent<CellProps>({
}

// AddEventListener Hover
const hovering = eagerComputed(() => {
const { index } = props;
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
});
watch([rowSpan,startRow,endRow],()=>{
hoverRef.value?.setAttribute("class",classNames(
cellPrefixCls,
Expand All @@ -338,7 +339,7 @@ export default defineComponent<CellProps>({
[`${cellPrefixCls}-fix-sticky`]:
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
}

const componentProps = {
title,
...restCellProps,
Expand All @@ -357,6 +358,7 @@ export default defineComponent<CellProps>({
onMouseleave,
style: [additionalProps.style, alignStyle, fixedStyle, cellStyle],
};

return (
<Component {...componentProps} ref={hoverRef}>
{appendNode}
Expand Down

0 comments on commit 3bacb9e

Please sign in to comment.