Skip to content

Commit 68a212d

Browse files
chore(perf): perf the format and style
1 parent e675d00 commit 68a212d

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

components/vc-table/Cell/index.tsx

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import classNames from '../../_util/classNames';
22
import { filterEmpty, flattenChildren, isValidElement } from '../../_util/props-util';
33
import type { CSSProperties, VNodeArrayChildren } from 'vue';
44
import { Text, computed, defineComponent, isVNode, ref, watch } from 'vue';
5+
import eagerComputed from '../../_util/eagerComputed';
56
import type {
67
DataIndex,
78
ColumnType,
@@ -103,7 +104,7 @@ export default defineComponent<CellProps>({
103104
'transformCellText',
104105
] as any,
105106
setup(props, { slots }) {
106-
107+
107108
const hoverRef = ref(null)
108109
const contextSlots = useInjectSlots();
109110
const { onHover, startRow, endRow } = useInjectHover();
@@ -121,14 +122,6 @@ export default defineComponent<CellProps>({
121122
(props.additionalProps?.rowspan as number)
122123
);
123124
});
124-
watch([rowSpan,startRow,endRow],()=>{
125-
const { index } = props;
126-
if(inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value)){
127-
hoverRef.value?.setAttribute("class",`ant-table-cell ${props.prefixCls}-cell-row-hover`)
128-
}else{
129-
hoverRef.value?.setAttribute("class",`ant-table-cell`)
130-
}
131-
})
132125
const supportSticky = useInjectSticky();
133126

134127
// ====================== Hover =======================
@@ -190,6 +183,7 @@ export default defineComponent<CellProps>({
190183
// ==================== Child Node ====================
191184
let cellProps: CellType;
192185
let childNode;
186+
let componentPropsCommonClassName
193187
const children = slots.default?.();
194188
if (validateValue(children) || cellType === 'header') {
195189
childNode = children;
@@ -207,7 +201,6 @@ export default defineComponent<CellProps>({
207201
renderIndex,
208202
column: column.__originColumn__,
209203
});
210-
211204
if (isRenderCell(renderData)) {
212205
if (process.env.NODE_ENV !== 'production') {
213206
warning(
@@ -221,7 +214,6 @@ export default defineComponent<CellProps>({
221214
childNode = renderData;
222215
}
223216
}
224-
225217
if (
226218
!(INTERNAL_COL_DEFINE in column) &&
227219
cellType === 'body' &&
@@ -282,7 +274,7 @@ export default defineComponent<CellProps>({
282274
} = cellProps || {};
283275
const mergedColSpan = (cellColSpan !== undefined ? cellColSpan : colSpan.value) ?? 1;
284276
const mergedRowSpan = (cellRowSpan !== undefined ? cellRowSpan : rowSpan.value) ?? 1;
285-
277+
286278
if (mergedColSpan === 0 || mergedRowSpan === 0) {
287279
return null;
288280
}
@@ -317,6 +309,35 @@ export default defineComponent<CellProps>({
317309
title = getTitle([childNode]);
318310
}
319311
}
312+
313+
// AddEventListener Hover
314+
const hovering = eagerComputed(() => {
315+
const { index } = props;
316+
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
317+
});
318+
watch([rowSpan,startRow,endRow],()=>{
319+
hoverRef.value?.setAttribute("class",classNames(
320+
cellPrefixCls,
321+
{
322+
...componentPropsCommonClassName,
323+
[`${cellPrefixCls}-row-hover`]: !cellProps && hovering.value,
324+
},
325+
additionalProps.class,
326+
cellClassName,
327+
))
328+
})
329+
componentPropsCommonClassName = {
330+
[`${cellPrefixCls}-fix-left`]: isFixLeft && supportSticky.value,
331+
[`${cellPrefixCls}-fix-left-first`]: firstFixLeft && supportSticky.value,
332+
[`${cellPrefixCls}-fix-left-last`]: lastFixLeft && supportSticky.value,
333+
[`${cellPrefixCls}-fix-right`]: isFixRight && supportSticky.value,
334+
[`${cellPrefixCls}-fix-right-first`]: firstFixRight && supportSticky.value,
335+
[`${cellPrefixCls}-fix-right-last`]: lastFixRight && supportSticky.value,
336+
[`${cellPrefixCls}-ellipsis`]: ellipsis,
337+
[`${cellPrefixCls}-with-append`]: appendNode,
338+
[`${cellPrefixCls}-fix-sticky`]:
339+
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
340+
}
320341

321342
const componentProps = {
322343
title,
@@ -326,18 +347,7 @@ export default defineComponent<CellProps>({
326347
rowSpan: mergedRowSpan !== 1 ? mergedRowSpan : null,
327348
class: classNames(
328349
cellPrefixCls,
329-
{
330-
[`${cellPrefixCls}-fix-left`]: isFixLeft && supportSticky.value,
331-
[`${cellPrefixCls}-fix-left-first`]: firstFixLeft && supportSticky.value,
332-
[`${cellPrefixCls}-fix-left-last`]: lastFixLeft && supportSticky.value,
333-
[`${cellPrefixCls}-fix-right`]: isFixRight && supportSticky.value,
334-
[`${cellPrefixCls}-fix-right-first`]: firstFixRight && supportSticky.value,
335-
[`${cellPrefixCls}-fix-right-last`]: lastFixRight && supportSticky.value,
336-
[`${cellPrefixCls}-ellipsis`]: ellipsis,
337-
[`${cellPrefixCls}-with-append`]: appendNode,
338-
[`${cellPrefixCls}-fix-sticky`]:
339-
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
340-
},
350+
componentPropsCommonClassName,
341351
additionalProps.class,
342352
cellClassName,
343353
),
@@ -347,7 +357,6 @@ export default defineComponent<CellProps>({
347357
onMouseleave,
348358
style: [additionalProps.style, alignStyle, fixedStyle, cellStyle],
349359
};
350-
351360
return (
352361
<Component {...componentProps} ref={hoverRef}>
353362
{appendNode}

0 commit comments

Comments
 (0)