Skip to content

Commit 8d95f44

Browse files
committed
!445 fix(table): 初始化赋值expandKeys错误
* fix(table): 初始化赋值expandKeys错误
1 parent a6fa2d7 commit 8d95f44

File tree

3 files changed

+77
-35
lines changed

3 files changed

+77
-35
lines changed

packages/component/component/table/__tests__/table.test.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { mount } from "@vue/test-utils";
2+
import LayTable from "../index.vue";
3+
4+
import { describe, expect, test, vi } from "vitest";
5+
import { nextTick, ref } from "vue";
6+
7+
describe("LayTable", () => {
8+
test("点击不可排序表头 是否报错", async () => {
9+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
10+
11+
const wrapper = mount(LayTable, {
12+
props: {
13+
columns: [
14+
{ title: "姓名", width: "80px", key: "name", sort: "desc" },
15+
{ title: "状态", width: "180px", key: "status" },
16+
],
17+
dataSource: [],
18+
},
19+
});
20+
await nextTick();
21+
22+
const thDom = wrapper.findAll(
23+
".layui-table-header .layui-table-header-wrapper th"
24+
);
25+
26+
await thDom[1].trigger("click");
27+
28+
expect(errorSpy).not.toHaveBeenCalled();
29+
30+
errorSpy.mockRestore();
31+
});
32+
33+
test("初始化expand-keys 未生效", async () => {
34+
const expandKeys = ref(["1", "1-1"]);
35+
const columns = [
36+
{ title: "姓名", width: "80px", key: "name", sort: "desc" },
37+
{ title: "状态", width: "180px", key: "status" },
38+
];
39+
const dataSource = [
40+
{
41+
id: "1",
42+
name: "张三",
43+
children: [
44+
{
45+
id: "1-1",
46+
name: "张三",
47+
children: [
48+
{
49+
id: "1-1-1",
50+
name: "张三",
51+
children: [],
52+
},
53+
],
54+
},
55+
],
56+
},
57+
{ id: "2", name: "张三" },
58+
];
59+
const wrapper = mount({
60+
setup() {
61+
return () => (
62+
<LayTable
63+
columns={columns}
64+
dataSource={dataSource}
65+
v-model:expandKeys={expandKeys.value}
66+
></LayTable>
67+
);
68+
},
69+
});
70+
await nextTick();
71+
72+
const trs = wrapper.findAll(".layui-table-body table tbody tr");
73+
74+
expect(trs.length).toBe(4);
75+
expect(expandKeys.value).toEqual(["1", "1-1"]);
76+
});
77+
});

packages/component/component/table/index.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const { rowClick, rowDoubleClick, rowContextmenu, cellDoubleClick, rowExpand } =
6868
useEmit(emit);
6969
const { t } = useI18n();
7070
const slot = useSlots();
71-
const slots = slot.default && slot.default();
7271
const tableRef = ref();
7372
7473
const s = "";
@@ -315,8 +314,6 @@ watch(
315314
const ids: string[] = [];
316315
lookForAllId(props.dataSource, ids);
317316
tableExpandKeys.value = ids;
318-
} else {
319-
tableExpandKeys.value = [];
320317
}
321318
},
322319
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy