From f262c3d53125e4dff8bd8f32aa712a9654522131 Mon Sep 17 00:00:00 2001
From: wanchun <445436867@qq.com>
Date: Fri, 1 Apr 2022 18:08:43 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=89=8B=E5=8A=A8=E5=B1=95?=
=?UTF-8?q?=E5=BC=80=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/table/components/expandTr.tsx | 2 +-
components/table/style/index.less | 6 +++++
components/table/table.tsx | 4 +++-
components/table/useTableExpand.ts | 11 +++++++--
docs/.vitepress/components/table/expand.vue | 25 +++++++++++++++++++--
docs/.vitepress/components/table/index.md | 3 ++-
pnpm-lock.yaml | 6 -----
7 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/components/table/components/expandTr.tsx b/components/table/components/expandTr.tsx
index 02868f95..1939bcd8 100644
--- a/components/table/components/expandTr.tsx
+++ b/components/table/components/expandTr.tsx
@@ -26,7 +26,7 @@ export default defineComponent({
{column.slots.default({
row,
diff --git a/components/table/style/index.less b/components/table/style/index.less
index 5fc3f834..ad9078ba 100644
--- a/components/table/style/index.less
+++ b/components/table/style/index.less
@@ -161,11 +161,17 @@
&.is-size-normal {
.@{table-prefix}-cell {
padding: @padding-md;
+ &.@{table-prefix}-expanded-cell {
+ padding: 0;
+ }
}
}
&.is-size-small {
.@{table-prefix}-cell {
padding: @padding-xs;
+ &.@{table-prefix}-expanded-cell {
+ padding: 0;
+ }
}
}
.@{table-prefix}-expand-icon {
diff --git a/components/table/table.tsx b/components/table/table.tsx
index 89cb8a4e..6a1e12b5 100644
--- a/components/table/table.tsx
+++ b/components/table/table.tsx
@@ -89,13 +89,15 @@ export default defineComponent({
layout,
columns,
rootProps,
+ toggleRowExpend,
} = useTable(props, ctx);
-
+
ctx.expose &&
ctx.expose({
toggleRowSelection: handleSelect,
toggleAllSelection: handleSelectAll,
clearSelection: clearSelect,
+ toggleRowExpend
});
// 计算出传入columns列的对应的宽度
diff --git a/components/table/useTableExpand.ts b/components/table/useTableExpand.ts
index ce54f2a9..bf34e35c 100644
--- a/components/table/useTableExpand.ts
+++ b/components/table/useTableExpand.ts
@@ -40,7 +40,7 @@ export default ({
return expandOpenedList.includes(rowKey);
};
- const handleExpand = ({ row }: { row: RowType }) => {
+ const toggleRowExpend = ({ row }: { row: RowType }) => {
const rowKey = getRowKey({ row });
const index = expandOpenedList.indexOf(rowKey);
if (index !== -1) {
@@ -48,11 +48,18 @@ export default ({
} else {
expandOpenedList.push(rowKey);
}
- ctx.emit('expandChange', { row, expanded: !index });
+ return index === -1;
};
+
+ const handleExpand = ({ row }: { row: RowType }) => {
+ const expanded = toggleRowExpend({ row });
+ ctx.emit('expandChange', { row, expanded });
+ };
+
return {
expandColumn,
isExpandOpened,
+ toggleRowExpend,
handleExpand,
};
};
diff --git a/docs/.vitepress/components/table/expand.vue b/docs/.vitepress/components/table/expand.vue
index a7d74985..5dfc6443 100644
--- a/docs/.vitepress/components/table/expand.vue
+++ b/docs/.vitepress/components/table/expand.vue
@@ -1,7 +1,16 @@
-
+
-
+
省份:{{ row.province }}
市区:{{ row.city }}
邮编:{{ row.zip }}
@@ -11,10 +20,13 @@
+ 手动展开/关闭第一行
|