Skip to content

Commit 5bc2435

Browse files
author
jry
committed
feat: 新增element-plus风格的table2组件
1 parent cfe08bf commit 5bc2435

File tree

4 files changed

+599
-0
lines changed

4 files changed

+599
-0
lines changed

src/pages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@
355355
"style" : {
356356
"navigationBarTitleText" : "表格"
357357
}
358+
},
359+
{
360+
"path" : "table2/table2",
361+
"style" : {
362+
"navigationBarTitleText" : "表格2"
363+
}
358364
}
359365
]
360366
},
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<template>
2+
<view class="u-page">
3+
<view class="u-demo-block">
4+
<view class="u-demo-block__title">基础表格(斑马纹 + 边框)</view>
5+
<view class="u-demo-block__content">
6+
<u-table2
7+
:data="tableData"
8+
:columns="columns"
9+
stripe
10+
border
11+
@row-click="handleRowClick"
12+
/>
13+
</view>
14+
</view>
15+
<view class="u-demo-block">
16+
<view class="u-demo-block__title">支持单选的表格</view>
17+
<view class="u-demo-block__content">
18+
<u-table2
19+
:data="tableData"
20+
:columns="columns"
21+
highlight-current-row
22+
:current-row-key="currentRowId"
23+
@row-click="handleRowClick"
24+
/>
25+
</view>
26+
</view>
27+
<view class="u-demo-block">
28+
<view class="u-demo-block__title">支持复选框的表格</view>
29+
<view class="u-demo-block__content">
30+
<u-table2
31+
:data="tableData"
32+
:columns="columnsCheck"
33+
row-key="id"
34+
@selection-change="handleSelectionChange"
35+
/>
36+
</view>
37+
</view>
38+
<view class="u-demo-block">
39+
<view class="u-demo-block__title">支持排序与筛选</view>
40+
<view class="u-demo-block__content">
41+
<u-table2
42+
:data="tableData"
43+
:columns="columns2"
44+
:sortable="true"
45+
:multiSort="true"
46+
:filters="filters"
47+
@sort-change="onSortChange"
48+
@filter-change="onFilterChange"
49+
/>
50+
</view>
51+
</view>
52+
<view class="u-demo-block">
53+
<view class="u-demo-block__title">树形结构 + 固定列</view>
54+
<view class="u-demo-block__content">
55+
<u-table2
56+
:data="tableData3"
57+
:columns="columns3"
58+
:tree-props="{ children: 'children' }"
59+
:expand-row-keys="['1']"
60+
@expand-change="onExpandChange"
61+
/>
62+
</view>
63+
</view>
64+
</view>
65+
</template>
66+
67+
<script>
68+
export default {
69+
data() {
70+
return {
71+
currentRowId: '',
72+
tableData: [
73+
{ id: 1, name: '张三', age: 25 },
74+
{ id: 2, name: '李四', age: 30 }
75+
],
76+
columns: [
77+
{ title: '姓名', key: 'name' },
78+
{ title: '年龄', key: 'age' }
79+
],
80+
columnsCheck: [
81+
// 复选框列
82+
{ type: 'selection', width: '50px'},
83+
// 普通列
84+
{ title: '姓名', key: 'name' },
85+
{ title: '年龄', key: 'age' }
86+
],
87+
columns2: [
88+
{ title: '姓名', key: 'name', sortable: true },
89+
{ title: '年龄', key: 'age', sortable: true }
90+
],
91+
filters: { name: '张' },
92+
tableData3: [
93+
{
94+
id: 1,
95+
name: '部门A',
96+
age: 25,
97+
children: [
98+
{ id: 2, name: '员工1', age: 22 },
99+
{ id: 3, name: '员工2', age: 24 }
100+
]
101+
},
102+
{ id: 4, name: '部门B', age: 30 }
103+
],
104+
columns3: [
105+
{ title: '', type: 'expand', width: '50px' },
106+
{ title: '名称', key: 'name', fixed: 'left' },
107+
{ title: '年龄', key: 'age' }
108+
]
109+
}
110+
},
111+
methods: {
112+
handleRowClick(row) {
113+
this.currentRowId = row.id;
114+
console.log('点击了行:', row);
115+
},
116+
handleSelectionChange(selection) {
117+
console.log('当前选中的行:', JSON.stringify(selection));
118+
},
119+
onSortChange(conditions) {
120+
console.log('排序条件:', conditions);
121+
},
122+
onFilterChange(filters) {
123+
console.log('筛选条件:', filters);
124+
},
125+
onExpandChange(keys) {
126+
console.log('展开行 keys:', keys);
127+
}
128+
}
129+
}
130+
</script>
131+
132+
<style lang="scss" scoped>
133+
.wrap {
134+
padding: 24rpx;
135+
}
136+
</style>

src/pages/example/components.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ export default [{
172172
title: 'Table 表格',
173173
title_en: 'Table',
174174
},
175+
{
176+
path: '/pages/componentsB/table2/table2',
177+
icon: 'table',
178+
title: 'Table2 表格2',
179+
title_en: 'Table2',
180+
},
175181
{
176182
path: '/pages/componentsB/countDown/countDown',
177183
icon: 'countDown',

0 commit comments

Comments
 (0)