From 51d06c4e3bb4521df5e0c4013bfb87542ad397f1 Mon Sep 17 00:00:00 2001 From: Jevin Date: Thu, 3 Jul 2025 11:10:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(table):=20=E5=93=8D=E5=BA=94=E5=BC=8Fcolumn?= =?UTF-8?q?s=E5=8F=98=E9=87=8F=20fixed=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/table/__tests__/table.test.tsx | 4 ++-- .../component/table/hooks/useTable.ts | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/component/component/table/__tests__/table.test.tsx b/packages/component/component/table/__tests__/table.test.tsx index bb9501c7..d52917be 100644 --- a/packages/component/component/table/__tests__/table.test.tsx +++ b/packages/component/component/table/__tests__/table.test.tsx @@ -916,10 +916,10 @@ describe("LayTable", () => { }); test("一级表头存在两个fixed为left表头,存在 layui-table-fixed-left-last 类名", async () => { - const columns = [ + const columns = reactive([ { title: "用户", width: "80px", key: "name", fixed: "left" as const }, { title: "城市", width: "80px", key: "city", fixed: "left" as const }, - ]; + ]); const dataSource = ref([]); diff --git a/packages/component/component/table/hooks/useTable.ts b/packages/component/component/table/hooks/useTable.ts index ea17acfd..54087d33 100644 --- a/packages/component/component/table/hooks/useTable.ts +++ b/packages/component/component/table/hooks/useTable.ts @@ -8,10 +8,8 @@ import type { import { isEqual, isValueArray, loopForEach } from "@layui/component/utils"; import { - isReactive, reactive, ref, - toRaw, watch, watchEffect, } from "vue"; @@ -77,7 +75,7 @@ export function useTable(props: RequiredTableProps, emit: TableEmit) { watch( () => props.columns, (newValue) => { - _columns.value = isReactive(newValue) ? newValue : reactive(newValue); + _columns.value = newValue; }, { immediate: true, @@ -270,14 +268,14 @@ export function useTable(props: RequiredTableProps, emit: TableEmit) { ) { const [topColumn] = mapValueColumns; - const _columns = isLeft ? props.columns : [...props.columns].reverse(); + const columnsValue = isLeft ? _columns.value : [..._columns.value].reverse(); let index - = _columns.findIndex(column => isEqual(column, toRaw(topColumn))) - 1; + = columnsValue.findIndex(column => isEqual(column, topColumn)) - 1; const fixedColumns = []; while (index > -1) { - const column = _columns[index]; + const column = columnsValue[index]; if (column.fixed && column.fixed === (isLeft ? "left" : "right")) { fixedColumns.push(column); } @@ -309,19 +307,20 @@ export function useTable(props: RequiredTableProps, emit: TableEmit) { let lastLeftClassName = ""; let firstRightClassName = ""; - const topLastLeft = (props.columns as any).findLast( + const topLastLeft = (_columns.value as any).findLast( (column: T) => column.fixed === "left", ); - const topFirstRight = props.columns.find( + + const topFirstRight = _columns.value.find( column => column.fixed === "right", ); - if (isEqual(toRaw(topColumn), topLastLeft)) { + if (isEqual(topColumn, topLastLeft)) { loopJudge(topColumn, "left") && (lastLeftClassName = lastLeftClassNameConstant); } - if (isEqual(toRaw(topColumn), topFirstRight)) { + if (isEqual(topColumn, topFirstRight)) { loopJudge(topColumn, "right") && (firstRightClassName = firstRightClassNameConstant); } -- Gitee