MergeTableDemo.vue
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
<div class="p-4">
<!--引用表格-->
<BasicTable @register="registerTable">
<!--操作栏-->
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" />
</template>
</BasicTable>
</div>
</template>
<script lang="ts" name="basic-table-demo" setup>
import { ActionItem, BasicColumn, BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
//定义表格列
const columns: BasicColumn[] = [
{
title: '名称',
dataIndex: 'name',
customCell: (record, index, column) => ({
colSpan: index < 4 ? 1 : 5,
}),
customRender: ({ text, record, index, column }) => {
return index < 4 ? text : `${record.name}/${record.age}/${record.address}/${record.phone}`;
},
},
{
title: '年龄',
dataIndex: 'age',
customCell: (record, index, column) => {
if (index == 4) {
return { colSpan: 0 };
}
},
},
{
title: '家庭住址',
dataIndex: 'address',
customCell: (record, index, column) => {
if (index == 4) {
return { colSpan: 0 };
}
},
},
{
title: '联系电话',
colSpan: 2,
dataIndex: 'tel',
customCell: (record, index, column) => {
if (index === 2) {
return { rowSpan: 2 };
}
if (index === 3) {
return { rowSpan: 0 };
}
if (index === 4) {
return { colSpan: 0 };
}
},
},
{
title: 'Phone',
colSpan: 0,
dataIndex: 'phone',
customCell: (record, index, column) => {
if (index === 4) {
return { colSpan: 0 };
}
},
},
];
// 列表页面公共参数、方法
const { tableContext } = useListPage({
designScope: 'basic-table-demo',
tableProps: {
title: '合并行列',
dataSource: [
{
key: '1',
name: '尹嘉乐',
age: 32,
tel: '0319-5972018',
phone: 17600080009,
address: '北京市昌平区',
},
{
key: '2',
name: '龙佳钰',
tel: '0319-5972018',
phone: 17600060007,
age: 42,
address: '北京市海淀区',
},
{
key: '3',
name: '贺泽惠',
age: 32,
tel: '0319-5972018',
phone: 17600040005,
address: '北京市门头沟区',
},
{
key: '4',
name: '沈勇',
age: 18,
tel: '0319-5972018',
phone: 17600010003,
address: '北京市朝阳区',
},
{
key: '5',
name: '白佳毅',
age: 18,
tel: '0319-5972018',
phone: 17600010002,
address: '北京市丰台区',
},
],
columns: columns,
showActionColumn: false,
useSearchForm: false,
},
});
//注册table数据
const [registerTable] = tableContext;
/**
* 操作栏
*/
function getTableAction(record): ActionItem[] {
return [
{
label: '编辑',
onClick: handleEdit.bind(null, record),
},
];
}
function handleEdit(record) {
console.log(record);
}
</script>
<style scoped></style>