@ebiz/designer-components 0.0.19-beta.6 → 0.0.19-beta.8

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.
@@ -31,7 +31,7 @@ export default {
31
31
  </script>
32
32
 
33
33
  <script setup>
34
- import { defineProps, defineEmits } from 'vue';
34
+ import { defineProps, defineEmits, ref, defineExpose } from 'vue';
35
35
  import { Form as TForm } from 'tdesign-vue-next';
36
36
 
37
37
  defineProps({
package/src/index.js CHANGED
@@ -56,6 +56,7 @@ import EbizTree from './components/EbizTree.vue';
56
56
  import EbizTreeSelector from './components/EbizTreeSelector.vue';
57
57
  import EbizTimePicker from './components/EbizTimePicker.vue';
58
58
  import EbizPopconfirm from './components/EbizPopconfirm.vue';
59
+ import EbizTreeMergeTable from './components/EbizTreeMergeTable.vue';
59
60
  import { MessagePlugin as EbizMessage } from 'tdesign-vue-next';
60
61
 
61
62
  import { Descriptions as EbizDescriptions, DescriptionsItem as EbizDescriptionsItem } from 'tdesign-vue-next';
@@ -171,6 +172,8 @@ export {
171
172
  EbizTimePicker,
172
173
  // 气泡确认框组件
173
174
  EbizPopconfirm,
175
+ // 树形合并表格组件
176
+ EbizTreeMergeTable,
174
177
  // 新增 EbizDescriptions 和 EbizDescriptionsItem
175
178
  EbizDescriptions,
176
179
  EbizDescriptionsItem
@@ -298,6 +298,12 @@ const routes = [
298
298
  name: 'Popconfirm',
299
299
  component: () => import('../views/PopconfirmDemo.vue'),
300
300
  meta: { title: 'Ebiz气泡确认框组件示例' }
301
+ },
302
+ {
303
+ path: '/tree-merge-table-demo',
304
+ name: 'TreeMergeTableDemo',
305
+ component: () => import('../views/TreeMergeTableDemo.vue'),
306
+ meta: { title: '树形合并表格组件示例' }
301
307
  }
302
308
  ]
303
309
 
@@ -17,6 +17,11 @@
17
17
  <div class="component-title">树形选择器</div>
18
18
  <div class="component-desc">基于树组件的选择器,支持搜索和多选</div>
19
19
  </router-link>
20
+
21
+ <router-link to="/tree-merge-table-demo" class="component-item">
22
+ <div class="component-title">树形合并表格</div>
23
+ <div class="component-desc">支持树形展示和单元格合并的表格组件</div>
24
+ </router-link>
20
25
  </div>
21
26
  </div>
22
27
  </template>
@@ -71,7 +76,8 @@ export default {
71
76
  { path: '/table-sort', title: 'Ebiz表格排序组件示例' },
72
77
  { path: '/time-picker', title: 'Ebiz时间选择器组件示例' },
73
78
  { path: '/tdesign-descriptions', title: 'Ebiz描述列表组件示例' },
74
- { path: '/popconfirm', title: 'Ebiz气泡确认框组件示例' }
79
+ { path: '/popconfirm', title: 'Ebiz气泡确认框组件示例' },
80
+ { path: '/tree-merge-table-demo', title: '树形合并表格组件示例' }
75
81
  ]
76
82
 
77
83
  return {
@@ -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>