@kne/table-page 0.1.7 → 0.1.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.
- package/README.md +979 -103
- package/dist/index.css +197 -15
- package/dist/index.css.map +1 -1
- package/dist/index.js +298 -82
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +296 -87
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +3 -1
- package/dist/locale/en-US.js.map +1 -1
- package/dist/locale/en-US.modern.js +3 -1
- package/dist/locale/en-US.modern.js.map +1 -1
- package/dist/locale/zh-CN.js +3 -1
- package/dist/locale/zh-CN.js.map +1 -1
- package/dist/locale/zh-CN.modern.js +3 -1
- package/dist/locale/zh-CN.modern.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -21,14 +21,15 @@ npm i --save @kne/table-page
|
|
|
21
21
|
表格页面主组件,基于 `@kne/react-fetch` 封装数据请求与分页逻辑。内置两种渲染模式:
|
|
22
22
|
|
|
23
23
|
- **`Table` 模式**(默认):基于 antd `Table`,支持列宽拖动、字段显示/隐藏、分组表头、粘性表头等
|
|
24
|
-
- **`TableView` 模式**:基于
|
|
24
|
+
- **`TableView` 模式**:基于 `@kne/table-view` CSS Grid,适合移动端或卡片式表格场景
|
|
25
25
|
|
|
26
26
|
通过 `loader` 或 `url` 配置数据源,通过 `dataFormat` 适配不同的接口数据结构。分页器渲染在表格外侧,翻页默认采用 `reload` 方式(不显示全屏 loading)。
|
|
27
27
|
|
|
28
|
-
同时内置了顶部工具栏(`TableToolbar
|
|
28
|
+
同时内置了顶部工具栏(`TableToolbar`),整合筛选、搜索、Tab 分类、批量操作等能力:
|
|
29
29
|
|
|
30
30
|
- **筛选(filter)**:基于 `@kne/react-filter` 的 `FilterLines`,支持多行多字段组合筛选,筛选值变化时自动 `reload` 并回到第 1 页
|
|
31
31
|
- **搜索(search)**:基于 `@kne/react-filter` 的 `SearchInput`,支持关键词搜索与防抖自动提交,与筛选器共享筛选值状态
|
|
32
|
+
- **Tab(tab)**:顶部分类切换,默认「全部」,选中值写入 filter value 并显示在已选标签;桌面端在表格边框外侧,移动端显示在 SearchInput 下方;可通过 `tabProps` 透传 antd Tabs 属性
|
|
32
33
|
- **批量操作(batchActions)**:配合 `rowSelection` 和 `useSelectedRow`,提供下拉菜单形式的批量操作(如批量导出、批量通知),未选中时自动禁用
|
|
33
34
|
- **已选筛选值展示**:工具栏下方展示当前生效的筛选条件标签,支持快速清除
|
|
34
35
|
|
|
@@ -44,7 +45,7 @@ npm i --save @kne/table-page
|
|
|
44
45
|
|
|
45
46
|
#### TableView
|
|
46
47
|
|
|
47
|
-
基于 CSS Grid
|
|
48
|
+
基于 `@kne/table-view` 的 CSS Grid 表格视图组件。相比于 `Table`,它更轻量灵活,适合需要自定义渲染、移动端卡片展示的场景。支持:
|
|
48
49
|
|
|
49
50
|
- 基于 24 栅格的列宽分配(`span` 属性)
|
|
50
51
|
- CSS Grid 自动布局,内容超出时自动撑开
|
|
@@ -74,6 +75,51 @@ npm i --save @kne/table-page
|
|
|
74
75
|
- 排序状态循环切换:DESC → ASC → 取消
|
|
75
76
|
- `sortDataSource(dataSource, sort, columns)` 工具函数,支持本地排序(包含中文排序)
|
|
76
77
|
|
|
78
|
+
### 渲染逻辑
|
|
79
|
+
|
|
80
|
+
#### 双模式:Table / TableView
|
|
81
|
+
|
|
82
|
+
`TablePage` 通过 `type` 切换底层表格实现:
|
|
83
|
+
|
|
84
|
+
| 模式 | 底层 | 适用场景 |
|
|
85
|
+
|------|------|----------|
|
|
86
|
+
| `Table`(默认) | antd `Table` | 桌面端完整表格能力:列宽拖动、列配置、分组表头、粘性表头、总结栏 |
|
|
87
|
+
| `TableView` | `@kne/table-view` CSS Grid | 轻量栅格表格、移动端、卡片式展示 |
|
|
88
|
+
|
|
89
|
+
两种模式共享 `columns`、`rowSelection`、`sortRender`、`renderType` 等 API,列渲染管线统一来自 `@kne/table-view`。
|
|
90
|
+
|
|
91
|
+
#### 列单元格渲染管线
|
|
92
|
+
|
|
93
|
+
无论 `Table` 还是 `TableView`,单元格内容均走同一套流程(`Table` 在 antd `columns[].render` 内调用):
|
|
94
|
+
|
|
95
|
+
1. **`resolveColumns`**:解析 `renderType`,注入内置 `render` 与 `width` / `min` / `max` / `ellipsis`
|
|
96
|
+
2. **`computeColumnsValue`**:`getValueOf` 取值 → `format` 格式化 → 按 `display` / 空值规则过滤
|
|
97
|
+
3. **`computeDisplay`**:空值占位;非空调用列 `render`
|
|
98
|
+
4. **`renderCellContent`**:按 `ellipsis` / `cellFullWidth` 输出最终节点
|
|
99
|
+
|
|
100
|
+
列渲染优先级:`column.render`(最高)> `renderType` 内置渲染 > 原始格式化值。`render` 与 `renderType` 共存时,后者仅提供列宽等布局维度。
|
|
101
|
+
|
|
102
|
+
#### 桌面端:antd Table
|
|
103
|
+
|
|
104
|
+
`Table` 将解析后的列映射为 antd `columns`,在 `render` 回调中复用上述管线。额外能力:
|
|
105
|
+
|
|
106
|
+
- `useTableConfig` 管理列宽拖动、显示/隐藏、localStorage 持久化
|
|
107
|
+
- `useGroupHeader` 生成分组表头
|
|
108
|
+
- `rowSelection` 映射为 antd 行选择(含 `allowSelectedAll` 全选)
|
|
109
|
+
- `render={({ header, renderBody }) => ...}` 可自定义表格外层,`renderBody()` 返回完整 antd Table
|
|
110
|
+
|
|
111
|
+
#### 移动端:`renderMobile`
|
|
112
|
+
|
|
113
|
+
`Table` 与 `TableView` 均支持 `renderMobile`,移动端判断使用 `useIsMobile()`(768px)。激活后 `Table` **不再渲染 antd Table**,委托 `TableView` 处理:
|
|
114
|
+
|
|
115
|
+
| `renderMobile` 值 | 行为 |
|
|
116
|
+
|-------------------|------|
|
|
117
|
+
| `true` | 默认卡片 List:每行一张卡片,字段列「标题 + 内容」纵向排列,`options` 操作列靠右(紧凑「⋯」入口) |
|
|
118
|
+
| `function` | 完全接管移动端渲染,签名 `({ header, renderBody, ...props }) => ReactNode`;可调用 `renderBody()` 复用默认卡片 |
|
|
119
|
+
| `string` | 从 `preset({ renderMobile: { [name]: fn } })` 查找;未注册则视为未开启,回退普通表格 |
|
|
120
|
+
|
|
121
|
+
桌面端不受 `renderMobile` 影响:`Table` 仍走 antd Table,`TableView` 仍走 CSS Grid 或 `render`。
|
|
122
|
+
|
|
77
123
|
### 列渲染类型系统
|
|
78
124
|
|
|
79
125
|
通过 `renderType` 属性,可以用声明式的方式定义列的渲染样式,无需手写 `render` 函数。内置以下 render 类型:
|
|
@@ -116,7 +162,7 @@ npm i --save @kne/table-page
|
|
|
116
162
|
- **后台管理系统**:订单管理、用户列表、商品管理等 CRUD 页面
|
|
117
163
|
- **数据报表**:配合排序、分页、总结栏展示统计数据
|
|
118
164
|
- **列表配置页**:需要用户自定义列宽、显示字段的表格场景
|
|
119
|
-
-
|
|
165
|
+
- **移动端适配**:`renderMobile` 启用卡片 List,或 `TableView` 模式做栅格式展示
|
|
120
166
|
|
|
121
167
|
|
|
122
168
|
### 示例
|
|
@@ -124,8 +170,8 @@ npm i --save @kne/table-page
|
|
|
124
170
|
#### 示例代码
|
|
125
171
|
|
|
126
172
|
- TablePage
|
|
127
|
-
- 表格页面组件,基于 @kne/react-fetch 实现数据加载与分页,支持 sticky 固定表头、useSort
|
|
128
|
-
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd),_ReactFilter(@kne/react-filter)[import * as _ReactFilter from "@kne/react-filter"],(@kne/react-filter/dist/index.css)
|
|
173
|
+
- 表格页面组件,基于 @kne/react-fetch 实现数据加载与分页,支持 sticky 固定表头、useSort 服务端排序、renderMobile 移动端卡片、tab 分类切换、列配置、总结栏等
|
|
174
|
+
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd),_ReactFilter(@kne/react-filter)[import * as _ReactFilter from "@kne/react-filter"],(@kne/react-filter/dist/index.css),_ResponsiveUtils(@kne/responsive-utils)[import * as _ResponsiveUtils from "@kne/responsive-utils"]
|
|
129
175
|
|
|
130
176
|
```jsx
|
|
131
177
|
const { default: TablePage, Table } = _TablePage;
|
|
@@ -133,6 +179,7 @@ const { fields } = _ReactFilter;
|
|
|
133
179
|
const { SuperSelectFilterItem } = fields;
|
|
134
180
|
const { Table: AntTable, Flex, Tag, Button, Space, message } = antd;
|
|
135
181
|
const { useMemo } = React;
|
|
182
|
+
const { useIsMobile } = _ResponsiveUtils;
|
|
136
183
|
|
|
137
184
|
const TOTAL = 156;
|
|
138
185
|
|
|
@@ -161,6 +208,7 @@ const perfMap = {
|
|
|
161
208
|
|
|
162
209
|
const departmentOptions = departments.map(item => ({ value: item, label: item }));
|
|
163
210
|
const statusOptions = Object.entries(statusMap).map(([value, { text }]) => ({ value, label: text }));
|
|
211
|
+
const positionOptions = positions.map(item => ({ value: item, label: item }));
|
|
164
212
|
|
|
165
213
|
const buildEmployee = index => {
|
|
166
214
|
const statusKeys = ['active', 'vacation', 'resigned', 'probation'];
|
|
@@ -287,6 +335,11 @@ const applyFilters = (employees, data, requestParams) => {
|
|
|
287
335
|
result = result.filter(item => item.status === status);
|
|
288
336
|
}
|
|
289
337
|
|
|
338
|
+
const position = normalizeFilterValue(params.position);
|
|
339
|
+
if (position) {
|
|
340
|
+
result = result.filter(item => item.position === position);
|
|
341
|
+
}
|
|
342
|
+
|
|
290
343
|
return result;
|
|
291
344
|
};
|
|
292
345
|
|
|
@@ -321,13 +374,21 @@ const Tips = () => (
|
|
|
321
374
|
<Tag style={TIP_TAG_STYLE} color="gold">筛选</Tag>
|
|
322
375
|
顶部工具栏集成 <code>filter</code>、<code>search</code>、<code>batchActions</code>;筛选变化自动 <code>reload</code> 并回到第 1 页。
|
|
323
376
|
</div>
|
|
377
|
+
<div>
|
|
378
|
+
<Tag style={TIP_TAG_STYLE} color="lime">Tab</Tag>
|
|
379
|
+
通过 <code>tab</code> 配置顶部分类切换(默认「全部」),选中值写入 filter value 并显示在已选标签;桌面端在表格边框外,移动端在 SearchInput 下方;可用 <code>tabProps</code> 透传 Tabs 属性(如 <code>tabBarExtraContent</code>)。
|
|
380
|
+
</div>
|
|
324
381
|
<div>
|
|
325
382
|
<Tag style={TIP_TAG_STYLE} color="orange">列配置</Tag>
|
|
326
383
|
设置 <code>name</code> 开启列宽拖动与显示/隐藏,「薪资范围」「学历」默认隐藏;状态列使用 <code>renderType="status"</code>,绩效列使用 <code>renderType="tag"</code>,操作列使用 <code>renderType="options"</code> 且 <code>fixed="right"</code>。
|
|
327
384
|
</div>
|
|
328
385
|
<div>
|
|
329
386
|
<Tag style={TIP_TAG_STYLE} color="cyan">排序</Tag>
|
|
330
|
-
配合 <code>Table.useSort</code> 与 <code>sortRender</code>,在 <code>onSortChange</code> 中调用 <code>reload</code> 传排序参数,与翻页一样不闪烁。
|
|
387
|
+
配合 <code>Table.useSort</code> 与 <code>sortRender</code>、<code>mobileSortToolbar</code>,在 <code>onSortChange</code> 中调用 <code>reload</code> 传排序参数,与翻页一样不闪烁。
|
|
388
|
+
</div>
|
|
389
|
+
<div>
|
|
390
|
+
<Tag style={TIP_TAG_STYLE} color="volcano">移动端</Tag>
|
|
391
|
+
设置 <code>renderMobile</code> 后,手机预览下启用卡片 List(含全选、排序工具栏);桌面端仍为 antd Table。
|
|
331
392
|
</div>
|
|
332
393
|
<div>
|
|
333
394
|
<Tag style={TIP_TAG_STYLE} color="geekblue">固定表头</Tag>
|
|
@@ -344,11 +405,14 @@ const Tips = () => (
|
|
|
344
405
|
</div>
|
|
345
406
|
);
|
|
346
407
|
|
|
408
|
+
const MOBILE_PREVIEW_PADDING = '0 16px';
|
|
409
|
+
|
|
347
410
|
const BaseExample = () => {
|
|
348
411
|
const tableRef = React.useRef();
|
|
412
|
+
const isMobile = useIsMobile();
|
|
349
413
|
const allEmployees = useMemo(() => range(0, TOTAL).map(buildEmployee), []);
|
|
350
414
|
const { selectedRows, getRowSelection } = Table.useSelectedRow({ rowKey: 'id' });
|
|
351
|
-
const { sort, sortRender } = Table.useSort({
|
|
415
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({
|
|
352
416
|
defaultSort: [{ name: 'joinDate', sort: 'DESC' }],
|
|
353
417
|
onSortChange: newSort => {
|
|
354
418
|
tableRef.current?.reload({
|
|
@@ -379,95 +443,112 @@ const BaseExample = () => {
|
|
|
379
443
|
刷新当前页
|
|
380
444
|
</Button>
|
|
381
445
|
</Space>
|
|
382
|
-
<
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
446
|
+
<div style={isMobile ? { padding: MOBILE_PREVIEW_PADDING } : undefined}>
|
|
447
|
+
<TablePage
|
|
448
|
+
ref={tableRef}
|
|
449
|
+
name="demo-employee-table"
|
|
450
|
+
sticky
|
|
451
|
+
scroll={{ x: 1600, y: 400 }}
|
|
452
|
+
size="large"
|
|
453
|
+
renderMobile
|
|
454
|
+
sortRender={sortRender}
|
|
455
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
456
|
+
rowSelection={getRowSelection(allEmployees)}
|
|
457
|
+
selectedRows={selectedRows}
|
|
458
|
+
search={{ name: 'keyword', label: '关键词', placeholder: '搜索工号/姓名', style: { width: 220 } }}
|
|
459
|
+
tab={{
|
|
460
|
+
name: 'position',
|
|
461
|
+
label: '职位',
|
|
462
|
+
list: positionOptions
|
|
463
|
+
}}
|
|
464
|
+
tabProps={{
|
|
465
|
+
tabBarExtraContent: (
|
|
466
|
+
<Button type="link" size="small" onClick={() => message.info('新增职位')}>
|
|
467
|
+
新增职位
|
|
468
|
+
</Button>
|
|
469
|
+
)
|
|
470
|
+
}}
|
|
471
|
+
filter={{
|
|
472
|
+
list: [
|
|
473
|
+
[
|
|
474
|
+
{
|
|
475
|
+
type: SuperSelectFilterItem,
|
|
476
|
+
props: { name: 'department', label: '部门', single: true, options: departmentOptions }
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: SuperSelectFilterItem,
|
|
480
|
+
props: { name: 'status', label: '状态', single: true, options: statusOptions }
|
|
481
|
+
}
|
|
482
|
+
]
|
|
483
|
+
],
|
|
484
|
+
displayLine: 1
|
|
485
|
+
}}
|
|
486
|
+
batchActions={[
|
|
487
|
+
{
|
|
488
|
+
key: 'export',
|
|
489
|
+
label: '批量导出',
|
|
490
|
+
onClick: ({ selectedRowKeys }) => {
|
|
491
|
+
message.info(`正在导出 ${selectedRowKeys.length} 名员工`);
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
key: 'notify',
|
|
496
|
+
label: '批量通知',
|
|
497
|
+
onClick: ({ selectedRowKeys }) => {
|
|
498
|
+
message.success(`已通知 ${selectedRowKeys.length} 名员工`);
|
|
401
499
|
}
|
|
402
|
-
]
|
|
403
|
-
],
|
|
404
|
-
displayLine: 1
|
|
405
|
-
}}
|
|
406
|
-
batchActions={[
|
|
407
|
-
{
|
|
408
|
-
key: 'export',
|
|
409
|
-
label: '批量导出',
|
|
410
|
-
onClick: ({ selectedRowKeys }) => {
|
|
411
|
-
message.info(`正在导出 ${selectedRowKeys.length} 名员工`);
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
key: 'notify',
|
|
416
|
-
label: '批量通知',
|
|
417
|
-
onClick: ({ selectedRowKeys }) => {
|
|
418
|
-
message.success(`已通知 ${selectedRowKeys.length} 名员工`);
|
|
419
500
|
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
</AntTable.Summary.
|
|
466
|
-
</AntTable.Summary
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
501
|
+
]}
|
|
502
|
+
pagination={{
|
|
503
|
+
open: true,
|
|
504
|
+
pageSize: 10,
|
|
505
|
+
showSizeChanger: true,
|
|
506
|
+
showQuickJumper: true,
|
|
507
|
+
pageSizeOptions: ['10', '20', '50', '100']
|
|
508
|
+
}}
|
|
509
|
+
dataFormat={data => ({
|
|
510
|
+
list: data.pageData,
|
|
511
|
+
total: data.totalCount,
|
|
512
|
+
data
|
|
513
|
+
})}
|
|
514
|
+
loader={({ data, requestParams }) => {
|
|
515
|
+
const currentPage = Number(data?.currentPage ?? requestParams?.data?.currentPage) || 1;
|
|
516
|
+
const perPage = Number(data?.perPage ?? requestParams?.data?.perPage) || 20;
|
|
517
|
+
const sortParams = data?.sort ?? requestParams?.data?.sort ?? [{ name: 'joinDate', sort: 'DESC' }];
|
|
518
|
+
const filteredEmployees = applyFilters(allEmployees, data, requestParams);
|
|
519
|
+
const sortedEmployees = sortParams.length ? Table.sortDataSource(filteredEmployees, sortParams, columns) : filteredEmployees;
|
|
520
|
+
const startIndex = (currentPage - 1) * perPage;
|
|
521
|
+
|
|
522
|
+
return new Promise(resolve => {
|
|
523
|
+
setTimeout(() => {
|
|
524
|
+
resolve({
|
|
525
|
+
pageData: sortedEmployees.slice(startIndex, startIndex + perPage),
|
|
526
|
+
totalCount: filteredEmployees.length
|
|
527
|
+
});
|
|
528
|
+
}, 400);
|
|
529
|
+
});
|
|
530
|
+
}}
|
|
531
|
+
columns={columns}
|
|
532
|
+
summary={({ pageData, data }) => {
|
|
533
|
+
const totalCount = data?.totalCount || 0;
|
|
534
|
+
return (
|
|
535
|
+
<AntTable.Summary fixed>
|
|
536
|
+
<AntTable.Summary.Row>
|
|
537
|
+
<AntTable.Summary.Cell index={0} colSpan={5}>
|
|
538
|
+
<strong>当前页统计</strong>
|
|
539
|
+
</AntTable.Summary.Cell>
|
|
540
|
+
<AntTable.Summary.Cell index={5}>
|
|
541
|
+
<strong>{pageData.length} 人</strong>
|
|
542
|
+
</AntTable.Summary.Cell>
|
|
543
|
+
<AntTable.Summary.Cell index={6} colSpan={7}>
|
|
544
|
+
<strong>总员工数: {totalCount} 人</strong>
|
|
545
|
+
</AntTable.Summary.Cell>
|
|
546
|
+
</AntTable.Summary.Row>
|
|
547
|
+
</AntTable.Summary>
|
|
548
|
+
);
|
|
549
|
+
}}
|
|
550
|
+
/>
|
|
551
|
+
</div>
|
|
471
552
|
</Flex>
|
|
472
553
|
);
|
|
473
554
|
};
|
|
@@ -1628,6 +1709,609 @@ render(<BaseExample />);
|
|
|
1628
1709
|
|
|
1629
1710
|
```
|
|
1630
1711
|
|
|
1712
|
+
- column render
|
|
1713
|
+
- 列同时配置 render 与 renderType 时,render 优先级最高,覆盖内置 renderType 的单元格渲染(Table / TableView 一致)
|
|
1714
|
+
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd)
|
|
1715
|
+
|
|
1716
|
+
```jsx
|
|
1717
|
+
const { Table, TableView } = _TablePage;
|
|
1718
|
+
const { Flex, Tag } = antd;
|
|
1719
|
+
|
|
1720
|
+
const statusMap = {
|
|
1721
|
+
待发货: { type: 'warning', text: '待发货' },
|
|
1722
|
+
处理中: { type: 'processing', text: '处理中' },
|
|
1723
|
+
已完成: { type: 'success', text: '已完成' }
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
const dataSource = [
|
|
1727
|
+
{
|
|
1728
|
+
id: 'ORD001',
|
|
1729
|
+
customerName: '深圳市腾讯计算机系统有限公司',
|
|
1730
|
+
amount: 42500,
|
|
1731
|
+
status: '待发货'
|
|
1732
|
+
},
|
|
1733
|
+
{
|
|
1734
|
+
id: 'ORD002',
|
|
1735
|
+
customerName: '华为技术有限公司',
|
|
1736
|
+
amount: 85000,
|
|
1737
|
+
status: '处理中'
|
|
1738
|
+
},
|
|
1739
|
+
{
|
|
1740
|
+
id: 'ORD003',
|
|
1741
|
+
customerName: '阿里巴巴集团控股有限公司',
|
|
1742
|
+
amount: 120000,
|
|
1743
|
+
status: '已完成'
|
|
1744
|
+
}
|
|
1745
|
+
];
|
|
1746
|
+
|
|
1747
|
+
const columns = [
|
|
1748
|
+
{ name: 'id', title: '编号', renderType: 'small' },
|
|
1749
|
+
{ name: 'customerName', title: '客户名称', renderType: 'main' },
|
|
1750
|
+
{
|
|
1751
|
+
name: 'amount',
|
|
1752
|
+
title: '金额',
|
|
1753
|
+
renderType: 'amount',
|
|
1754
|
+
format: 'number-style:decimal-maximumFractionDigits:0-useGrouping:true-suffix:元'
|
|
1755
|
+
},
|
|
1756
|
+
{
|
|
1757
|
+
name: 'status',
|
|
1758
|
+
title: '状态(仅 renderType)',
|
|
1759
|
+
renderType: 'status',
|
|
1760
|
+
getValueOf: item => statusMap[item.status]
|
|
1761
|
+
},
|
|
1762
|
+
{
|
|
1763
|
+
name: 'statusRender',
|
|
1764
|
+
title: '状态(render 优先)',
|
|
1765
|
+
renderType: 'status',
|
|
1766
|
+
getValueOf: item => statusMap[item.status],
|
|
1767
|
+
render: (value, { dataSource }) => (
|
|
1768
|
+
<span style={{ color: '#1677ff' }}>
|
|
1769
|
+
自定义渲染:{dataSource.status}(未走 status Badge)
|
|
1770
|
+
</span>
|
|
1771
|
+
)
|
|
1772
|
+
}
|
|
1773
|
+
];
|
|
1774
|
+
|
|
1775
|
+
const BaseExample = () => {
|
|
1776
|
+
return (
|
|
1777
|
+
<Flex vertical gap={24}>
|
|
1778
|
+
<div style={{ color: '#666', fontSize: 13, lineHeight: 1.8 }}>
|
|
1779
|
+
<p>
|
|
1780
|
+
列同时配置 <code>render</code> 与 <code>renderType</code> 时,
|
|
1781
|
+
<Tag color="blue" style={{ margin: '0 4px' }}>render 优先级最高</Tag>
|
|
1782
|
+
,会直接使用自定义 <code>render</code>,不再走内置 renderType。
|
|
1783
|
+
</p>
|
|
1784
|
+
<ul style={{ margin: '8px 0', paddingLeft: 20 }}>
|
|
1785
|
+
<li>「状态(仅 renderType)」列:走内置 <code>status</code>,渲染 Badge</li>
|
|
1786
|
+
<li>「状态(render 优先)」列:同样写了 <code>renderType: 'status'</code>,但因存在 <code>render</code>,最终显示自定义内容</li>
|
|
1787
|
+
<li>renderType 仍可提供列宽等维度(width / min / max),仅单元格内容渲染被 <code>render</code> 覆盖</li>
|
|
1788
|
+
</ul>
|
|
1789
|
+
</div>
|
|
1790
|
+
<div>
|
|
1791
|
+
<div style={{ marginBottom: 8, color: '#666' }}>Table</div>
|
|
1792
|
+
<Table dataSource={dataSource} columns={columns} scroll={{ x: 1200 }} />
|
|
1793
|
+
</div>
|
|
1794
|
+
<div>
|
|
1795
|
+
<div style={{ marginBottom: 8, color: '#666' }}>TableView</div>
|
|
1796
|
+
<TableView dataSource={dataSource} columns={columns} />
|
|
1797
|
+
</div>
|
|
1798
|
+
</Flex>
|
|
1799
|
+
);
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
render(<BaseExample />);
|
|
1803
|
+
|
|
1804
|
+
```
|
|
1805
|
+
|
|
1806
|
+
- renderMobile
|
|
1807
|
+
- 移动端专用渲染:true 为默认卡片 List;function 完全接管;string 从 preset 按名称查找;支持 mobileSortToolbar 排序工具栏
|
|
1808
|
+
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd)
|
|
1809
|
+
|
|
1810
|
+
```jsx
|
|
1811
|
+
const { Table, TableView, preset } = _TablePage;
|
|
1812
|
+
const { Flex, Tag, Card, Button, Dropdown, Tabs, Checkbox } = antd;
|
|
1813
|
+
const { useState, useMemo } = React;
|
|
1814
|
+
|
|
1815
|
+
const statusMap = {
|
|
1816
|
+
已完成: { color: 'success', text: '已完成' },
|
|
1817
|
+
处理中: { color: 'processing', text: '处理中' },
|
|
1818
|
+
待发货: { color: 'warning', text: '待发货' }
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
const dataSource = [
|
|
1822
|
+
{
|
|
1823
|
+
id: 'ORD001',
|
|
1824
|
+
customerName: '深圳市腾讯计算机系统有限公司',
|
|
1825
|
+
contact: '张三',
|
|
1826
|
+
phone: '13800138000',
|
|
1827
|
+
amount: 42500,
|
|
1828
|
+
status: '已完成'
|
|
1829
|
+
},
|
|
1830
|
+
{
|
|
1831
|
+
id: 'ORD002',
|
|
1832
|
+
customerName: '华为技术有限公司',
|
|
1833
|
+
contact: '李四',
|
|
1834
|
+
phone: '13900149000',
|
|
1835
|
+
amount: 85000,
|
|
1836
|
+
status: '处理中'
|
|
1837
|
+
},
|
|
1838
|
+
{
|
|
1839
|
+
id: 'ORD003',
|
|
1840
|
+
customerName: '阿里巴巴集团控股有限公司',
|
|
1841
|
+
contact: '王五',
|
|
1842
|
+
phone: '13700157000',
|
|
1843
|
+
amount: 120000,
|
|
1844
|
+
status: '待发货'
|
|
1845
|
+
}
|
|
1846
|
+
];
|
|
1847
|
+
|
|
1848
|
+
const columns = [
|
|
1849
|
+
{ name: 'id', title: '订单编号', width: 120, renderType: 'small' },
|
|
1850
|
+
{ name: 'customerName', title: '客户名称', width: 220, renderType: 'main', sort: true },
|
|
1851
|
+
{ name: 'contact', title: '联系人', width: 80 },
|
|
1852
|
+
{ name: 'phone', title: '联系电话', width: 130, render: value => value.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3') },
|
|
1853
|
+
{
|
|
1854
|
+
name: 'amount',
|
|
1855
|
+
title: '订单金额',
|
|
1856
|
+
width: 120,
|
|
1857
|
+
sort: true,
|
|
1858
|
+
renderType: 'amount',
|
|
1859
|
+
format: 'number-style:decimal-maximumFractionDigits:0-useGrouping:true-suffix:元'
|
|
1860
|
+
},
|
|
1861
|
+
{
|
|
1862
|
+
name: 'status',
|
|
1863
|
+
title: '状态',
|
|
1864
|
+
width: 100,
|
|
1865
|
+
renderType: 'status',
|
|
1866
|
+
getValueOf: item => ({ type: statusMap[item.status]?.color || 'default', text: item.status })
|
|
1867
|
+
},
|
|
1868
|
+
{
|
|
1869
|
+
name: 'options',
|
|
1870
|
+
title: '操作',
|
|
1871
|
+
width: 140,
|
|
1872
|
+
renderType: 'options',
|
|
1873
|
+
getValueOf: item => [
|
|
1874
|
+
{ children: '查看', onClick: () => console.log('查看', item.id) },
|
|
1875
|
+
{ children: '编辑', onClick: () => console.log('编辑', item.id) },
|
|
1876
|
+
{ children: '删除', isDelete: true, message: `确定删除 ${item.id} 吗?`, onClick: () => console.log('删除', item.id) }
|
|
1877
|
+
]
|
|
1878
|
+
}
|
|
1879
|
+
];
|
|
1880
|
+
|
|
1881
|
+
preset({
|
|
1882
|
+
renderMobile: {
|
|
1883
|
+
orderCard: ({ renderBody }) => {
|
|
1884
|
+
const totalAmount = dataSource.reduce((sum, item) => sum + item.amount, 0);
|
|
1885
|
+
return (
|
|
1886
|
+
<div
|
|
1887
|
+
className="preset-order-card-example"
|
|
1888
|
+
style={{
|
|
1889
|
+
borderRadius: 12,
|
|
1890
|
+
background: '#f5f7fa',
|
|
1891
|
+
padding: 16
|
|
1892
|
+
}}
|
|
1893
|
+
>
|
|
1894
|
+
<style>{`
|
|
1895
|
+
.preset-order-card-example .info-page-table-mobile-card:not(.is-mobile-card-selected):not(.is-mobile-card-selected-all) {
|
|
1896
|
+
background: linear-gradient(135deg, #ffffff 0%, #f9f0ff 52%, #eef2ff 100%) !important;
|
|
1897
|
+
border-color: #e8dfff !important;
|
|
1898
|
+
}
|
|
1899
|
+
.preset-order-card-example .info-page-table-mobile-card:not(.is-mobile-card-selected):not(.is-mobile-card-selected-all):hover {
|
|
1900
|
+
background: linear-gradient(135deg, #fafafa 0%, #f3ebff 52%, #e8eeff 100%) !important;
|
|
1901
|
+
}
|
|
1902
|
+
`}</style>
|
|
1903
|
+
<div style={{ marginBottom: 16 }}>
|
|
1904
|
+
<Flex justify="space-between" align="center" gap={8} style={{ marginBottom: 4 }}>
|
|
1905
|
+
<div style={{ fontSize: 17, fontWeight: 600, color: 'rgba(0,0,0,0.88)' }}>近期订单</div>
|
|
1906
|
+
<Tag color="purple" style={{ margin: 0, flexShrink: 0 }}>
|
|
1907
|
+
preset: orderCard
|
|
1908
|
+
</Tag>
|
|
1909
|
+
</Flex>
|
|
1910
|
+
<div style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>
|
|
1911
|
+
{dataSource.length} 笔 · 合计 ¥{totalAmount.toLocaleString()}
|
|
1912
|
+
</div>
|
|
1913
|
+
</div>
|
|
1914
|
+
<div
|
|
1915
|
+
className="info-page-table"
|
|
1916
|
+
style={{
|
|
1917
|
+
'--kne-table-cell-padding': '14px 8px'
|
|
1918
|
+
}}
|
|
1919
|
+
>
|
|
1920
|
+
{renderBody()}
|
|
1921
|
+
</div>
|
|
1922
|
+
</div>
|
|
1923
|
+
);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
|
|
1928
|
+
const formatPhone = phone => phone.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
|
|
1929
|
+
|
|
1930
|
+
const getOrderActions = item => [
|
|
1931
|
+
{ key: 'view', label: '查看', onClick: () => console.log('查看', item.id) },
|
|
1932
|
+
{ key: 'edit', label: '编辑', onClick: () => console.log('编辑', item.id) },
|
|
1933
|
+
{ key: 'delete', label: '删除', danger: true, onClick: () => console.log('删除', item.id) }
|
|
1934
|
+
];
|
|
1935
|
+
|
|
1936
|
+
const OrderMobileCard = ({ item, checked, disabled, onCheckChange }) => {
|
|
1937
|
+
const status = statusMap[item.status] || { color: 'default', text: item.status };
|
|
1938
|
+
const actionItems = getOrderActions(item);
|
|
1939
|
+
const isSelected = checked;
|
|
1940
|
+
|
|
1941
|
+
return (
|
|
1942
|
+
<div
|
|
1943
|
+
style={{
|
|
1944
|
+
display: 'flex',
|
|
1945
|
+
alignItems: 'flex-start',
|
|
1946
|
+
gap: 12,
|
|
1947
|
+
background: isSelected ? 'var(--primary-color-1, #e6f4ff)' : '#fff',
|
|
1948
|
+
borderRadius: 12,
|
|
1949
|
+
padding: 16,
|
|
1950
|
+
border: `1px solid ${isSelected ? 'var(--primary-color-2, var(--primary-color, #1677ff))' : 'transparent'}`,
|
|
1951
|
+
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.04)',
|
|
1952
|
+
color: isSelected ? 'var(--primary-color, #1677ff)' : undefined,
|
|
1953
|
+
boxSizing: 'border-box'
|
|
1954
|
+
}}
|
|
1955
|
+
>
|
|
1956
|
+
<Checkbox checked={checked} disabled={disabled} onChange={onCheckChange} style={{ marginTop: 2, flexShrink: 0 }} />
|
|
1957
|
+
<div style={{ flex: 1, minWidth: 0 }}>
|
|
1958
|
+
<Flex justify="space-between" align="center" gap={8} style={{ marginBottom: 10 }}>
|
|
1959
|
+
<Flex align="center" gap={8} wrap="wrap" style={{ flex: 1, minWidth: 0 }}>
|
|
1960
|
+
<Tag color={status.color} style={{ margin: 0 }}>
|
|
1961
|
+
{status.text}
|
|
1962
|
+
</Tag>
|
|
1963
|
+
<span style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>{item.id}</span>
|
|
1964
|
+
</Flex>
|
|
1965
|
+
<Dropdown
|
|
1966
|
+
trigger={['click']}
|
|
1967
|
+
menu={{
|
|
1968
|
+
items: actionItems.map(({ key, label, danger, onClick }) => ({
|
|
1969
|
+
key,
|
|
1970
|
+
label,
|
|
1971
|
+
danger,
|
|
1972
|
+
onClick: ({ domEvent }) => {
|
|
1973
|
+
domEvent.stopPropagation();
|
|
1974
|
+
onClick();
|
|
1975
|
+
}
|
|
1976
|
+
}))
|
|
1977
|
+
}}
|
|
1978
|
+
>
|
|
1979
|
+
<Button type="text" size="small" style={{ padding: '0 4px' }} onClick={e => e.stopPropagation()}>
|
|
1980
|
+
···
|
|
1981
|
+
</Button>
|
|
1982
|
+
</Dropdown>
|
|
1983
|
+
</Flex>
|
|
1984
|
+
<div
|
|
1985
|
+
style={{
|
|
1986
|
+
fontSize: 16,
|
|
1987
|
+
fontWeight: 600,
|
|
1988
|
+
color: 'rgba(0,0,0,0.88)',
|
|
1989
|
+
lineHeight: 1.5,
|
|
1990
|
+
marginBottom: 6
|
|
1991
|
+
}}
|
|
1992
|
+
>
|
|
1993
|
+
{item.customerName}
|
|
1994
|
+
</div>
|
|
1995
|
+
<div style={{ fontSize: 13, color: 'rgba(0,0,0,0.45)', lineHeight: 1.6 }}>
|
|
1996
|
+
{item.contact} · {formatPhone(item.phone)}
|
|
1997
|
+
</div>
|
|
1998
|
+
<Flex
|
|
1999
|
+
justify="space-between"
|
|
2000
|
+
align="center"
|
|
2001
|
+
gap={12}
|
|
2002
|
+
style={{
|
|
2003
|
+
marginTop: 14,
|
|
2004
|
+
paddingTop: 12,
|
|
2005
|
+
borderTop: '1px solid #f0f0f0'
|
|
2006
|
+
}}
|
|
2007
|
+
>
|
|
2008
|
+
<Flex align="baseline" gap={6} style={{ flex: 1, minWidth: 0 }}>
|
|
2009
|
+
<span style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)', flexShrink: 0 }}>订单金额</span>
|
|
2010
|
+
<span style={{ fontSize: 16, fontWeight: 600, color: '#1677ff' }}>¥{item.amount.toLocaleString()}</span>
|
|
2011
|
+
</Flex>
|
|
2012
|
+
<Flex gap={4} align="center" style={{ flexShrink: 0 }}>
|
|
2013
|
+
{actionItems.slice(0, 2).map(({ key, label, onClick }) => (
|
|
2014
|
+
<Button
|
|
2015
|
+
key={key}
|
|
2016
|
+
type="link"
|
|
2017
|
+
size="small"
|
|
2018
|
+
style={{ padding: '0 4px', height: 'auto' }}
|
|
2019
|
+
onClick={e => {
|
|
2020
|
+
e.stopPropagation();
|
|
2021
|
+
onClick();
|
|
2022
|
+
}}
|
|
2023
|
+
>
|
|
2024
|
+
{label}
|
|
2025
|
+
</Button>
|
|
2026
|
+
))}
|
|
2027
|
+
</Flex>
|
|
2028
|
+
</Flex>
|
|
2029
|
+
</div>
|
|
2030
|
+
</div>
|
|
2031
|
+
);
|
|
2032
|
+
};
|
|
2033
|
+
|
|
2034
|
+
const DefaultMobileCards = ({ Component }) => {
|
|
2035
|
+
const [selectKeys, setSelectKeys] = useState([]);
|
|
2036
|
+
const totalAmount = selectKeys.reduce((sum, id) => sum + (dataSource.find(d => d.id === id)?.amount || 0), 0);
|
|
2037
|
+
return (
|
|
2038
|
+
<div>
|
|
2039
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2040
|
+
<code>renderMobile={'{true}'}</code>:移动端启用默认卡片 List,不再渲染 antd Table;
|
|
2041
|
+
开启 <code>allowSelectedAll</code> 后顶部工具栏左侧显示全选。请用示例预览的手机模式查看效果。
|
|
2042
|
+
</div>
|
|
2043
|
+
<Flex justify="space-between" align="center" style={{ marginBottom: 12 }}>
|
|
2044
|
+
<span>
|
|
2045
|
+
已选 <strong>{selectKeys.length}</strong> 个订单,总金额 <strong style={{ color: '#52c41a' }}>¥{totalAmount.toLocaleString()}</strong>
|
|
2046
|
+
</span>
|
|
2047
|
+
</Flex>
|
|
2048
|
+
<Component
|
|
2049
|
+
dataSource={dataSource}
|
|
2050
|
+
columns={columns}
|
|
2051
|
+
size="large"
|
|
2052
|
+
controllerOpen={false}
|
|
2053
|
+
renderMobile
|
|
2054
|
+
rowSelection={{
|
|
2055
|
+
type: 'checkbox',
|
|
2056
|
+
allowSelectedAll: true,
|
|
2057
|
+
selectedRowKeys: selectKeys,
|
|
2058
|
+
onChange: keys => setSelectKeys(keys)
|
|
2059
|
+
}}
|
|
2060
|
+
/>
|
|
2061
|
+
</div>
|
|
2062
|
+
);
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
const SortState = ({ sort }) => (
|
|
2066
|
+
<div style={{ marginBottom: 12, padding: '10px 12px', background: '#f5f5f5', borderRadius: 8, fontSize: 13 }}>
|
|
2067
|
+
当前排序:
|
|
2068
|
+
{sort.length ? (
|
|
2069
|
+
<span>
|
|
2070
|
+
{sort.map(item => (
|
|
2071
|
+
<Tag key={item.name} color="blue" style={{ marginLeft: 8 }}>
|
|
2072
|
+
{item.name} {item.sort}
|
|
2073
|
+
</Tag>
|
|
2074
|
+
))}
|
|
2075
|
+
</span>
|
|
2076
|
+
) : (
|
|
2077
|
+
<span style={{ marginLeft: 8, color: '#999' }}>无</span>
|
|
2078
|
+
)}
|
|
2079
|
+
</div>
|
|
2080
|
+
);
|
|
2081
|
+
|
|
2082
|
+
const MobileSortWithSelectAll = ({ Component }) => {
|
|
2083
|
+
const [selectKeys, setSelectKeys] = useState([]);
|
|
2084
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({});
|
|
2085
|
+
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort]);
|
|
2086
|
+
|
|
2087
|
+
return (
|
|
2088
|
+
<Component
|
|
2089
|
+
dataSource={sortedData}
|
|
2090
|
+
columns={columns}
|
|
2091
|
+
size="large"
|
|
2092
|
+
controllerOpen={false}
|
|
2093
|
+
renderMobile
|
|
2094
|
+
sortRender={sortRender}
|
|
2095
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
2096
|
+
rowSelection={{
|
|
2097
|
+
type: 'checkbox',
|
|
2098
|
+
allowSelectedAll: true,
|
|
2099
|
+
selectedRowKeys: selectKeys,
|
|
2100
|
+
onChange: keys => setSelectKeys(keys)
|
|
2101
|
+
}}
|
|
2102
|
+
/>
|
|
2103
|
+
);
|
|
2104
|
+
};
|
|
2105
|
+
|
|
2106
|
+
const MobileSortExample = ({ Component }) => {
|
|
2107
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({
|
|
2108
|
+
defaultSort: [{ name: 'amount', sort: 'DESC' }],
|
|
2109
|
+
onSortChange: value => console.log('移动端排序变更:', value)
|
|
2110
|
+
});
|
|
2111
|
+
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort]);
|
|
2112
|
+
|
|
2113
|
+
return (
|
|
2114
|
+
<Flex vertical gap={24}>
|
|
2115
|
+
<div>
|
|
2116
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2117
|
+
移动端排序:列配置 <code>sort: true</code>,配合 <code>Table.useSort</code> 传入 <code>mobileSortToolbar</code>。
|
|
2118
|
+
工具栏居右,可选择排序列并切换升序 / 降序;再次点击当前方向或下拉选「取消排序」可清除。数据需自行用 <code>sortDataSource</code> 排序。
|
|
2119
|
+
</div>
|
|
2120
|
+
<SortState sort={sort} />
|
|
2121
|
+
<Component
|
|
2122
|
+
dataSource={sortedData}
|
|
2123
|
+
columns={columns}
|
|
2124
|
+
size="large"
|
|
2125
|
+
controllerOpen={false}
|
|
2126
|
+
renderMobile
|
|
2127
|
+
sortRender={sortRender}
|
|
2128
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
2129
|
+
/>
|
|
2130
|
+
</div>
|
|
2131
|
+
<div>
|
|
2132
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2133
|
+
排序与全选同时开启:工具栏左侧全选、右侧排序。
|
|
2134
|
+
</div>
|
|
2135
|
+
<MobileSortWithSelectAll Component={Component} />
|
|
2136
|
+
</div>
|
|
2137
|
+
</Flex>
|
|
2138
|
+
);
|
|
2139
|
+
};
|
|
2140
|
+
|
|
2141
|
+
const CustomMobileRender = ({ Component }) => {
|
|
2142
|
+
const [selectKeys, setSelectKeys] = useState([]);
|
|
2143
|
+
const [isSelectedAll, setIsSelectedAll] = useState(false);
|
|
2144
|
+
const totalAmount = dataSource.reduce((sum, item) => sum + item.amount, 0);
|
|
2145
|
+
const selectedAmount = selectKeys.reduce((sum, id) => sum + (dataSource.find(d => d.id === id)?.amount || 0), 0);
|
|
2146
|
+
const checkedAll = isSelectedAll || (dataSource.length > 0 && selectKeys.length === dataSource.length);
|
|
2147
|
+
const indeterminate = selectKeys.length > 0 && !checkedAll;
|
|
2148
|
+
|
|
2149
|
+
const handleSelectAllChange = e => {
|
|
2150
|
+
const checked = e.target.checked;
|
|
2151
|
+
if (!checked) {
|
|
2152
|
+
setIsSelectedAll(false);
|
|
2153
|
+
setSelectKeys([]);
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
setIsSelectedAll(true);
|
|
2157
|
+
setSelectKeys(dataSource.map(item => item.id));
|
|
2158
|
+
};
|
|
2159
|
+
|
|
2160
|
+
const handleCardCheckChange = (id, checked) => {
|
|
2161
|
+
setIsSelectedAll(false);
|
|
2162
|
+
setSelectKeys(keys => (checked ? keys.filter(key => key !== id) : [...keys, id]));
|
|
2163
|
+
};
|
|
2164
|
+
|
|
2165
|
+
return (
|
|
2166
|
+
<div>
|
|
2167
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2168
|
+
<code>renderMobile</code> 为 function 时完全接管渲染,可自定义主次关系卡片:客户名称作主信息,状态/编号/联系人作次要信息。
|
|
2169
|
+
桌面端仍走 <code>render</code>,样式与普通 Table 一致。
|
|
2170
|
+
</div>
|
|
2171
|
+
<Flex justify="space-between" align="center" style={{ marginBottom: 12 }}>
|
|
2172
|
+
<span>
|
|
2173
|
+
已选 <strong>{selectKeys.length}</strong> 个订单,金额 <strong style={{ color: '#52c41a' }}>¥{selectedAmount.toLocaleString()}</strong>
|
|
2174
|
+
</span>
|
|
2175
|
+
</Flex>
|
|
2176
|
+
<Card size="small" title="近期订单" extra={<Tag>桌面 render</Tag>} styles={{ body: { padding: 0 } }}>
|
|
2177
|
+
<Flex
|
|
2178
|
+
justify="space-between"
|
|
2179
|
+
align="center"
|
|
2180
|
+
style={{ padding: '12px 16px', background: '#fafafa', borderBottom: '1px solid #f0f0f0' }}
|
|
2181
|
+
>
|
|
2182
|
+
<Flex gap={8} align="center">
|
|
2183
|
+
<Tag color="blue">{dataSource.length} 笔</Tag>
|
|
2184
|
+
<span style={{ color: 'rgba(0,0,0,0.65)', fontSize: 13 }}>
|
|
2185
|
+
合计 <strong style={{ color: '#52c41a' }}>¥{totalAmount.toLocaleString()}</strong>
|
|
2186
|
+
</span>
|
|
2187
|
+
</Flex>
|
|
2188
|
+
<span style={{ color: 'rgba(0,0,0,0.45)', fontSize: 12 }}>桌面端 render 自定义外层</span>
|
|
2189
|
+
</Flex>
|
|
2190
|
+
<Component
|
|
2191
|
+
dataSource={dataSource}
|
|
2192
|
+
columns={columns}
|
|
2193
|
+
controllerOpen={false}
|
|
2194
|
+
render={({ renderBody }) => <div style={{ overflowX: 'auto' }}>{renderBody()}</div>}
|
|
2195
|
+
renderMobile={() => (
|
|
2196
|
+
<div
|
|
2197
|
+
style={{
|
|
2198
|
+
borderRadius: 12,
|
|
2199
|
+
background: '#f5f7fa',
|
|
2200
|
+
padding: 16
|
|
2201
|
+
}}
|
|
2202
|
+
>
|
|
2203
|
+
<div style={{ marginBottom: 16 }}>
|
|
2204
|
+
<Flex justify="space-between" align="center" gap={8} style={{ marginBottom: 4 }}>
|
|
2205
|
+
<div style={{ fontSize: 17, fontWeight: 600, color: 'rgba(0,0,0,0.88)' }}>近期订单</div>
|
|
2206
|
+
<Tag color="processing" style={{ margin: 0, flexShrink: 0 }}>
|
|
2207
|
+
renderMobile
|
|
2208
|
+
</Tag>
|
|
2209
|
+
</Flex>
|
|
2210
|
+
<div style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>
|
|
2211
|
+
{dataSource.length} 笔 · 合计 ¥{totalAmount.toLocaleString()}
|
|
2212
|
+
</div>
|
|
2213
|
+
</div>
|
|
2214
|
+
<div
|
|
2215
|
+
style={{
|
|
2216
|
+
display: 'flex',
|
|
2217
|
+
alignItems: 'center',
|
|
2218
|
+
gap: 6,
|
|
2219
|
+
marginBottom: 12,
|
|
2220
|
+
padding: '4px 8px',
|
|
2221
|
+
background: 'var(--bg-color-grey-1, #fafafa)',
|
|
2222
|
+
borderRadius: 8,
|
|
2223
|
+
fontSize: 12
|
|
2224
|
+
}}
|
|
2225
|
+
>
|
|
2226
|
+
<Checkbox checked={checkedAll} indeterminate={indeterminate} onChange={handleSelectAllChange} />
|
|
2227
|
+
<span>全选</span>
|
|
2228
|
+
</div>
|
|
2229
|
+
<Flex vertical gap={12}>
|
|
2230
|
+
{dataSource.map(item => {
|
|
2231
|
+
const isChecked = selectKeys.indexOf(item.id) > -1;
|
|
2232
|
+
return (
|
|
2233
|
+
<OrderMobileCard
|
|
2234
|
+
key={item.id}
|
|
2235
|
+
item={item}
|
|
2236
|
+
checked={(isSelectedAll && !item.disabled) || isChecked}
|
|
2237
|
+
disabled={isSelectedAll}
|
|
2238
|
+
onCheckChange={() => handleCardCheckChange(item.id, isChecked)}
|
|
2239
|
+
/>
|
|
2240
|
+
);
|
|
2241
|
+
})}
|
|
2242
|
+
</Flex>
|
|
2243
|
+
</div>
|
|
2244
|
+
)}
|
|
2245
|
+
/>
|
|
2246
|
+
</Card>
|
|
2247
|
+
</div>
|
|
2248
|
+
);
|
|
2249
|
+
};
|
|
2250
|
+
|
|
2251
|
+
const PresetStringRender = ({ Component }) => {
|
|
2252
|
+
const [selectKeys, setSelectKeys] = useState([]);
|
|
2253
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({
|
|
2254
|
+
defaultSort: [{ name: 'amount', sort: 'DESC' }]
|
|
2255
|
+
});
|
|
2256
|
+
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort]);
|
|
2257
|
+
|
|
2258
|
+
return (
|
|
2259
|
+
<Flex vertical gap={24}>
|
|
2260
|
+
<div>
|
|
2261
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2262
|
+
<code>renderMobile="orderCard"</code>:通过 <code>preset({'{ renderMobile }'})</code> 注册名称对应的渲染函数;
|
|
2263
|
+
仅移动端生效,支持全选与选中样式。可配合 <code>mobileSortToolbar</code> 开启排序。
|
|
2264
|
+
</div>
|
|
2265
|
+
<Component
|
|
2266
|
+
dataSource={sortedData}
|
|
2267
|
+
columns={columns}
|
|
2268
|
+
controllerOpen={false}
|
|
2269
|
+
size="large"
|
|
2270
|
+
renderMobile="orderCard"
|
|
2271
|
+
sortRender={sortRender}
|
|
2272
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
2273
|
+
rowSelection={{
|
|
2274
|
+
type: 'checkbox',
|
|
2275
|
+
allowSelectedAll: true,
|
|
2276
|
+
selectedRowKeys: selectKeys,
|
|
2277
|
+
onChange: keys => setSelectKeys(keys)
|
|
2278
|
+
}}
|
|
2279
|
+
/>
|
|
2280
|
+
</div>
|
|
2281
|
+
<div>
|
|
2282
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2283
|
+
<code>renderMobile="notRegistered"</code>:preset 中未注册时视为未开启,移动端仍显示普通表格。
|
|
2284
|
+
</div>
|
|
2285
|
+
<Component dataSource={dataSource} columns={columns} controllerOpen={false} renderMobile="notRegistered" />
|
|
2286
|
+
</div>
|
|
2287
|
+
</Flex>
|
|
2288
|
+
);
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
const Examples = ({ Component }) => (
|
|
2292
|
+
<Flex vertical gap={32}>
|
|
2293
|
+
<DefaultMobileCards Component={Component} />
|
|
2294
|
+
<MobileSortExample Component={Component} />
|
|
2295
|
+
<CustomMobileRender Component={Component} />
|
|
2296
|
+
<PresetStringRender Component={Component} />
|
|
2297
|
+
</Flex>
|
|
2298
|
+
);
|
|
2299
|
+
|
|
2300
|
+
const BaseExample = () => {
|
|
2301
|
+
return (
|
|
2302
|
+
<Tabs
|
|
2303
|
+
items={[
|
|
2304
|
+
{ key: 'table', label: 'Table', children: <Examples Component={Table} /> },
|
|
2305
|
+
{ key: 'table-view', label: 'TableView', children: <Examples Component={TableView} /> }
|
|
2306
|
+
]}
|
|
2307
|
+
/>
|
|
2308
|
+
);
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2311
|
+
render(<BaseExample />);
|
|
2312
|
+
|
|
2313
|
+
```
|
|
2314
|
+
|
|
1631
2315
|
- column config
|
|
1632
2316
|
- 列宽拖动调整、显示/隐藏字段、列排序与 localStorage 持久化(仅 Table)
|
|
1633
2317
|
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd)
|
|
@@ -1966,6 +2650,144 @@ render(<BaseExample />);
|
|
|
1966
2650
|
|
|
1967
2651
|
```
|
|
1968
2652
|
|
|
2653
|
+
- size
|
|
2654
|
+
- 单元格 padding 尺寸:默认 8px,small 为 4px,large 为 14px 8px;Table / TableView 均支持,可用 CSS 变量 --kne-table-cell-padding-* 覆盖
|
|
2655
|
+
- _TablePage(@kne/current-lib_table-page)[import * as _TablePage from "@kne/table-page"],(@kne/current-lib_table-page/dist/index.css),antd(antd)
|
|
2656
|
+
|
|
2657
|
+
```jsx
|
|
2658
|
+
const { Table, TableView } = _TablePage;
|
|
2659
|
+
const { Flex, Radio, Tabs } = antd;
|
|
2660
|
+
const { useState } = React;
|
|
2661
|
+
|
|
2662
|
+
const dataSource = [
|
|
2663
|
+
{
|
|
2664
|
+
id: 'ORD001',
|
|
2665
|
+
customerName: '深圳市腾讯计算机系统有限公司',
|
|
2666
|
+
contact: '张三',
|
|
2667
|
+
amount: 42500,
|
|
2668
|
+
status: '已完成'
|
|
2669
|
+
},
|
|
2670
|
+
{
|
|
2671
|
+
id: 'ORD002',
|
|
2672
|
+
customerName: '华为技术有限公司',
|
|
2673
|
+
contact: '李四',
|
|
2674
|
+
amount: 85000,
|
|
2675
|
+
status: '处理中'
|
|
2676
|
+
},
|
|
2677
|
+
{
|
|
2678
|
+
id: 'ORD003',
|
|
2679
|
+
customerName: '阿里巴巴集团控股有限公司',
|
|
2680
|
+
contact: '王五',
|
|
2681
|
+
amount: 120000,
|
|
2682
|
+
status: '待发货'
|
|
2683
|
+
}
|
|
2684
|
+
];
|
|
2685
|
+
|
|
2686
|
+
const columns = [
|
|
2687
|
+
{ name: 'id', title: '订单编号', width: 120, renderType: 'small' },
|
|
2688
|
+
{ name: 'customerName', title: '客户名称', width: 220, renderType: 'main' },
|
|
2689
|
+
{ name: 'contact', title: '联系人', width: 80 },
|
|
2690
|
+
{
|
|
2691
|
+
name: 'amount',
|
|
2692
|
+
title: '订单金额',
|
|
2693
|
+
width: 120,
|
|
2694
|
+
renderType: 'amount',
|
|
2695
|
+
format: 'number-style:decimal-maximumFractionDigits:0-useGrouping:true-suffix:元'
|
|
2696
|
+
},
|
|
2697
|
+
{ name: 'status', title: '状态', width: 100 }
|
|
2698
|
+
];
|
|
2699
|
+
|
|
2700
|
+
const SizeDemo = ({ Component, title, description, size }) => (
|
|
2701
|
+
<div>
|
|
2702
|
+
<div style={{ marginBottom: 8 }}>
|
|
2703
|
+
<strong>{title}</strong>
|
|
2704
|
+
<span style={{ marginLeft: 8, color: '#666', fontSize: 13 }}>{description}</span>
|
|
2705
|
+
</div>
|
|
2706
|
+
<Component dataSource={dataSource} columns={columns} size={size} controllerOpen={false} />
|
|
2707
|
+
</div>
|
|
2708
|
+
);
|
|
2709
|
+
|
|
2710
|
+
const InteractiveSize = ({ Component }) => {
|
|
2711
|
+
const [size, setSize] = useState('default');
|
|
2712
|
+
return (
|
|
2713
|
+
<div>
|
|
2714
|
+
<Flex align="center" gap={12} style={{ marginBottom: 12 }}>
|
|
2715
|
+
<strong>切换 size</strong>
|
|
2716
|
+
<Radio.Group
|
|
2717
|
+
optionType="button"
|
|
2718
|
+
value={size}
|
|
2719
|
+
onChange={e => setSize(e.target.value)}
|
|
2720
|
+
options={[
|
|
2721
|
+
{ label: 'default (8px)', value: 'default' },
|
|
2722
|
+
{ label: 'small (4px)', value: 'small' },
|
|
2723
|
+
{ label: 'large (14px 8px)', value: 'large' }
|
|
2724
|
+
]}
|
|
2725
|
+
/>
|
|
2726
|
+
</Flex>
|
|
2727
|
+
<Component dataSource={dataSource} columns={columns} size={size === 'default' ? undefined : size} controllerOpen={false} />
|
|
2728
|
+
</div>
|
|
2729
|
+
);
|
|
2730
|
+
};
|
|
2731
|
+
|
|
2732
|
+
const SizeExamples = ({ Component }) => (
|
|
2733
|
+
<Flex vertical gap={24}>
|
|
2734
|
+
<InteractiveSize Component={Component} />
|
|
2735
|
+
<SizeDemo Component={Component} title="default" description="padding: 8px" />
|
|
2736
|
+
<SizeDemo Component={Component} title='size="small"' description="padding: 4px" size="small" />
|
|
2737
|
+
<SizeDemo Component={Component} title='size="large"' description="padding: 14px 8px" size="large" />
|
|
2738
|
+
<div>
|
|
2739
|
+
<div style={{ marginBottom: 8 }}>
|
|
2740
|
+
<strong>CSS 变量覆盖</strong>
|
|
2741
|
+
<span style={{ marginLeft: 8, color: '#666', fontSize: 13 }}>
|
|
2742
|
+
--kne-table-cell-padding-default: 12px 16px
|
|
2743
|
+
</span>
|
|
2744
|
+
</div>
|
|
2745
|
+
<div style={{ '--kne-table-cell-padding-default': '12px 16px' }}>
|
|
2746
|
+
<Component dataSource={dataSource} columns={columns} controllerOpen={false} />
|
|
2747
|
+
</div>
|
|
2748
|
+
</div>
|
|
2749
|
+
</Flex>
|
|
2750
|
+
);
|
|
2751
|
+
|
|
2752
|
+
const BaseExample = () => {
|
|
2753
|
+
return (
|
|
2754
|
+
<Flex vertical gap={16}>
|
|
2755
|
+
<div style={{ background: '#f5f5f5', padding: '12px', borderRadius: 8, fontSize: 13 }}>
|
|
2756
|
+
<div>
|
|
2757
|
+
<code>size</code> 控制单元格 padding:默认 <code>8px</code>,<code>small</code> 为 <code>4px</code>,
|
|
2758
|
+
<code>large</code> 为 <code>14px 8px</code>
|
|
2759
|
+
</div>
|
|
2760
|
+
<div style={{ marginTop: 4, color: '#666' }}>
|
|
2761
|
+
可通过 CSS 变量覆盖:
|
|
2762
|
+
<code>--kne-table-cell-padding-default</code> /
|
|
2763
|
+
<code>--kne-table-cell-padding-small</code> /
|
|
2764
|
+
<code>--kne-table-cell-padding-large</code>,或直接设
|
|
2765
|
+
<code>--kne-table-cell-padding</code>
|
|
2766
|
+
</div>
|
|
2767
|
+
</div>
|
|
2768
|
+
|
|
2769
|
+
<Tabs
|
|
2770
|
+
items={[
|
|
2771
|
+
{
|
|
2772
|
+
key: 'table',
|
|
2773
|
+
label: 'Table',
|
|
2774
|
+
children: <SizeExamples Component={Table} />
|
|
2775
|
+
},
|
|
2776
|
+
{
|
|
2777
|
+
key: 'tableView',
|
|
2778
|
+
label: 'TableView',
|
|
2779
|
+
children: <SizeExamples Component={TableView} />
|
|
2780
|
+
}
|
|
2781
|
+
]}
|
|
2782
|
+
/>
|
|
2783
|
+
</Flex>
|
|
2784
|
+
);
|
|
2785
|
+
};
|
|
2786
|
+
|
|
2787
|
+
render(<BaseExample />);
|
|
2788
|
+
|
|
2789
|
+
```
|
|
2790
|
+
|
|
1969
2791
|
### API
|
|
1970
2792
|
|
|
1971
2793
|
### TablePage
|
|
@@ -1993,11 +2815,13 @@ render(<BaseExample />);
|
|
|
1993
2815
|
| columnRenderProps | object | `{}` | 列渲染扩展属性,会合并进列 `render` 的 context |
|
|
1994
2816
|
| filter | object | - | 顶部筛选器配置,基于 `@kne/react-filter` 的 `FilterLines`,见下方 |
|
|
1995
2817
|
| search | object | - | 顶部搜索框配置,基于 `@kne/react-filter` 的 `SearchInput`,见下方 |
|
|
2818
|
+
| tab | object | - | 顶部 Tab 分类切换,选中值写入 filter value,见下方 |
|
|
2819
|
+
| tabProps | object | - | 透传给 antd `Tabs` 的额外属性(如 `tabBarExtraContent`) |
|
|
1996
2820
|
| batchActions | array | - | 批量操作下拉菜单项,需配合 `rowSelection` 使用,见下方 |
|
|
1997
2821
|
| selectedRows | array | - | 已选行数据,传给 `batchActions` 的 `onClick` 上下文 |
|
|
1998
2822
|
| className | string | - | 自定义类名 |
|
|
1999
2823
|
| ...fetchProps | - | - | 其余属性透传给 `@kne/react-fetch`(如 `url`、`params`、`auto` 等) |
|
|
2000
|
-
| ...tableProps | - | - | 其余属性透传给内部 `Table`(如 `rowKey`、`rowSelection`、`scroll`) |
|
|
2824
|
+
| ...tableProps | - | - | 其余属性透传给内部 `Table` / `TableView`(如 `rowKey`、`rowSelection`、`scroll`、`size`、`renderMobile`、`sortRender`、`mobileSortToolbar`) |
|
|
2001
2825
|
|
|
2002
2826
|
#### pagination
|
|
2003
2827
|
|
|
@@ -2041,6 +2865,39 @@ render(<BaseExample />);
|
|
|
2041
2865
|
| placeholder | string | - | 占位符 |
|
|
2042
2866
|
| searchDelay | number | `500` | 自动提交防抖时间(毫秒) |
|
|
2043
2867
|
|
|
2868
|
+
#### tab
|
|
2869
|
+
|
|
2870
|
+
顶部 Tab 分类切换。默认选中「全部」(不写入筛选值);切换到具体项时,将 `{ name, label, value: { value, label } }` 写入 filter value,并触发 `reload` 回到第 1 页。桌面端显示在表格边框外侧上方;移动端(含 `renderMobile`)显示在 `SearchInput` 下方。选中值会出现在已选筛选标签中,清除标签会回到「全部」。
|
|
2871
|
+
|
|
2872
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
2873
|
+
|------|------|--------|------|
|
|
2874
|
+
| name | string | - | 必填,写入筛选值的字段名 |
|
|
2875
|
+
| label | string | - | 筛选字段标签 |
|
|
2876
|
+
| list | `Array<{ label, value }>` | - | Tab 选项列表 |
|
|
2877
|
+
|
|
2878
|
+
#### tabProps
|
|
2879
|
+
|
|
2880
|
+
透传给 antd `Tabs` 的额外属性。内部会覆盖 `activeKey`、`onChange`、`items`,其余如 `tabBarExtraContent`、`type` 等可自由传入。
|
|
2881
|
+
|
|
2882
|
+
```jsx
|
|
2883
|
+
<TablePage
|
|
2884
|
+
tab={{
|
|
2885
|
+
name: 'position',
|
|
2886
|
+
label: '职位',
|
|
2887
|
+
list: [
|
|
2888
|
+
{ label: '工程师', value: '工程师' },
|
|
2889
|
+
{ label: '经理', value: '经理' }
|
|
2890
|
+
]
|
|
2891
|
+
}}
|
|
2892
|
+
tabProps={{
|
|
2893
|
+
tabBarExtraContent: <Button type="link">新增职位</Button>
|
|
2894
|
+
}}
|
|
2895
|
+
search={{ name: 'keyword', label: '关键词' }}
|
|
2896
|
+
loader={...}
|
|
2897
|
+
columns={...}
|
|
2898
|
+
/>
|
|
2899
|
+
```
|
|
2900
|
+
|
|
2044
2901
|
#### batchActions
|
|
2045
2902
|
|
|
2046
2903
|
批量操作下拉菜单,需配合 `rowSelection`(通常来自 `Table.useSelectedRow`)使用。
|
|
@@ -2120,7 +2977,21 @@ render(<BaseExample />);
|
|
|
2120
2977
|
| headerStyle | object | - | 表头自定义样式,仅在 `render` 自定义渲染时作用于 `header` |
|
|
2121
2978
|
| onRowSelect | function | - | 行点击回调 `(item, { columns, dataSource }) => void` |
|
|
2122
2979
|
| render | function | - | 自定义渲染 `(props) => ReactNode`,可获取 `header` 和 `renderBody` |
|
|
2123
|
-
|
|
|
2980
|
+
| renderMobile | boolean \| function \| string | - | 仅移动端生效。`true` 使用默认卡片 List(不再渲染 antd Table);为 function 时签名与 `render` 一致,且优先级高于 `render`,完全接管渲染;为 string 时从 `preset({ renderMobile })` 按名称取渲染函数,未注册则视为未开启 |
|
|
2981
|
+
| sortRender | function | - | 排序按钮渲染,由 `useSort` 提供(桌面端表头) |
|
|
2982
|
+
| mobileSortToolbar | function | - | 移动端排序工具栏,由 `useSort` 提供 |
|
|
2983
|
+
| size | `'small'` \| `'large'` | - | 单元格内边距:默认 `8px`,`small` 为 `4px`,`large` 为 `14px 8px`;可通过 CSS 变量覆盖 |
|
|
2984
|
+
|
|
2985
|
+
单元格 padding 由 CSS 变量控制,可在外层覆盖:
|
|
2986
|
+
|
|
2987
|
+
```css
|
|
2988
|
+
.info-page-table {
|
|
2989
|
+
--kne-table-cell-padding-default: 8px;
|
|
2990
|
+
--kne-table-cell-padding-small: 4px;
|
|
2991
|
+
--kne-table-cell-padding-large: 14px 8px;
|
|
2992
|
+
/* 或直接覆盖当前生效值:--kne-table-cell-padding: 10px; */
|
|
2993
|
+
}
|
|
2994
|
+
```
|
|
2124
2995
|
|
|
2125
2996
|
#### columns
|
|
2126
2997
|
|
|
@@ -2133,7 +3004,8 @@ render(<BaseExample />);
|
|
|
2133
3004
|
| align | string | `'top'` | 垂直对齐方式 |
|
|
2134
3005
|
| justify | string | `'flex-start'` | 水平对齐方式 |
|
|
2135
3006
|
| format | string \| function | - | 值格式化 |
|
|
2136
|
-
| render | function | - | 自定义单元格渲染 `(value, { column, dataSource, context }) => ReactNode` |
|
|
3007
|
+
| render | function | - | 自定义单元格渲染 `(value, { column, dataSource, context }) => ReactNode`;与 `renderType` 同时存在时优先级最高 |
|
|
3008
|
+
| renderType | string | - | 声明式列渲染类型;存在 `render` 时仅保留列宽等维度,不参与单元格渲染 |
|
|
2137
3009
|
| sort | boolean \| object | - | 是否支持排序,`{ single: true }` 为单列排序 |
|
|
2138
3010
|
| ellipsis | boolean \| object | `false` | 超出省略,基于 antd Typography;`true` 开启省略与 tooltip,`{ showTitle: false }` 关闭 tooltip |
|
|
2139
3011
|
| display | boolean \| function | - | 是否显示该列 |
|
|
@@ -2206,7 +3078,8 @@ const { selectedRowKeys, getRowSelection, clearSelectedRows } = Table.useSelecte
|
|
|
2206
3078
|
|------|------|------|
|
|
2207
3079
|
| sort | array | 当前排序配置 |
|
|
2208
3080
|
| setSort | function | 设置排序 |
|
|
2209
|
-
| sortRender | function | `({ name, single }) => ReactNode`,传给 Table / TableView |
|
|
3081
|
+
| sortRender | function | `({ name, single }) => ReactNode`,传给 Table / TableView 表头 |
|
|
3082
|
+
| mobileSortToolbar | function | `({ columns }) => ReactNode`,传给 Table / TableView 移动端工具栏右侧 |
|
|
2210
3083
|
|
|
2211
3084
|
#### columns.sort
|
|
2212
3085
|
|
|
@@ -2223,15 +3096,15 @@ const { selectedRowKeys, getRowSelection, clearSelectedRows } = Table.useSelecte
|
|
|
2223
3096
|
#### 示例
|
|
2224
3097
|
|
|
2225
3098
|
```jsx
|
|
2226
|
-
const { sort, sortRender } = Table.useSort({ onSortChange: console.log });
|
|
3099
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({ onSortChange: console.log });
|
|
2227
3100
|
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort, dataSource]);
|
|
2228
3101
|
|
|
2229
|
-
<Table dataSource={sortedData} columns={columns} sortRender={sortRender} />;
|
|
3102
|
+
<Table dataSource={sortedData} columns={columns} sortRender={sortRender} mobileSortToolbar={mobileSortToolbar} />;
|
|
2230
3103
|
```
|
|
2231
3104
|
|
|
2232
3105
|
### Table
|
|
2233
3106
|
|
|
2234
|
-
表格组件,以 antd `Table` 作为展示层,外层 API 与 `TableView` 保持一致,可直接复用相同的 `columns`、`rowSelection` 等配置。此外支持透传 antd Table 的原生属性(如 `scroll`、`pagination`、`
|
|
3107
|
+
表格组件,以 antd `Table` 作为展示层,外层 API 与 `TableView` 保持一致,可直接复用相同的 `columns`、`rowSelection` 等配置。此外支持透传 antd Table 的原生属性(如 `scroll`、`pagination`、`bordered` 等)。
|
|
2235
3108
|
|
|
2236
3109
|
#### 属性
|
|
2237
3110
|
|
|
@@ -2251,11 +3124,14 @@ const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns)
|
|
|
2251
3124
|
| headerStyle | object | - | 表头自定义样式 |
|
|
2252
3125
|
| onRowSelect | function | - | 行点击回调 `(item, { columns, dataSource }) => void` |
|
|
2253
3126
|
| render | function | - | 自定义渲染 `(props) => ReactNode`,`header` 为 `null`,`renderBody` 返回 antd Table |
|
|
2254
|
-
|
|
|
3127
|
+
| renderMobile | boolean \| function \| string | - | 仅移动端生效。`true` 使用默认卡片 List(不再渲染 antd Table);为 function 时签名与 `render` 一致,且优先级高于 `render`,完全接管渲染;为 string 时从 `preset({ renderMobile })` 按名称取渲染函数,未注册则视为未开启 |
|
|
3128
|
+
| sortRender | function | - | 排序按钮渲染,由 `useSort` 提供(桌面端表头) |
|
|
3129
|
+
| mobileSortToolbar | function | - | 移动端排序工具栏,由 `useSort` 提供 |
|
|
2255
3130
|
| pagination | boolean \| object | `false` | 分页配置,默认不显示;传入对象时使用 antd 分页 |
|
|
2256
3131
|
| name | string | - | 表格唯一标识,用于持久化列配置 |
|
|
2257
3132
|
| controllerOpen | boolean | `true` | 是否开启列宽拖动与列配置面板 |
|
|
2258
3133
|
| tableServerApis | object | - | 自定义列配置存储 API,默认使用 `localStorage` |
|
|
3134
|
+
| size | `'small'` \| `'large'` | - | 单元格内边距:默认 `8px`,`small` 为 `4px`,`large` 为 `14px 8px`;可通过 CSS 变量覆盖(同 TableView) |
|
|
2259
3135
|
| ...antdTableProps | - | - | 其余属性透传给 antd `Table`(如 `scroll`、`bordered`) |
|
|
2260
3136
|
|
|
2261
3137
|
#### 与 TableView 的差异
|