@ebiz/designer-components 0.0.19-beta.7 → 0.0.19-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,240 @@
1
+ <template>
2
+ <div class="container">
3
+ <h1>树形合并单元格表格组件</h1>
4
+ <p>本组件基于TDesign表格组件,支持树形结构展示和单元格合并功能,通过单一的v-model绑定选中数据。</p>
5
+
6
+ <h2>基础树形表格</h2>
7
+ <div class="demo-block">
8
+ <EbizTreeMergeTable
9
+ :data="treeData"
10
+ :columns="basicColumns"
11
+ :bordered="true"
12
+ :tree="{ childrenKey: 'children', treeNodeColumnIndex: 0 }"
13
+ row-key="id"
14
+ />
15
+ </div>
16
+
17
+ <h2>可选择的树形表格</h2>
18
+ <div class="demo-block">
19
+ <EbizTreeMergeTable
20
+ v-model="selectedRows"
21
+ :data="treeData"
22
+ :columns="selectableColumns"
23
+ :bordered="true"
24
+ :tree="{ childrenKey: 'children', treeNodeColumnIndex: 1 }"
25
+ row-key="id"
26
+ @select-change="onSelectChange"
27
+ />
28
+ <div class="mt-2">
29
+ <p>已选择的行:{{ selectedRows.map(item => item.name).join(', ') || '无' }}</p>
30
+ </div>
31
+ </div>
32
+
33
+ <h2>单元格合并的树形表格</h2>
34
+ <div class="demo-block">
35
+ <EbizTreeMergeTable
36
+ :data="mergeTreeData"
37
+ :columns="mergeColumns"
38
+ :bordered="true"
39
+ :tree="{ childrenKey: 'children', treeNodeColumnIndex: 0 }"
40
+ :merge-cells="mergeCells"
41
+ row-key="id"
42
+ />
43
+ <div class="description">
44
+ <p>该示例展示了如何通过mergeCells属性实现单元格合并</p>
45
+ </div>
46
+ </div>
47
+
48
+ <h2>动态合并单元格的树形表格</h2>
49
+ <div class="demo-block">
50
+ <EbizTreeMergeTable
51
+ :data="mergeTreeData"
52
+ :columns="mergeColumns"
53
+ :bordered="true"
54
+ :tree="{ childrenKey: 'children', treeNodeColumnIndex: 0 }"
55
+ :merge-config="dynamicMergeConfig"
56
+ row-key="id"
57
+ />
58
+ <div class="description">
59
+ <p>该示例展示了如何通过mergeConfig函数动态计算单元格合并逻辑</p>
60
+ </div>
61
+ </div>
62
+ </div>
63
+ </template>
64
+
65
+ <script setup>
66
+ import { ref, reactive } from 'vue';
67
+ import { EbizTreeMergeTable } from '../index.js';
68
+
69
+ // 基础树形数据
70
+ const treeData = [
71
+ {
72
+ id: 1,
73
+ name: '北京总部',
74
+ age: '-',
75
+ address: '北京市海淀区',
76
+ children: [
77
+ { id: 11, name: '研发部', age: 20, address: '北京市海淀区' },
78
+ { id: 12, name: '销售部', age: 15, address: '北京市朝阳区' },
79
+ ]
80
+ },
81
+ {
82
+ id: 2,
83
+ name: '上海分部',
84
+ age: '-',
85
+ address: '上海市浦东新区',
86
+ children: [
87
+ { id: 21, name: '研发部', age: 12, address: '上海市浦东新区' },
88
+ { id: 22, name: '销售部', age: 8, address: '上海市静安区' },
89
+ ]
90
+ }
91
+ ];
92
+
93
+ // 合并单元格的树形数据
94
+ const mergeTreeData = [
95
+ {
96
+ id: 1,
97
+ name: '研发部',
98
+ manager: '张三',
99
+ project: 'A项目',
100
+ status: '进行中',
101
+ children: [
102
+ { id: 11, name: '研发部', manager: '张三', project: 'A项目子任务1', status: '进行中' },
103
+ { id: 12, name: '研发部', manager: '张三', project: 'A项目子任务2', status: '已完成' },
104
+ { id: 13, name: '研发部', manager: '张三', project: 'A项目子任务3', status: '进行中' },
105
+ ]
106
+ },
107
+ {
108
+ id: 2,
109
+ name: '销售部',
110
+ manager: '李四',
111
+ project: 'B项目',
112
+ status: '已完成',
113
+ children: [
114
+ { id: 21, name: '销售部', manager: '李四', project: 'B项目子任务1', status: '已完成' },
115
+ { id: 22, name: '销售部', manager: '李四', project: 'B项目子任务2', status: '已完成' },
116
+ ]
117
+ },
118
+ {
119
+ id: 3,
120
+ name: '市场部',
121
+ manager: '王五',
122
+ project: 'C项目',
123
+ status: '规划中',
124
+ children: [
125
+ { id: 31, name: '市场部', manager: '王五', project: 'C项目子任务1', status: '规划中' },
126
+ ]
127
+ }
128
+ ];
129
+
130
+ // 基础列配置
131
+ const basicColumns = [
132
+ { colKey: 'name', title: '名称', width: 150 },
133
+ { colKey: 'age', title: '年龄', width: 100 },
134
+ { colKey: 'address', title: '地址' },
135
+ ];
136
+
137
+ // 可选择列配置
138
+ const selectableColumns = [
139
+ { colKey: 'row-select', type: 'multiple', width: 50 },
140
+ { colKey: 'name', title: '名称', width: 150 },
141
+ { colKey: 'age', title: '年龄', width: 100 },
142
+ { colKey: 'address', title: '地址' },
143
+ ];
144
+
145
+ // 合并单元格列配置
146
+ const mergeColumns = [
147
+ { colKey: 'name', title: '部门', width: 150 },
148
+ { colKey: 'manager', title: '负责人', width: 120 },
149
+ { colKey: 'project', title: '项目', width: 200 },
150
+ { colKey: 'status', title: '状态', width: 100 },
151
+ ];
152
+
153
+ // 已选择的行
154
+ const selectedRows = ref([]);
155
+
156
+ // 选择变化处理
157
+ const onSelectChange = (selectedRowData) => {
158
+ console.log('选择变化', selectedRowData);
159
+ };
160
+
161
+ // 静态合并单元格配置
162
+ const mergeCells = [
163
+ { row: 0, col: 0, rowspan: 4, colspan: 1 }, // 第一个部门名称跨4行
164
+ { row: 0, col: 1, rowspan: 4, colspan: 1 }, // 第一个负责人跨4行
165
+ { row: 4, col: 0, rowspan: 3, colspan: 1 }, // 第二个部门名称跨3行
166
+ { row: 4, col: 1, rowspan: 3, colspan: 1 }, // 第二个负责人跨3行
167
+ { row: 7, col: 0, rowspan: 2, colspan: 1 }, // 第三个部门名称跨2行
168
+ { row: 7, col: 1, rowspan: 2, colspan: 1 }, // 第三个负责人跨2行
169
+ ];
170
+
171
+ // 动态合并单元格配置函数
172
+ const dynamicMergeConfig = (data) => {
173
+ const mergeCells = [];
174
+ let rowIndex = 0;
175
+
176
+ // 为每个部门生成合并单元格配置
177
+ data.forEach(dept => {
178
+ const rowCount = getRowCount(dept);
179
+
180
+ // 如果有子节点,合并部门名称和负责人列
181
+ if (rowCount > 1) {
182
+ mergeCells.push({ row: rowIndex, col: 0, rowspan: rowCount, colspan: 1 }); // 部门名称
183
+ mergeCells.push({ row: rowIndex, col: 1, rowspan: rowCount, colspan: 1 }); // 负责人
184
+ }
185
+
186
+ rowIndex += rowCount;
187
+ });
188
+
189
+ return mergeCells;
190
+ };
191
+
192
+ // 计算一个节点及其子节点的总行数
193
+ const getRowCount = (node) => {
194
+ if (!node.children || node.children.length === 0) {
195
+ return 1;
196
+ }
197
+
198
+ return 1 + node.children.reduce((sum, child) => sum + getRowCount(child), 0);
199
+ };
200
+ </script>
201
+
202
+ <style scoped>
203
+ .container {
204
+ padding: 20px;
205
+ max-width: 1200px;
206
+ margin: 0 auto;
207
+ }
208
+
209
+ .demo-block {
210
+ margin-bottom: 24px;
211
+ border: 1px solid #e9e9e9;
212
+ border-radius: 2px;
213
+ padding: 24px;
214
+ background-color: #fafafa;
215
+ }
216
+
217
+ h1 {
218
+ font-size: 28px;
219
+ margin-bottom: 16px;
220
+ }
221
+
222
+ h2 {
223
+ font-size: 20px;
224
+ margin: 24px 0 16px;
225
+ }
226
+
227
+ h3 {
228
+ font-size: 18px;
229
+ margin: 24px 0 16px;
230
+ }
231
+
232
+ .description {
233
+ margin-top: 16px;
234
+ color: #666;
235
+ }
236
+
237
+ .mt-2 {
238
+ margin-top: 16px;
239
+ }
240
+ </style>