From ffe1fe9f6b1c61cb29454bfdf04df85e4be922b1 Mon Sep 17 00:00:00 2001 From: wangchen Date: Thu, 11 Jan 2024 15:42:53 +0800 Subject: [PATCH] fix(table): fix span problem --- .../components/table/hooks/use-span.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/web-vue/components/table/hooks/use-span.ts b/packages/web-vue/components/table/hooks/use-span.ts index 10da6bffd..fa6f1410c 100644 --- a/packages/web-vue/components/table/hooks/use-span.ts +++ b/packages/web-vue/components/table/hooks/use-span.ts @@ -42,17 +42,19 @@ export const useSpan = ({ if (rowspan > 1 || colspan > 1) { span[`${rowIndex}-${columnIndex}-${record.key}`] = [rowspan, colspan]; Array.from({ length: rowspan }).forEach((_, r) => { - const key = tableData?.[rowIndex + r].key; - Array.from({ length: colspan }).forEach((_, c) => { - if ( - `${rowIndex}-${columnIndex}-${record.key}` !== - `${rowIndex + r}-${columnIndex + c}-${key}` - ) { - spanzero.value[`${rowIndex + r}-${columnIndex + c}-${key}`] = [ - 0, 0, - ]; - } - }); + if (rowIndex + r < tableData.length) { + const { key } = tableData[rowIndex + r] ?? {}; + Array.from({ length: colspan }).forEach((_, c) => { + if ( + columnIndex + c < columns.value.length && + `${rowIndex}-${columnIndex}-${record.key}` !== + `${rowIndex + r}-${columnIndex + c}-${key}` + ) { + spanzero.value[`${rowIndex + r}-${columnIndex + c}-${key}`] = + [0, 0]; + } + }); + } }); } });