@agile-team/wl-skills-kit 2.11.1 → 2.11.2
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.
- package/CHANGELOG.md +13 -0
- package/README.md +1 -1
- package/bin/wl-skills.js +27 -3
- package/files/.wl-skills/docs/jh-pagination.md +505 -505
- package/files/.wl-skills/docs/request.md +940 -940
- package/files/.wl-skills/guides/architecture.md +1 -1
- package/files/.wl-skills/skills/core/convention-audit/SKILL.md +3 -3
- package/files/.wl-skills/skills/core/spec-doc-parse/SKILL.md +332 -332
- package/files/.wl-skills/skills/core/spec-doc-parse/USAGE.md +97 -97
- package/files/.wl-skills/skills/sync/permission-sync/USAGE.md +107 -107
- package/files/.wl-skills/src/components/global/C_ParentView/index.vue +3 -3
- package/files/.wl-skills/src/components/global/C_RightToolbar/index.vue +157 -157
- package/files/.wl-skills/src/components/global/C_SvgIcon/index.vue +31 -31
- package/files/.wl-skills/src/components/global/C_SvgIcon/svgicon.js +10 -10
- package/files/.wl-skills/src/components/global/C_TagStatus/README.md +264 -264
- package/files/.wl-skills/src/components/global/C_TagStatus/config.ts +192 -192
- package/files/.wl-skills/src/components/global/C_TagStatus/index.vue +106 -106
- package/files/.wl-skills/src/components/global/C_TagStatus/types.ts +64 -64
- package/files/.wl-skills/src/components/global/C_Tree/README.md +153 -153
- package/files/.wl-skills/src/components/global/C_Tree/index.scss +42 -42
- package/files/.wl-skills/src/components/global/C_Tree/index.vue +78 -78
- package/files/.wl-skills/src/components/global/C_Tree/types.ts +59 -59
- package/files/.wl-skills/src/components/local/c_formModal/README.md +235 -235
- package/files/.wl-skills/src/components/local/c_formModal/data.ts +95 -95
- package/files/.wl-skills/src/components/local/c_formModal/index.scss +8 -8
- package/files/.wl-skills/src/components/local/c_formModal/index.vue +107 -107
- package/files/.wl-skills/src/components/local/c_formSections/data.ts +175 -175
- package/files/.wl-skills/src/components/local/c_formSections/index.scss +280 -280
- package/files/.wl-skills/src/components/local/c_formSections/index.vue +429 -429
- package/files/.wl-skills/src/components/local/c_listModal/data.ts +41 -41
- package/files/.wl-skills/src/components/local/c_listModal/index.vue +136 -136
- package/files/.wl-skills/src/components/local/c_spliterTitle/index.scss +25 -25
- package/files/.wl-skills/src/components/local/c_spliterTitle/index.vue +21 -21
- package/files/.wl-skills/src/components/remote/AGGrid/README.md +530 -530
- package/files/.wl-skills/src/components/remote/BaseForm/README.md +508 -508
- package/files/.wl-skills/src/components/remote/BaseQuery/README.md +865 -865
- package/files/.wl-skills/src/components/remote/BaseTable/README.md +941 -941
- package/files/.wl-skills/src/components/remote/BaseToolbar/README.md +496 -496
- package/files/.wl-skills/src/types/page.ts +24 -24
- package/files/.wl-skills/standards/04-coding-basics.md +39 -1
- package/files/.wl-skills/standards/09-typescript.md +26 -3
- package/files/.wl-skills/standards/index.md +2 -2
- package/files/.wl-skills/templates/README.md +44 -44
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add/api.md +54 -54
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add/data.ts +346 -346
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add/index.scss +1 -1
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add/index.vue +28 -28
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add-form/data.ts +115 -115
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add-form/index.scss +44 -44
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-add-form/index.vue +43 -43
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change/data.ts +338 -338
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change/index.scss +1 -1
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change/index.vue +28 -28
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change-form/data.ts +115 -115
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change-form/index.scss +44 -44
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-apply-change-form/index.vue +43 -43
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-archive/api.md +88 -88
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-archive/data.ts +601 -601
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-archive/index.scss +1 -1
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-archive/index.vue +64 -64
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-detail/api.md +67 -67
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-detail/data.ts +286 -286
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-detail/index.scss +139 -139
- package/files/.wl-skills/templates/produce/aiflow/mmwr-customer-detail/index.vue +318 -318
- package/files/.wl-skills/templates/produce/aiflow/mmwr-temp-customer-archive/api.md +98 -98
- package/files/.wl-skills/templates/produce/aiflow/mmwr-temp-customer-archive/data.ts +543 -543
- package/files/.wl-skills/templates/produce/aiflow/mmwr-temp-customer-archive/index.scss +1 -1
- package/files/.wl-skills/templates/produce/aiflow/mmwr-temp-customer-archive/index.vue +52 -52
- package/files/.wl-skills/templates/sale/demo/add-demo/data.ts +518 -518
- package/files/.wl-skills/templates/sale/demo/billet-flame-cut-plan/data.ts +524 -524
- package/files/.wl-skills/templates/sale/demo/billet-flame-cut-plan/index.scss +154 -154
- package/files/.wl-skills/templates/sale/demo/billet-flame-cut-plan/index.vue +117 -117
- package/files/.wl-skills/templates/sale/demo/domestic-trade-order/data.ts +308 -308
- package/files/.wl-skills/templates/sale/demo/domestic-trade-order/index.scss +99 -99
- package/files/.wl-skills/templates/sale/demo/domestic-trade-order/index.vue +77 -77
- package/files/.wl-skills/templates/sale/demo/heat-batch-return/data.ts +367 -367
- package/files/.wl-skills/templates/sale/demo/heat-batch-return/index.scss +100 -100
- package/files/.wl-skills/templates/sale/demo/heat-batch-return/index.vue +170 -170
- package/files/.wl-skills/templates/sale/demo/heat-batch-return/meltDialog.vue +320 -320
- package/files/.wl-skills/templates/sale/demo/metallurgical-spec/data.ts +824 -824
- package/lib/ast-rules.js +304 -9
- package/mcp/config.js +46 -46
- package/mcp/registry.js +6 -1
- package/mcp/tools/projectTools.js +9 -1
- package/package.json +2 -2
|
@@ -1,530 +1,530 @@
|
|
|
1
|
-
# AGGrid 高性能表格
|
|
2
|
-
|
|
3
|
-
> 来源:`@jhlc/common-core` 远程组件
|
|
4
|
-
|
|
5
|
-
AGGrid 是 BaseTable 的高性能渲染模式,基于 AG Grid 企业级表格库实现。适用于大数据量场景,支持虚拟滚动、列固定、分组聚合等企业级特性。
|
|
6
|
-
|
|
7
|
-
## 📦 使用方式
|
|
8
|
-
|
|
9
|
-
AGGrid 不是独立组件,而是 BaseTable 的一种渲染模式,通过 `render-type="agGrid"` 启用:
|
|
10
|
-
|
|
11
|
-
```vue
|
|
12
|
-
<template>
|
|
13
|
-
<BaseTable
|
|
14
|
-
ref="tableRef"
|
|
15
|
-
render-type="agGrid"
|
|
16
|
-
:data="tableData"
|
|
17
|
-
:columns="columns"
|
|
18
|
-
:row-key="'id'"
|
|
19
|
-
/>
|
|
20
|
-
</template>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 💡 可以在同一页面并存使用 (但不推荐,最好默认使用一个)
|
|
24
|
-
|
|
25
|
-
**完全可以**在同一个页面中使用多个 BaseTable,并为每个表格指定不同的 `render-type`:
|
|
26
|
-
|
|
27
|
-
```vue
|
|
28
|
-
<template>
|
|
29
|
-
<div>
|
|
30
|
-
<!-- 表格1:大数据量,使用 agGrid -->
|
|
31
|
-
<BaseTable
|
|
32
|
-
:data="largeDataList"
|
|
33
|
-
:columns="columns1"
|
|
34
|
-
render-type="agGrid"
|
|
35
|
-
/>
|
|
36
|
-
|
|
37
|
-
<!-- 表格2:小数据量,使用默认 dataTable -->
|
|
38
|
-
<BaseTable
|
|
39
|
-
:data="smallDataList"
|
|
40
|
-
:columns="columns2"
|
|
41
|
-
render-type="dataTable"
|
|
42
|
-
/>
|
|
43
|
-
</div>
|
|
44
|
-
</template>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 🔄 一键切换渲染模式
|
|
48
|
-
|
|
49
|
-
```vue
|
|
50
|
-
<template>
|
|
51
|
-
<div>
|
|
52
|
-
<BaseToolbar :items="toolbarItems" />
|
|
53
|
-
<BaseTable
|
|
54
|
-
:data="tableData"
|
|
55
|
-
:columns="columns"
|
|
56
|
-
:render-type="renderType"
|
|
57
|
-
/>
|
|
58
|
-
</div>
|
|
59
|
-
</template>
|
|
60
|
-
|
|
61
|
-
<script setup lang="ts">
|
|
62
|
-
import { ref } from "vue";
|
|
63
|
-
|
|
64
|
-
// 响应式渲染类型
|
|
65
|
-
const renderType = ref<"dataTable" | "agGrid">("dataTable");
|
|
66
|
-
|
|
67
|
-
const toolbarItems = computed(() => [
|
|
68
|
-
{
|
|
69
|
-
name: "switch",
|
|
70
|
-
label: `切换到 ${renderType.value === "dataTable" ? "agGrid" : "dataTable"}`,
|
|
71
|
-
icon: "Switch",
|
|
72
|
-
onClick: () => {
|
|
73
|
-
renderType.value =
|
|
74
|
-
renderType.value === "dataTable" ? "agGrid" : "dataTable";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
]);
|
|
78
|
-
</script>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## 🆚 与 dataTable 模式对比
|
|
82
|
-
|
|
83
|
-
| 特性 | dataTable(默认) | agGrid |
|
|
84
|
-
| ------------ | -------------------- | -------------------- |
|
|
85
|
-
| 渲染性能 | 一般(全量渲染) | 高(虚拟滚动) |
|
|
86
|
-
| 数据量支持 | < 1000 条 | 10万+ 条 |
|
|
87
|
-
| 列固定 | ✅ | ✅ |
|
|
88
|
-
| 行内编辑 | ✅ | ✅(性能更优) |
|
|
89
|
-
| 分组聚合 | ❌ | ✅ |
|
|
90
|
-
| 列拖拽排序 | ❌ | ✅ |
|
|
91
|
-
| 列配置持久化 | ❌ | ✅ |
|
|
92
|
-
| 自定义渲染 | ✅ VNode | ✅ VNode |
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## 📋 renderType 属性
|
|
97
|
-
|
|
98
|
-
| 值 | 说明 |
|
|
99
|
-
| ----------- | -------------------------- |
|
|
100
|
-
| `""` | 使用全局配置(默认) |
|
|
101
|
-
| `dataTable` | 使用 Element Plus 表格渲染 |
|
|
102
|
-
| `agGrid` | 使用 AG Grid 渲染 |
|
|
103
|
-
|
|
104
|
-
### 🎯 三种配置方式
|
|
105
|
-
|
|
106
|
-
#### 方式1: 全局配置(所有未指定 render-type 的表格)
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
// 在环境配置文件中设置(如 vite/environment.ts 或 main.ts)
|
|
110
|
-
envConfig().componentConfig.table = {
|
|
111
|
-
renderType: "agGrid" // 或 "dataTable"
|
|
112
|
-
};
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
```vue
|
|
116
|
-
<!-- 使用全局配置 -->
|
|
117
|
-
<BaseTable :data="tableData" :columns="columns" />
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### 方式2: 单独指定(不受全局配置影响)
|
|
121
|
-
|
|
122
|
-
```vue
|
|
123
|
-
<!-- 明确指定,优先级最高 -->
|
|
124
|
-
<BaseTable
|
|
125
|
-
:data="tableData"
|
|
126
|
-
:columns="columns"
|
|
127
|
-
render-type="agGrid"
|
|
128
|
-
/>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
#### 方式3: 响应式切换(动态切换)
|
|
132
|
-
|
|
133
|
-
```vue
|
|
134
|
-
<template>
|
|
135
|
-
<div>
|
|
136
|
-
<el-radio-group v-model="renderType">
|
|
137
|
-
<el-radio-button label="dataTable">默认表格</el-radio-button>
|
|
138
|
-
<el-radio-button label="agGrid">AG Grid</el-radio-button>
|
|
139
|
-
</el-radio-group>
|
|
140
|
-
|
|
141
|
-
<BaseTable
|
|
142
|
-
:data="tableData"
|
|
143
|
-
:columns="columns"
|
|
144
|
-
:render-type="renderType"
|
|
145
|
-
/>
|
|
146
|
-
</div>
|
|
147
|
-
</template>
|
|
148
|
-
|
|
149
|
-
<script setup lang="ts">
|
|
150
|
-
import { ref } from "vue";
|
|
151
|
-
|
|
152
|
-
// 响应式渲染类型,可动态切换
|
|
153
|
-
const renderType = ref<"dataTable" | "agGrid">("dataTable");
|
|
154
|
-
</script>
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
## 📋 AGGrid 特有功能
|
|
160
|
-
|
|
161
|
-
### 1. 虚拟滚动
|
|
162
|
-
|
|
163
|
-
AGGrid 默认启用虚拟滚动,只渲染可视区域的行,大幅提升大数据量下的性能:
|
|
164
|
-
|
|
165
|
-
```vue
|
|
166
|
-
<BaseTable
|
|
167
|
-
render-type="agGrid"
|
|
168
|
-
:data="largeData"
|
|
169
|
-
:columns="columns"
|
|
170
|
-
/>
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### 2. 列配置持久化
|
|
174
|
-
|
|
175
|
-
AGGrid 模式支持用户自定义列宽、列顺序、列可见性,并可持久化保存:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
// 通过 ref 调用
|
|
179
|
-
const tableRef = ref();
|
|
180
|
-
|
|
181
|
-
// 保存当前列配置
|
|
182
|
-
tableRef.value?.persistenceStatus();
|
|
183
|
-
|
|
184
|
-
// 恢复列配置
|
|
185
|
-
tableRef.value?.restoreColumn();
|
|
186
|
-
|
|
187
|
-
// 清除列配置
|
|
188
|
-
tableRef.value?.clearColumnsStatus();
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### 3. 列设置面板
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
// 打开列设置侧边栏
|
|
195
|
-
tableRef.value?.openSetting();
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### 4. 分组与聚合
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
const columns = computed(() => [
|
|
202
|
-
{
|
|
203
|
-
name: "category",
|
|
204
|
-
label: "分类",
|
|
205
|
-
rowGroup: true, // 作为分组字段
|
|
206
|
-
hide: true // 分组字段可隐藏列
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
name: "amount",
|
|
210
|
-
label: "金额",
|
|
211
|
-
aggFunc: "sum" // 聚合函数:sum, avg, count, min, max
|
|
212
|
-
}
|
|
213
|
-
]);
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### 5. 强制刷新
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
// 强制刷新表格视图
|
|
220
|
-
tableRef.value?.forceRefresh();
|
|
221
|
-
|
|
222
|
-
// 重新加载列配置
|
|
223
|
-
tableRef.value?.reloadColumns();
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
## 📋 AgGridInstanceApi
|
|
229
|
-
|
|
230
|
-
AGGrid 模式下,通过 ref 可以获取 AG Grid 实例 API:
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
interface AgGridInstanceApi {
|
|
234
|
-
// 获取选中的行
|
|
235
|
-
getSelection: () => any[];
|
|
236
|
-
// 取消所有选中
|
|
237
|
-
deselectAll: () => void;
|
|
238
|
-
// 设置单行选中状态
|
|
239
|
-
setSelect: (row, status: boolean) => void;
|
|
240
|
-
// 设置多行选中
|
|
241
|
-
setSelection: (rows: object[]) => void;
|
|
242
|
-
// 获取可见的选中行
|
|
243
|
-
getVisibleSelection: () => any[];
|
|
244
|
-
// 获取行节点
|
|
245
|
-
getRowNode: () => any[];
|
|
246
|
-
// 添加触发器
|
|
247
|
-
addTrigger: Function;
|
|
248
|
-
// 是否单选模式
|
|
249
|
-
isSingleSelection: Ref<boolean>;
|
|
250
|
-
// 打开设置面板
|
|
251
|
-
openSetting: () => void;
|
|
252
|
-
// 原始列配置
|
|
253
|
-
rawColumns: TableColumnDesc[];
|
|
254
|
-
// 强制刷新
|
|
255
|
-
forceRefresh: () => void;
|
|
256
|
-
// 重新加载列
|
|
257
|
-
reloadColumns: () => Promise;
|
|
258
|
-
// 持久化状态
|
|
259
|
-
persistenceStatus: () => Promise;
|
|
260
|
-
// 恢复列配置
|
|
261
|
-
restoreColumn: () => void;
|
|
262
|
-
// 清除列状态
|
|
263
|
-
clearColumnsStatus: () => void;
|
|
264
|
-
// 侧边栏静默模式
|
|
265
|
-
sideBarSilence: Ref<boolean>;
|
|
266
|
-
// 获取分组合计行
|
|
267
|
-
getGroupTotalRow: () => string;
|
|
268
|
-
// 获取总计行
|
|
269
|
-
getGrandTotalRow: () => string;
|
|
270
|
-
// 获取列配置
|
|
271
|
-
getColumns: () => TableColumnDesc[];
|
|
272
|
-
// 事件触发器
|
|
273
|
-
emit: any;
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
## 📋 列配置增强
|
|
280
|
-
|
|
281
|
-
### 单元格样式
|
|
282
|
-
|
|
283
|
-
AGGrid 模式支持更灵活的单元格样式配置:
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
interface CellStyleParam {
|
|
287
|
-
row: any; // 行数据
|
|
288
|
-
value: any; // 单元格值
|
|
289
|
-
rowIndex: number; // 行索引
|
|
290
|
-
name: string; // 字段名
|
|
291
|
-
label: string; // 列标题
|
|
292
|
-
colDef: TableColumnDesc; // 列配置
|
|
293
|
-
node: object; // AG Grid 节点
|
|
294
|
-
params: object; // AG Grid 参数
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const columns = computed(() => [
|
|
298
|
-
{
|
|
299
|
-
name: "status",
|
|
300
|
-
label: "状态",
|
|
301
|
-
cellStyle: (params: CellStyleParam) => {
|
|
302
|
-
if (params.value === "error") {
|
|
303
|
-
return { color: "red", fontWeight: "bold" };
|
|
304
|
-
}
|
|
305
|
-
return {};
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
]);
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### 编辑组件
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
interface EditorParams {
|
|
315
|
-
instance: CellEditor; // 编辑器实例
|
|
316
|
-
h: any; // Vue h 函数
|
|
317
|
-
api: GridApiClass; // Grid API
|
|
318
|
-
data: object; // 行数据
|
|
319
|
-
node: Object; // AG Grid 节点
|
|
320
|
-
colDef: TableColumnDesc; // 列配置
|
|
321
|
-
rowIndex: number; // 行索引
|
|
322
|
-
|
|
323
|
-
// 方法
|
|
324
|
-
getValue: () => any;
|
|
325
|
-
setValue: (value) => void;
|
|
326
|
-
setDataValue: (key: string, value: any) => void;
|
|
327
|
-
updateData: (data: object) => void;
|
|
328
|
-
stopEditing: () => void;
|
|
329
|
-
refreshCells: () => void;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const columns = computed(() => [
|
|
333
|
-
{
|
|
334
|
-
name: "price",
|
|
335
|
-
label: "单价",
|
|
336
|
-
editable: true,
|
|
337
|
-
logicType: "number",
|
|
338
|
-
editComponent: (row, value, params: EditorParams) => ({
|
|
339
|
-
tag: "jh-input-number",
|
|
340
|
-
props: {
|
|
341
|
-
min: 0,
|
|
342
|
-
max: 99999,
|
|
343
|
-
precision: 2
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
}
|
|
347
|
-
]);
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
---
|
|
351
|
-
|
|
352
|
-
## 💡 使用示例
|
|
353
|
-
|
|
354
|
-
### 大数据量表格
|
|
355
|
-
|
|
356
|
-
```vue
|
|
357
|
-
<template>
|
|
358
|
-
<BaseTable
|
|
359
|
-
ref="tableRef"
|
|
360
|
-
render-type="agGrid"
|
|
361
|
-
:data="largeData"
|
|
362
|
-
:columns="columns"
|
|
363
|
-
:row-key="'id'"
|
|
364
|
-
@selection-change="handleSelectionChange"
|
|
365
|
-
/>
|
|
366
|
-
</template>
|
|
367
|
-
|
|
368
|
-
<script setup lang="ts">
|
|
369
|
-
import { ref, computed, onMounted } from "vue";
|
|
370
|
-
|
|
371
|
-
const tableRef = ref();
|
|
372
|
-
const largeData = ref([]);
|
|
373
|
-
|
|
374
|
-
// 加载 10 万条数据
|
|
375
|
-
onMounted(async () => {
|
|
376
|
-
largeData.value = await fetchLargeData();
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
const columns = computed(() => [
|
|
380
|
-
{ name: "id", label: "ID", width: 80 },
|
|
381
|
-
{ name: "name", label: "名称" },
|
|
382
|
-
{ name: "status", label: "状态", logicType: "dict", logicValue: "STATUS" },
|
|
383
|
-
{ name: "amount", label: "金额", logicType: "number" }
|
|
384
|
-
]);
|
|
385
|
-
</script>
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### 分组聚合
|
|
389
|
-
|
|
390
|
-
```vue
|
|
391
|
-
<template>
|
|
392
|
-
<BaseTable
|
|
393
|
-
render-type="agGrid"
|
|
394
|
-
:data="salesData"
|
|
395
|
-
:columns="columns"
|
|
396
|
-
/>
|
|
397
|
-
</template>
|
|
398
|
-
|
|
399
|
-
<script setup lang="ts">
|
|
400
|
-
const columns = computed(() => [
|
|
401
|
-
{
|
|
402
|
-
name: "region",
|
|
403
|
-
label: "区域",
|
|
404
|
-
rowGroup: true,
|
|
405
|
-
hide: true
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
name: "product",
|
|
409
|
-
label: "产品"
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
name: "quantity",
|
|
413
|
-
label: "数量",
|
|
414
|
-
aggFunc: "sum"
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
name: "amount",
|
|
418
|
-
label: "金额",
|
|
419
|
-
aggFunc: "sum",
|
|
420
|
-
formatter: (row, val) => `¥${val?.toFixed(2) || 0}`
|
|
421
|
-
}
|
|
422
|
-
]);
|
|
423
|
-
</script>
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
### 列配置持久化
|
|
427
|
-
|
|
428
|
-
```vue
|
|
429
|
-
<template>
|
|
430
|
-
<div>
|
|
431
|
-
<BaseToolbar :items="toolbarItems" />
|
|
432
|
-
<BaseTable
|
|
433
|
-
ref="tableRef"
|
|
434
|
-
render-type="agGrid"
|
|
435
|
-
:data="tableData"
|
|
436
|
-
:columns="columns"
|
|
437
|
-
/>
|
|
438
|
-
</div>
|
|
439
|
-
</template>
|
|
440
|
-
|
|
441
|
-
<script setup lang="ts">
|
|
442
|
-
const tableRef = ref();
|
|
443
|
-
|
|
444
|
-
const toolbarItems = computed(() => [
|
|
445
|
-
{
|
|
446
|
-
name: "setting",
|
|
447
|
-
label: "列设置",
|
|
448
|
-
icon: "Setting",
|
|
449
|
-
onClick: () => tableRef.value?.openSetting()
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
name: "save",
|
|
453
|
-
label: "保存配置",
|
|
454
|
-
onClick: async () => {
|
|
455
|
-
await tableRef.value?.persistenceStatus();
|
|
456
|
-
ElMessage.success("列配置已保存");
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
name: "reset",
|
|
461
|
-
label: "重置配置",
|
|
462
|
-
onClick: () => {
|
|
463
|
-
tableRef.value?.clearColumnsStatus();
|
|
464
|
-
ElMessage.success("列配置已重置");
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
]);
|
|
468
|
-
</script>
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
---
|
|
472
|
-
|
|
473
|
-
## ⚠️ 注意事项
|
|
474
|
-
|
|
475
|
-
1. **大数据量场景建议使用 AGGrid**
|
|
476
|
-
|
|
477
|
-
```vue
|
|
478
|
-
<!-- 数据量 > 1000 时推荐 -->
|
|
479
|
-
<BaseTable render-type="agGrid" />
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
2. **同一页面可以混用两种渲染模式**
|
|
483
|
-
|
|
484
|
-
```vue
|
|
485
|
-
<!-- 主表格用 agGrid,详情表格用 dataTable -->
|
|
486
|
-
<BaseTable :data="mainList" render-type="agGrid" />
|
|
487
|
-
<BaseTable :data="detailList" render-type="dataTable" />
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
3. **与 dataTable 的 API 兼容**
|
|
491
|
-
|
|
492
|
-
- 基础 API(getSelection, setSelection 等)两种模式通用
|
|
493
|
-
- AGGrid 特有 API(persistenceStatus 等)仅在 agGrid 模式下可用
|
|
494
|
-
|
|
495
|
-
3. **列配置持久化需要后端支持**
|
|
496
|
-
|
|
497
|
-
- 需要配置持久化接口
|
|
498
|
-
- 不同用户的列配置独立存储
|
|
499
|
-
|
|
500
|
-
4. **分组聚合列的 hide 属性**
|
|
501
|
-
|
|
502
|
-
```typescript
|
|
503
|
-
{
|
|
504
|
-
name: "category",
|
|
505
|
-
rowGroup: true,
|
|
506
|
-
hide: true // 分组字段建议隐藏,避免重复显示
|
|
507
|
-
}
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
5. **编辑器参数差异**
|
|
511
|
-
|
|
512
|
-
- dataTable 模式使用 `editable` + `editComponent`
|
|
513
|
-
- agGrid 模式的 `editComponent` 参数中包含更丰富的 AG Grid 上下文
|
|
514
|
-
|
|
515
|
-
6. **全局配置默认渲染模式**
|
|
516
|
-
|
|
517
|
-
```typescript
|
|
518
|
-
// 在环境配置中设置默认渲染模式
|
|
519
|
-
envConfig().componentConfig.table = {
|
|
520
|
-
renderType: "agGrid" // 全局默认使用 AGGrid
|
|
521
|
-
};
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
---
|
|
525
|
-
|
|
526
|
-
## 📚 相关文档
|
|
527
|
-
|
|
528
|
-
- [BaseTable 表格组件](../BaseTable/README.md) - 完整的表格 Props 和列配置
|
|
529
|
-
- [BaseToolbar 工具栏组件](../BaseToolbar/README.md) - 搭配工具栏使用
|
|
530
|
-
- [AG Grid 官方文档](https://www.ag-grid.com/documentation/) - AG Grid 更多高级特性
|
|
1
|
+
# AGGrid 高性能表格
|
|
2
|
+
|
|
3
|
+
> 来源:`@jhlc/common-core` 远程组件
|
|
4
|
+
|
|
5
|
+
AGGrid 是 BaseTable 的高性能渲染模式,基于 AG Grid 企业级表格库实现。适用于大数据量场景,支持虚拟滚动、列固定、分组聚合等企业级特性。
|
|
6
|
+
|
|
7
|
+
## 📦 使用方式
|
|
8
|
+
|
|
9
|
+
AGGrid 不是独立组件,而是 BaseTable 的一种渲染模式,通过 `render-type="agGrid"` 启用:
|
|
10
|
+
|
|
11
|
+
```vue
|
|
12
|
+
<template>
|
|
13
|
+
<BaseTable
|
|
14
|
+
ref="tableRef"
|
|
15
|
+
render-type="agGrid"
|
|
16
|
+
:data="tableData"
|
|
17
|
+
:columns="columns"
|
|
18
|
+
:row-key="'id'"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 💡 可以在同一页面并存使用 (但不推荐,最好默认使用一个)
|
|
24
|
+
|
|
25
|
+
**完全可以**在同一个页面中使用多个 BaseTable,并为每个表格指定不同的 `render-type`:
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<template>
|
|
29
|
+
<div>
|
|
30
|
+
<!-- 表格1:大数据量,使用 agGrid -->
|
|
31
|
+
<BaseTable
|
|
32
|
+
:data="largeDataList"
|
|
33
|
+
:columns="columns1"
|
|
34
|
+
render-type="agGrid"
|
|
35
|
+
/>
|
|
36
|
+
|
|
37
|
+
<!-- 表格2:小数据量,使用默认 dataTable -->
|
|
38
|
+
<BaseTable
|
|
39
|
+
:data="smallDataList"
|
|
40
|
+
:columns="columns2"
|
|
41
|
+
render-type="dataTable"
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 🔄 一键切换渲染模式
|
|
48
|
+
|
|
49
|
+
```vue
|
|
50
|
+
<template>
|
|
51
|
+
<div>
|
|
52
|
+
<BaseToolbar :items="toolbarItems" />
|
|
53
|
+
<BaseTable
|
|
54
|
+
:data="tableData"
|
|
55
|
+
:columns="columns"
|
|
56
|
+
:render-type="renderType"
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<script setup lang="ts">
|
|
62
|
+
import { ref } from "vue";
|
|
63
|
+
|
|
64
|
+
// 响应式渲染类型
|
|
65
|
+
const renderType = ref<"dataTable" | "agGrid">("dataTable");
|
|
66
|
+
|
|
67
|
+
const toolbarItems = computed(() => [
|
|
68
|
+
{
|
|
69
|
+
name: "switch",
|
|
70
|
+
label: `切换到 ${renderType.value === "dataTable" ? "agGrid" : "dataTable"}`,
|
|
71
|
+
icon: "Switch",
|
|
72
|
+
onClick: () => {
|
|
73
|
+
renderType.value =
|
|
74
|
+
renderType.value === "dataTable" ? "agGrid" : "dataTable";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]);
|
|
78
|
+
</script>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 🆚 与 dataTable 模式对比
|
|
82
|
+
|
|
83
|
+
| 特性 | dataTable(默认) | agGrid |
|
|
84
|
+
| ------------ | -------------------- | -------------------- |
|
|
85
|
+
| 渲染性能 | 一般(全量渲染) | 高(虚拟滚动) |
|
|
86
|
+
| 数据量支持 | < 1000 条 | 10万+ 条 |
|
|
87
|
+
| 列固定 | ✅ | ✅ |
|
|
88
|
+
| 行内编辑 | ✅ | ✅(性能更优) |
|
|
89
|
+
| 分组聚合 | ❌ | ✅ |
|
|
90
|
+
| 列拖拽排序 | ❌ | ✅ |
|
|
91
|
+
| 列配置持久化 | ❌ | ✅ |
|
|
92
|
+
| 自定义渲染 | ✅ VNode | ✅ VNode |
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 📋 renderType 属性
|
|
97
|
+
|
|
98
|
+
| 值 | 说明 |
|
|
99
|
+
| ----------- | -------------------------- |
|
|
100
|
+
| `""` | 使用全局配置(默认) |
|
|
101
|
+
| `dataTable` | 使用 Element Plus 表格渲染 |
|
|
102
|
+
| `agGrid` | 使用 AG Grid 渲染 |
|
|
103
|
+
|
|
104
|
+
### 🎯 三种配置方式
|
|
105
|
+
|
|
106
|
+
#### 方式1: 全局配置(所有未指定 render-type 的表格)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// 在环境配置文件中设置(如 vite/environment.ts 或 main.ts)
|
|
110
|
+
envConfig().componentConfig.table = {
|
|
111
|
+
renderType: "agGrid" // 或 "dataTable"
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```vue
|
|
116
|
+
<!-- 使用全局配置 -->
|
|
117
|
+
<BaseTable :data="tableData" :columns="columns" />
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### 方式2: 单独指定(不受全局配置影响)
|
|
121
|
+
|
|
122
|
+
```vue
|
|
123
|
+
<!-- 明确指定,优先级最高 -->
|
|
124
|
+
<BaseTable
|
|
125
|
+
:data="tableData"
|
|
126
|
+
:columns="columns"
|
|
127
|
+
render-type="agGrid"
|
|
128
|
+
/>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### 方式3: 响应式切换(动态切换)
|
|
132
|
+
|
|
133
|
+
```vue
|
|
134
|
+
<template>
|
|
135
|
+
<div>
|
|
136
|
+
<el-radio-group v-model="renderType">
|
|
137
|
+
<el-radio-button label="dataTable">默认表格</el-radio-button>
|
|
138
|
+
<el-radio-button label="agGrid">AG Grid</el-radio-button>
|
|
139
|
+
</el-radio-group>
|
|
140
|
+
|
|
141
|
+
<BaseTable
|
|
142
|
+
:data="tableData"
|
|
143
|
+
:columns="columns"
|
|
144
|
+
:render-type="renderType"
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
</template>
|
|
148
|
+
|
|
149
|
+
<script setup lang="ts">
|
|
150
|
+
import { ref } from "vue";
|
|
151
|
+
|
|
152
|
+
// 响应式渲染类型,可动态切换
|
|
153
|
+
const renderType = ref<"dataTable" | "agGrid">("dataTable");
|
|
154
|
+
</script>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 📋 AGGrid 特有功能
|
|
160
|
+
|
|
161
|
+
### 1. 虚拟滚动
|
|
162
|
+
|
|
163
|
+
AGGrid 默认启用虚拟滚动,只渲染可视区域的行,大幅提升大数据量下的性能:
|
|
164
|
+
|
|
165
|
+
```vue
|
|
166
|
+
<BaseTable
|
|
167
|
+
render-type="agGrid"
|
|
168
|
+
:data="largeData"
|
|
169
|
+
:columns="columns"
|
|
170
|
+
/>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 2. 列配置持久化
|
|
174
|
+
|
|
175
|
+
AGGrid 模式支持用户自定义列宽、列顺序、列可见性,并可持久化保存:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// 通过 ref 调用
|
|
179
|
+
const tableRef = ref();
|
|
180
|
+
|
|
181
|
+
// 保存当前列配置
|
|
182
|
+
tableRef.value?.persistenceStatus();
|
|
183
|
+
|
|
184
|
+
// 恢复列配置
|
|
185
|
+
tableRef.value?.restoreColumn();
|
|
186
|
+
|
|
187
|
+
// 清除列配置
|
|
188
|
+
tableRef.value?.clearColumnsStatus();
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 3. 列设置面板
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// 打开列设置侧边栏
|
|
195
|
+
tableRef.value?.openSetting();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 4. 分组与聚合
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const columns = computed(() => [
|
|
202
|
+
{
|
|
203
|
+
name: "category",
|
|
204
|
+
label: "分类",
|
|
205
|
+
rowGroup: true, // 作为分组字段
|
|
206
|
+
hide: true // 分组字段可隐藏列
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "amount",
|
|
210
|
+
label: "金额",
|
|
211
|
+
aggFunc: "sum" // 聚合函数:sum, avg, count, min, max
|
|
212
|
+
}
|
|
213
|
+
]);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 5. 强制刷新
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// 强制刷新表格视图
|
|
220
|
+
tableRef.value?.forceRefresh();
|
|
221
|
+
|
|
222
|
+
// 重新加载列配置
|
|
223
|
+
tableRef.value?.reloadColumns();
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 📋 AgGridInstanceApi
|
|
229
|
+
|
|
230
|
+
AGGrid 模式下,通过 ref 可以获取 AG Grid 实例 API:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
interface AgGridInstanceApi {
|
|
234
|
+
// 获取选中的行
|
|
235
|
+
getSelection: () => any[];
|
|
236
|
+
// 取消所有选中
|
|
237
|
+
deselectAll: () => void;
|
|
238
|
+
// 设置单行选中状态
|
|
239
|
+
setSelect: (row, status: boolean) => void;
|
|
240
|
+
// 设置多行选中
|
|
241
|
+
setSelection: (rows: object[]) => void;
|
|
242
|
+
// 获取可见的选中行
|
|
243
|
+
getVisibleSelection: () => any[];
|
|
244
|
+
// 获取行节点
|
|
245
|
+
getRowNode: () => any[];
|
|
246
|
+
// 添加触发器
|
|
247
|
+
addTrigger: Function;
|
|
248
|
+
// 是否单选模式
|
|
249
|
+
isSingleSelection: Ref<boolean>;
|
|
250
|
+
// 打开设置面板
|
|
251
|
+
openSetting: () => void;
|
|
252
|
+
// 原始列配置
|
|
253
|
+
rawColumns: TableColumnDesc[];
|
|
254
|
+
// 强制刷新
|
|
255
|
+
forceRefresh: () => void;
|
|
256
|
+
// 重新加载列
|
|
257
|
+
reloadColumns: () => Promise;
|
|
258
|
+
// 持久化状态
|
|
259
|
+
persistenceStatus: () => Promise;
|
|
260
|
+
// 恢复列配置
|
|
261
|
+
restoreColumn: () => void;
|
|
262
|
+
// 清除列状态
|
|
263
|
+
clearColumnsStatus: () => void;
|
|
264
|
+
// 侧边栏静默模式
|
|
265
|
+
sideBarSilence: Ref<boolean>;
|
|
266
|
+
// 获取分组合计行
|
|
267
|
+
getGroupTotalRow: () => string;
|
|
268
|
+
// 获取总计行
|
|
269
|
+
getGrandTotalRow: () => string;
|
|
270
|
+
// 获取列配置
|
|
271
|
+
getColumns: () => TableColumnDesc[];
|
|
272
|
+
// 事件触发器
|
|
273
|
+
emit: any;
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 📋 列配置增强
|
|
280
|
+
|
|
281
|
+
### 单元格样式
|
|
282
|
+
|
|
283
|
+
AGGrid 模式支持更灵活的单元格样式配置:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
interface CellStyleParam {
|
|
287
|
+
row: any; // 行数据
|
|
288
|
+
value: any; // 单元格值
|
|
289
|
+
rowIndex: number; // 行索引
|
|
290
|
+
name: string; // 字段名
|
|
291
|
+
label: string; // 列标题
|
|
292
|
+
colDef: TableColumnDesc; // 列配置
|
|
293
|
+
node: object; // AG Grid 节点
|
|
294
|
+
params: object; // AG Grid 参数
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const columns = computed(() => [
|
|
298
|
+
{
|
|
299
|
+
name: "status",
|
|
300
|
+
label: "状态",
|
|
301
|
+
cellStyle: (params: CellStyleParam) => {
|
|
302
|
+
if (params.value === "error") {
|
|
303
|
+
return { color: "red", fontWeight: "bold" };
|
|
304
|
+
}
|
|
305
|
+
return {};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
]);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 编辑组件
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
interface EditorParams {
|
|
315
|
+
instance: CellEditor; // 编辑器实例
|
|
316
|
+
h: any; // Vue h 函数
|
|
317
|
+
api: GridApiClass; // Grid API
|
|
318
|
+
data: object; // 行数据
|
|
319
|
+
node: Object; // AG Grid 节点
|
|
320
|
+
colDef: TableColumnDesc; // 列配置
|
|
321
|
+
rowIndex: number; // 行索引
|
|
322
|
+
|
|
323
|
+
// 方法
|
|
324
|
+
getValue: () => any;
|
|
325
|
+
setValue: (value) => void;
|
|
326
|
+
setDataValue: (key: string, value: any) => void;
|
|
327
|
+
updateData: (data: object) => void;
|
|
328
|
+
stopEditing: () => void;
|
|
329
|
+
refreshCells: () => void;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const columns = computed(() => [
|
|
333
|
+
{
|
|
334
|
+
name: "price",
|
|
335
|
+
label: "单价",
|
|
336
|
+
editable: true,
|
|
337
|
+
logicType: "number",
|
|
338
|
+
editComponent: (row, value, params: EditorParams) => ({
|
|
339
|
+
tag: "jh-input-number",
|
|
340
|
+
props: {
|
|
341
|
+
min: 0,
|
|
342
|
+
max: 99999,
|
|
343
|
+
precision: 2
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 💡 使用示例
|
|
353
|
+
|
|
354
|
+
### 大数据量表格
|
|
355
|
+
|
|
356
|
+
```vue
|
|
357
|
+
<template>
|
|
358
|
+
<BaseTable
|
|
359
|
+
ref="tableRef"
|
|
360
|
+
render-type="agGrid"
|
|
361
|
+
:data="largeData"
|
|
362
|
+
:columns="columns"
|
|
363
|
+
:row-key="'id'"
|
|
364
|
+
@selection-change="handleSelectionChange"
|
|
365
|
+
/>
|
|
366
|
+
</template>
|
|
367
|
+
|
|
368
|
+
<script setup lang="ts">
|
|
369
|
+
import { ref, computed, onMounted } from "vue";
|
|
370
|
+
|
|
371
|
+
const tableRef = ref();
|
|
372
|
+
const largeData = ref([]);
|
|
373
|
+
|
|
374
|
+
// 加载 10 万条数据
|
|
375
|
+
onMounted(async () => {
|
|
376
|
+
largeData.value = await fetchLargeData();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const columns = computed(() => [
|
|
380
|
+
{ name: "id", label: "ID", width: 80 },
|
|
381
|
+
{ name: "name", label: "名称" },
|
|
382
|
+
{ name: "status", label: "状态", logicType: "dict", logicValue: "STATUS" },
|
|
383
|
+
{ name: "amount", label: "金额", logicType: "number" }
|
|
384
|
+
]);
|
|
385
|
+
</script>
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### 分组聚合
|
|
389
|
+
|
|
390
|
+
```vue
|
|
391
|
+
<template>
|
|
392
|
+
<BaseTable
|
|
393
|
+
render-type="agGrid"
|
|
394
|
+
:data="salesData"
|
|
395
|
+
:columns="columns"
|
|
396
|
+
/>
|
|
397
|
+
</template>
|
|
398
|
+
|
|
399
|
+
<script setup lang="ts">
|
|
400
|
+
const columns = computed(() => [
|
|
401
|
+
{
|
|
402
|
+
name: "region",
|
|
403
|
+
label: "区域",
|
|
404
|
+
rowGroup: true,
|
|
405
|
+
hide: true
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
name: "product",
|
|
409
|
+
label: "产品"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: "quantity",
|
|
413
|
+
label: "数量",
|
|
414
|
+
aggFunc: "sum"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: "amount",
|
|
418
|
+
label: "金额",
|
|
419
|
+
aggFunc: "sum",
|
|
420
|
+
formatter: (row, val) => `¥${val?.toFixed(2) || 0}`
|
|
421
|
+
}
|
|
422
|
+
]);
|
|
423
|
+
</script>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### 列配置持久化
|
|
427
|
+
|
|
428
|
+
```vue
|
|
429
|
+
<template>
|
|
430
|
+
<div>
|
|
431
|
+
<BaseToolbar :items="toolbarItems" />
|
|
432
|
+
<BaseTable
|
|
433
|
+
ref="tableRef"
|
|
434
|
+
render-type="agGrid"
|
|
435
|
+
:data="tableData"
|
|
436
|
+
:columns="columns"
|
|
437
|
+
/>
|
|
438
|
+
</div>
|
|
439
|
+
</template>
|
|
440
|
+
|
|
441
|
+
<script setup lang="ts">
|
|
442
|
+
const tableRef = ref();
|
|
443
|
+
|
|
444
|
+
const toolbarItems = computed(() => [
|
|
445
|
+
{
|
|
446
|
+
name: "setting",
|
|
447
|
+
label: "列设置",
|
|
448
|
+
icon: "Setting",
|
|
449
|
+
onClick: () => tableRef.value?.openSetting()
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "save",
|
|
453
|
+
label: "保存配置",
|
|
454
|
+
onClick: async () => {
|
|
455
|
+
await tableRef.value?.persistenceStatus();
|
|
456
|
+
ElMessage.success("列配置已保存");
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
name: "reset",
|
|
461
|
+
label: "重置配置",
|
|
462
|
+
onClick: () => {
|
|
463
|
+
tableRef.value?.clearColumnsStatus();
|
|
464
|
+
ElMessage.success("列配置已重置");
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
]);
|
|
468
|
+
</script>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## ⚠️ 注意事项
|
|
474
|
+
|
|
475
|
+
1. **大数据量场景建议使用 AGGrid**
|
|
476
|
+
|
|
477
|
+
```vue
|
|
478
|
+
<!-- 数据量 > 1000 时推荐 -->
|
|
479
|
+
<BaseTable render-type="agGrid" />
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
2. **同一页面可以混用两种渲染模式**
|
|
483
|
+
|
|
484
|
+
```vue
|
|
485
|
+
<!-- 主表格用 agGrid,详情表格用 dataTable -->
|
|
486
|
+
<BaseTable :data="mainList" render-type="agGrid" />
|
|
487
|
+
<BaseTable :data="detailList" render-type="dataTable" />
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
3. **与 dataTable 的 API 兼容**
|
|
491
|
+
|
|
492
|
+
- 基础 API(getSelection, setSelection 等)两种模式通用
|
|
493
|
+
- AGGrid 特有 API(persistenceStatus 等)仅在 agGrid 模式下可用
|
|
494
|
+
|
|
495
|
+
3. **列配置持久化需要后端支持**
|
|
496
|
+
|
|
497
|
+
- 需要配置持久化接口
|
|
498
|
+
- 不同用户的列配置独立存储
|
|
499
|
+
|
|
500
|
+
4. **分组聚合列的 hide 属性**
|
|
501
|
+
|
|
502
|
+
```typescript
|
|
503
|
+
{
|
|
504
|
+
name: "category",
|
|
505
|
+
rowGroup: true,
|
|
506
|
+
hide: true // 分组字段建议隐藏,避免重复显示
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
5. **编辑器参数差异**
|
|
511
|
+
|
|
512
|
+
- dataTable 模式使用 `editable` + `editComponent`
|
|
513
|
+
- agGrid 模式的 `editComponent` 参数中包含更丰富的 AG Grid 上下文
|
|
514
|
+
|
|
515
|
+
6. **全局配置默认渲染模式**
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
// 在环境配置中设置默认渲染模式
|
|
519
|
+
envConfig().componentConfig.table = {
|
|
520
|
+
renderType: "agGrid" // 全局默认使用 AGGrid
|
|
521
|
+
};
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
526
|
+
## 📚 相关文档
|
|
527
|
+
|
|
528
|
+
- [BaseTable 表格组件](../BaseTable/README.md) - 完整的表格 Props 和列配置
|
|
529
|
+
- [BaseToolbar 工具栏组件](../BaseToolbar/README.md) - 搭配工具栏使用
|
|
530
|
+
- [AG Grid 官方文档](https://www.ag-grid.com/documentation/) - AG Grid 更多高级特性
|