@kne/table-page 0.1.11 → 0.1.13
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 +296 -60
- package/dist/index.css +78 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +176 -46
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +170 -50
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -28,7 +28,8 @@ npm i --save @kne/table-page
|
|
|
28
28
|
同时内置了顶部工具栏(`TableToolbar`),整合筛选、搜索、Tab 分类、批量操作等能力:
|
|
29
29
|
|
|
30
30
|
- **筛选(filter)**:基于 `@kne/react-filter` 的 `FilterLines`,支持多行多字段组合筛选,筛选值变化时自动 `reload` 并回到第 1 页
|
|
31
|
-
- **搜索(search)**:基于 `@kne/react-filter` 的 `SearchInput
|
|
31
|
+
- **搜索(search)**:基于 `@kne/react-filter` 的 `SearchInput`,支持关键词搜索与防抖自动提交,与筛选器共享筛选值状态;移动端开启 `renderMobile` 时,SearchInput 与下方卡片列表之间保留间距
|
|
32
|
+
- **操作按钮(buttonGroup)**:透传 `@kne/button-group` 参数;桌面端显示在 SearchInput 右侧(small、至少 1 个外露),移动端通过 `ButtonFooter` 居中固定在列表底部(正常尺寸、至少 2 个外露)
|
|
32
33
|
- **Tab(tab)**:顶部分类切换,默认「全部」,选中值写入 filter value 并显示在已选标签;桌面端在表格边框外侧,移动端显示在 SearchInput 下方;可通过 `tabProps` 透传 antd Tabs 属性
|
|
33
34
|
- **批量操作(batchActions)**:配合 `rowSelection` 和 `useSelectedRow`,提供下拉菜单形式的批量操作(如批量导出、批量通知),未选中时自动禁用
|
|
34
35
|
- **已选筛选值展示**:工具栏下方展示当前生效的筛选条件标签,支持快速清除
|
|
@@ -115,7 +116,7 @@ npm i --save @kne/table-page
|
|
|
115
116
|
| `renderMobile` 值 | 行为 |
|
|
116
117
|
|-------------------|------|
|
|
117
118
|
| `true` | 默认卡片 List:每行一张卡片,字段列「标题 + 内容」纵向排列,`options` 操作列靠右(紧凑「⋯」入口) |
|
|
118
|
-
| `function` |
|
|
119
|
+
| `function` | 完全接管移动端渲染;回调含 `renderToolbar` / `getSelectionProps` / `getRowKey` 等,见 TableView API |
|
|
119
120
|
| `string` | 从 `preset({ renderMobile: { [name]: fn } })` 查找;未注册则视为未开启,回退普通表格 |
|
|
120
121
|
|
|
121
122
|
桌面端不受 `renderMobile` 影响:`Table` 仍走 antd Table,`TableView` 仍走 CSS Grid 或 `render`。
|
|
@@ -184,7 +185,7 @@ npm i --save @kne/table-page
|
|
|
184
185
|
#### 示例代码
|
|
185
186
|
|
|
186
187
|
- TablePage
|
|
187
|
-
- 表格页面组件,基于 @kne/react-fetch 实现数据加载与分页,支持 sticky 固定表头、useSort 服务端排序、renderMobile 移动端卡片、tab 分类切换、列配置、总结栏;空数据(total 为 0
|
|
188
|
+
- 表格页面组件,基于 @kne/react-fetch 实现数据加载与分页,支持 sticky 固定表头、useSort 服务端排序、renderMobile 移动端卡片、tab 分类切换、列配置、总结栏;空数据(total 为 0)时不显示分页器。文末含仅 SearchInput + renderMobile 自定义卡片示例(验证工具栏与卡片间距)
|
|
188
189
|
- _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)
|
|
189
190
|
|
|
190
191
|
```jsx
|
|
@@ -385,7 +386,7 @@ const Tips = () => (
|
|
|
385
386
|
</div>
|
|
386
387
|
<div>
|
|
387
388
|
<Tag style={TIP_TAG_STYLE} color="gold">筛选</Tag>
|
|
388
|
-
顶部工具栏集成 <code>filter</code>、<code>search</code>、<code>batchActions</code>;筛选变化自动 <code>reload</code> 并回到第 1
|
|
389
|
+
顶部工具栏集成 <code>filter</code>、<code>search</code>、<code>batchActions</code>、<code>buttonGroup</code>;筛选变化自动 <code>reload</code> 并回到第 1 页;<code>buttonGroup</code> 桌面在 SearchInput 右侧,移动端经 ButtonFooter 固定在列表底部。
|
|
389
390
|
</div>
|
|
390
391
|
<div>
|
|
391
392
|
<Tag style={TIP_TAG_STYLE} color="lime">Tab</Tag>
|
|
@@ -401,7 +402,7 @@ const Tips = () => (
|
|
|
401
402
|
</div>
|
|
402
403
|
<div>
|
|
403
404
|
<Tag style={TIP_TAG_STYLE} color="volcano">移动端</Tag>
|
|
404
|
-
设置 <code>renderMobile</code> 后,手机预览下启用卡片 List(含全选、排序工具栏);桌面端仍为 antd Table
|
|
405
|
+
设置 <code>renderMobile</code> 后,手机预览下启用卡片 List(含全选、排序工具栏);桌面端仍为 antd Table。下方另有「仅 SearchInput + 自定义卡片」示例,用于确认 SearchInput 与卡片列表间距。
|
|
405
406
|
</div>
|
|
406
407
|
<div>
|
|
407
408
|
<Tag style={TIP_TAG_STYLE} color="geekblue">固定表头</Tag>
|
|
@@ -478,6 +479,19 @@ const BaseExample = () => {
|
|
|
478
479
|
rowSelection={getRowSelection(allEmployees)}
|
|
479
480
|
selectedRows={selectedRows}
|
|
480
481
|
search={{ name: 'keyword', label: '关键词', placeholder: '搜索工号/姓名', style: { width: 220 } }}
|
|
482
|
+
buttonGroup={{
|
|
483
|
+
list: [
|
|
484
|
+
{
|
|
485
|
+
type: 'primary',
|
|
486
|
+
children: '新建员工',
|
|
487
|
+
onClick: () => message.success('打开新建员工')
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
children: '导出全部',
|
|
491
|
+
onClick: () => message.info('正在导出全部员工')
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
}}
|
|
481
495
|
tab={{
|
|
482
496
|
name: 'position',
|
|
483
497
|
label: '职位',
|
|
@@ -579,8 +593,129 @@ const BaseExample = () => {
|
|
|
579
593
|
);
|
|
580
594
|
};
|
|
581
595
|
|
|
582
|
-
|
|
596
|
+
const sharedGroups = [
|
|
597
|
+
{
|
|
598
|
+
id: 1,
|
|
599
|
+
name: '华北销售共享组',
|
|
600
|
+
description: '覆盖华北区销售线索与客户跟进数据,成员可按只读或读写权限访问。',
|
|
601
|
+
members: [{ id: 'u1' }, { id: 'u2' }, { id: 'u3' }],
|
|
602
|
+
dataSources: [{ id: 'd1' }, { id: 'd2' }],
|
|
603
|
+
sharedModules: [{ id: 'm1' }]
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
id: 2,
|
|
607
|
+
name: '产品研发协作组',
|
|
608
|
+
description: '产品与研发跨部门协作,共享需求池与缺陷跟踪模块。',
|
|
609
|
+
members: [{ id: 'u4' }, { id: 'u5' }],
|
|
610
|
+
dataSources: [{ id: 'd3' }],
|
|
611
|
+
sharedModules: [{ id: 'm2' }, { id: 'm3' }]
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
id: 3,
|
|
615
|
+
name: '财务审计只读组',
|
|
616
|
+
description: '审计人员只读访问财务相关模块与导出记录。',
|
|
617
|
+
members: [{ id: 'u6' }],
|
|
618
|
+
dataSources: [{ id: 'd4' }, { id: 'd5' }, { id: 'd6' }],
|
|
619
|
+
sharedModules: [{ id: 'm4' }]
|
|
620
|
+
}
|
|
621
|
+
];
|
|
622
|
+
|
|
623
|
+
const sharedGroupColumns = [
|
|
624
|
+
{ name: 'id', title: 'ID', width: 80, renderType: 'small' },
|
|
625
|
+
{ name: 'name', title: '共享组名称', width: 180, renderType: 'main' },
|
|
626
|
+
{ name: 'description', title: '描述', width: 320, renderType: 'description', ellipsis: true },
|
|
627
|
+
{
|
|
628
|
+
name: 'options',
|
|
629
|
+
title: '操作',
|
|
630
|
+
width: 140,
|
|
631
|
+
renderType: 'options',
|
|
632
|
+
getValueOf: item => [
|
|
633
|
+
{ children: '编辑', type: 'link', onClick: () => console.log('edit', item.id) },
|
|
634
|
+
{ children: '删除', type: 'link', isDelete: true, message: `确定删除 ${item.name} 吗?`, onClick: () => console.log('remove', item.id) }
|
|
635
|
+
]
|
|
636
|
+
}
|
|
637
|
+
];
|
|
638
|
+
|
|
639
|
+
const SharedGroupMobileCard = ({ item }) => (
|
|
640
|
+
<div
|
|
641
|
+
style={{
|
|
642
|
+
display: 'flex',
|
|
643
|
+
flexDirection: 'column',
|
|
644
|
+
gap: 12,
|
|
645
|
+
padding: '14px 16px',
|
|
646
|
+
background: '#fff',
|
|
647
|
+
border: '1px solid #f0f0f0',
|
|
648
|
+
borderRadius: 12,
|
|
649
|
+
boxSizing: 'border-box'
|
|
650
|
+
}}
|
|
651
|
+
>
|
|
652
|
+
<div>
|
|
653
|
+
<div style={{ marginBottom: 8, fontSize: 16, fontWeight: 600, lineHeight: 1.4, color: 'rgba(0,0,0,0.88)' }}>
|
|
654
|
+
{item.name}
|
|
655
|
+
</div>
|
|
656
|
+
<Flex align="center" gap={8} wrap="wrap" style={{ marginBottom: 6, fontSize: 13, color: 'rgba(0,0,0,0.65)' }}>
|
|
657
|
+
<span>成员 {item.members.length}</span>
|
|
658
|
+
<span style={{ color: 'rgba(0,0,0,0.25)' }}>·</span>
|
|
659
|
+
<span>数据来源 {item.dataSources.length}</span>
|
|
660
|
+
<span style={{ color: 'rgba(0,0,0,0.25)' }}>·</span>
|
|
661
|
+
<span>模块 {item.sharedModules.length}</span>
|
|
662
|
+
<span style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>#{item.id}</span>
|
|
663
|
+
</Flex>
|
|
664
|
+
<div
|
|
665
|
+
style={{
|
|
666
|
+
display: '-webkit-box',
|
|
667
|
+
WebkitBoxOrient: 'vertical',
|
|
668
|
+
WebkitLineClamp: 2,
|
|
669
|
+
overflow: 'hidden',
|
|
670
|
+
fontSize: 13,
|
|
671
|
+
lineHeight: 1.5,
|
|
672
|
+
color: 'rgba(0,0,0,0.45)'
|
|
673
|
+
}}
|
|
674
|
+
>
|
|
675
|
+
{item.description}
|
|
676
|
+
</div>
|
|
677
|
+
</div>
|
|
678
|
+
</div>
|
|
679
|
+
);
|
|
583
680
|
|
|
681
|
+
/** 仅 SearchInput + renderMobile:确认工具栏与卡片列表有间距、不紧贴 */
|
|
682
|
+
const SearchMobileExample = () => (
|
|
683
|
+
<Flex vertical gap={12}>
|
|
684
|
+
<div style={{ color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
685
|
+
<Tag color="blue" style={{ marginRight: 8 }}>
|
|
686
|
+
search only
|
|
687
|
+
</Tag>
|
|
688
|
+
仅配置 <code>search</code>(无 filter / batch / tab),移动端开启 <code>renderMobile</code> 自定义卡片时,
|
|
689
|
+
SearchInput 与下方卡片列表应有间距,不可紧挨。请切换手机预览查看。
|
|
690
|
+
</div>
|
|
691
|
+
<TablePage
|
|
692
|
+
name="demo-search-mobile-gap"
|
|
693
|
+
pagination={{ open: false }}
|
|
694
|
+
search={{ name: 'keyword', label: '关键词', placeholder: '搜索共享组名称' }}
|
|
695
|
+
columns={sharedGroupColumns}
|
|
696
|
+
loader={() =>
|
|
697
|
+
Promise.resolve({
|
|
698
|
+
pageData: sharedGroups,
|
|
699
|
+
totalCount: sharedGroups.length
|
|
700
|
+
})
|
|
701
|
+
}
|
|
702
|
+
renderMobile={({ dataSource }) => (
|
|
703
|
+
<Flex vertical gap={12} className="info-page-table-mobile-card-list">
|
|
704
|
+
{(dataSource || []).map(item => (
|
|
705
|
+
<SharedGroupMobileCard key={item.id} item={item} />
|
|
706
|
+
))}
|
|
707
|
+
</Flex>
|
|
708
|
+
)}
|
|
709
|
+
/>
|
|
710
|
+
</Flex>
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
render(
|
|
714
|
+
<Flex vertical gap={32}>
|
|
715
|
+
<BaseExample />
|
|
716
|
+
<SearchMobileExample />
|
|
717
|
+
</Flex>
|
|
718
|
+
);
|
|
584
719
|
```
|
|
585
720
|
|
|
586
721
|
- TablePage sticky scroll
|
|
@@ -1835,7 +1970,7 @@ render(<BaseExample />);
|
|
|
1835
1970
|
|
|
1836
1971
|
```jsx
|
|
1837
1972
|
const { Table, TableView, preset } = _TablePage;
|
|
1838
|
-
const { Flex, Tag, Card, Button, Dropdown, Tabs, Checkbox } = antd;
|
|
1973
|
+
const { Flex, Tag, Card, Button, Dropdown, Tabs, Checkbox, Radio } = antd;
|
|
1839
1974
|
const { useState, useMemo } = React;
|
|
1840
1975
|
|
|
1841
1976
|
const statusMap = {
|
|
@@ -1906,7 +2041,7 @@ const columns = [
|
|
|
1906
2041
|
|
|
1907
2042
|
preset({
|
|
1908
2043
|
renderMobile: {
|
|
1909
|
-
orderCard: ({ renderBody }) => {
|
|
2044
|
+
orderCard: ({ renderBody, dataSource = [] }) => {
|
|
1910
2045
|
const totalAmount = dataSource.reduce((sum, item) => sum + item.amount, 0);
|
|
1911
2046
|
return (
|
|
1912
2047
|
<div
|
|
@@ -1959,10 +2094,11 @@ const getOrderActions = item => [
|
|
|
1959
2094
|
{ key: 'delete', label: '删除', danger: true, onClick: () => console.log('删除', item.id) }
|
|
1960
2095
|
];
|
|
1961
2096
|
|
|
1962
|
-
const OrderMobileCard = ({ item, checked, disabled, onCheckChange }) => {
|
|
2097
|
+
const OrderMobileCard = ({ item, checked, disabled, onCheckChange, selectionType = 'checkbox' }) => {
|
|
1963
2098
|
const status = statusMap[item.status] || { color: 'default', text: item.status };
|
|
1964
2099
|
const actionItems = getOrderActions(item);
|
|
1965
2100
|
const isSelected = checked;
|
|
2101
|
+
const SelectionControl = selectionType === 'radio' ? Radio : Checkbox;
|
|
1966
2102
|
|
|
1967
2103
|
return (
|
|
1968
2104
|
<div
|
|
@@ -1979,7 +2115,7 @@ const OrderMobileCard = ({ item, checked, disabled, onCheckChange }) => {
|
|
|
1979
2115
|
boxSizing: 'border-box'
|
|
1980
2116
|
}}
|
|
1981
2117
|
>
|
|
1982
|
-
<
|
|
2118
|
+
<SelectionControl checked={checked} disabled={disabled} onChange={onCheckChange} style={{ marginTop: 2, flexShrink: 0 }} />
|
|
1983
2119
|
<div style={{ flex: 1, minWidth: 0 }}>
|
|
1984
2120
|
<Flex justify="space-between" align="center" gap={8} style={{ marginBottom: 10 }}>
|
|
1985
2121
|
<Flex align="center" gap={8} wrap="wrap" style={{ flex: 1, minWidth: 0 }}>
|
|
@@ -2166,33 +2302,18 @@ const MobileSortExample = ({ Component }) => {
|
|
|
2166
2302
|
|
|
2167
2303
|
const CustomMobileRender = ({ Component }) => {
|
|
2168
2304
|
const [selectKeys, setSelectKeys] = useState([]);
|
|
2169
|
-
const
|
|
2305
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({});
|
|
2306
|
+
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort]);
|
|
2170
2307
|
const totalAmount = dataSource.reduce((sum, item) => sum + item.amount, 0);
|
|
2171
2308
|
const selectedAmount = selectKeys.reduce((sum, id) => sum + (dataSource.find(d => d.id === id)?.amount || 0), 0);
|
|
2172
|
-
const checkedAll = isSelectedAll || (dataSource.length > 0 && selectKeys.length === dataSource.length);
|
|
2173
|
-
const indeterminate = selectKeys.length > 0 && !checkedAll;
|
|
2174
|
-
|
|
2175
|
-
const handleSelectAllChange = e => {
|
|
2176
|
-
const checked = e.target.checked;
|
|
2177
|
-
if (!checked) {
|
|
2178
|
-
setIsSelectedAll(false);
|
|
2179
|
-
setSelectKeys([]);
|
|
2180
|
-
return;
|
|
2181
|
-
}
|
|
2182
|
-
setIsSelectedAll(true);
|
|
2183
|
-
setSelectKeys(dataSource.map(item => item.id));
|
|
2184
|
-
};
|
|
2185
|
-
|
|
2186
|
-
const handleCardCheckChange = (id, checked) => {
|
|
2187
|
-
setIsSelectedAll(false);
|
|
2188
|
-
setSelectKeys(keys => (checked ? keys.filter(key => key !== id) : [...keys, id]));
|
|
2189
|
-
};
|
|
2190
2309
|
|
|
2191
2310
|
return (
|
|
2192
2311
|
<div>
|
|
2193
2312
|
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2194
|
-
<code>renderMobile</code> 为 function
|
|
2195
|
-
|
|
2313
|
+
<code>renderMobile</code> 为 function 时完全接管渲染,可自定义卡片内容;
|
|
2314
|
+
全选 / 排序请用回调里的 <code>renderToolbar()</code>(与默认 MobileCard 同一套实现),
|
|
2315
|
+
行勾选用 <code>getSelectionProps(item)</code>,不必自己维护全选状态或排序 UI。
|
|
2316
|
+
桌面端仍走 <code>render</code>。
|
|
2196
2317
|
</div>
|
|
2197
2318
|
<Flex justify="space-between" align="center" style={{ marginBottom: 12 }}>
|
|
2198
2319
|
<span>
|
|
@@ -2214,11 +2335,19 @@ const CustomMobileRender = ({ Component }) => {
|
|
|
2214
2335
|
<span style={{ color: 'rgba(0,0,0,0.45)', fontSize: 12 }}>桌面端 render 自定义外层</span>
|
|
2215
2336
|
</Flex>
|
|
2216
2337
|
<Component
|
|
2217
|
-
dataSource={
|
|
2338
|
+
dataSource={sortedData}
|
|
2218
2339
|
columns={columns}
|
|
2219
2340
|
controllerOpen={false}
|
|
2341
|
+
sortRender={sortRender}
|
|
2342
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
2343
|
+
rowSelection={{
|
|
2344
|
+
type: 'checkbox',
|
|
2345
|
+
allowSelectedAll: true,
|
|
2346
|
+
selectedRowKeys: selectKeys,
|
|
2347
|
+
onChange: keys => setSelectKeys(keys)
|
|
2348
|
+
}}
|
|
2220
2349
|
render={({ renderBody }) => <div style={{ overflowX: 'auto' }}>{renderBody()}</div>}
|
|
2221
|
-
renderMobile={() => (
|
|
2350
|
+
renderMobile={({ dataSource: mobileList = [], renderToolbar, getSelectionProps, getRowKey }) => (
|
|
2222
2351
|
<div
|
|
2223
2352
|
style={{
|
|
2224
2353
|
borderRadius: 12,
|
|
@@ -2234,34 +2363,20 @@ const CustomMobileRender = ({ Component }) => {
|
|
|
2234
2363
|
</Tag>
|
|
2235
2364
|
</Flex>
|
|
2236
2365
|
<div style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>
|
|
2237
|
-
{
|
|
2366
|
+
{mobileList.length} 笔 · 合计 ¥{mobileList.reduce((sum, item) => sum + item.amount, 0).toLocaleString()}
|
|
2238
2367
|
</div>
|
|
2239
2368
|
</div>
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
gap: 6,
|
|
2245
|
-
marginBottom: 12,
|
|
2246
|
-
padding: '4px 8px',
|
|
2247
|
-
background: 'var(--bg-color-grey-1, #fafafa)',
|
|
2248
|
-
borderRadius: 8,
|
|
2249
|
-
fontSize: 12
|
|
2250
|
-
}}
|
|
2251
|
-
>
|
|
2252
|
-
<Checkbox checked={checkedAll} indeterminate={indeterminate} onChange={handleSelectAllChange} />
|
|
2253
|
-
<span>全选</span>
|
|
2254
|
-
</div>
|
|
2255
|
-
<Flex vertical gap={12}>
|
|
2256
|
-
{dataSource.map(item => {
|
|
2257
|
-
const isChecked = selectKeys.indexOf(item.id) > -1;
|
|
2369
|
+
{renderToolbar()}
|
|
2370
|
+
<Flex vertical gap={12} style={{ marginTop: 12 }}>
|
|
2371
|
+
{mobileList.map(item => {
|
|
2372
|
+
const selection = getSelectionProps(item);
|
|
2258
2373
|
return (
|
|
2259
2374
|
<OrderMobileCard
|
|
2260
|
-
key={item
|
|
2375
|
+
key={getRowKey(item)}
|
|
2261
2376
|
item={item}
|
|
2262
|
-
checked={
|
|
2263
|
-
disabled={
|
|
2264
|
-
onCheckChange={
|
|
2377
|
+
checked={selection.checked}
|
|
2378
|
+
disabled={selection.disabled}
|
|
2379
|
+
onCheckChange={selection.onChange}
|
|
2265
2380
|
/>
|
|
2266
2381
|
);
|
|
2267
2382
|
})}
|
|
@@ -2274,6 +2389,73 @@ const CustomMobileRender = ({ Component }) => {
|
|
|
2274
2389
|
);
|
|
2275
2390
|
};
|
|
2276
2391
|
|
|
2392
|
+
const CustomMobileRadioRender = ({ Component }) => {
|
|
2393
|
+
const [selectKeys, setSelectKeys] = useState([]);
|
|
2394
|
+
const { sort, sortRender, mobileSortToolbar } = Table.useSort({});
|
|
2395
|
+
const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns), [sort]);
|
|
2396
|
+
const selectedOrder = dataSource.find(item => item.id === selectKeys[0]);
|
|
2397
|
+
|
|
2398
|
+
return (
|
|
2399
|
+
<div>
|
|
2400
|
+
<div style={{ marginBottom: 12, color: '#666', fontSize: 13, lineHeight: 1.7 }}>
|
|
2401
|
+
自定义 <code>renderMobile</code> 单选:<code>rowSelection.type</code> 设为 <code>radio</code>,
|
|
2402
|
+
卡片上的 Radio 直接绑 <code>getSelectionProps(item)</code>,选中态与切换逻辑由 TableView 管理;
|
|
2403
|
+
工具栏 <code>renderToolbar()</code> 此时仅显示排序(单选无全选)。
|
|
2404
|
+
</div>
|
|
2405
|
+
<Flex justify="space-between" align="center" style={{ marginBottom: 12 }}>
|
|
2406
|
+
<span>
|
|
2407
|
+
当前选中:
|
|
2408
|
+
{selectedOrder ? (
|
|
2409
|
+
<strong>
|
|
2410
|
+
{selectedOrder.id} · ¥{selectedOrder.amount.toLocaleString()}
|
|
2411
|
+
</strong>
|
|
2412
|
+
) : (
|
|
2413
|
+
<span style={{ color: '#999' }}>未选择</span>
|
|
2414
|
+
)}
|
|
2415
|
+
</span>
|
|
2416
|
+
</Flex>
|
|
2417
|
+
<Component
|
|
2418
|
+
dataSource={sortedData}
|
|
2419
|
+
columns={columns}
|
|
2420
|
+
controllerOpen={false}
|
|
2421
|
+
sortRender={sortRender}
|
|
2422
|
+
mobileSortToolbar={mobileSortToolbar}
|
|
2423
|
+
rowSelection={{
|
|
2424
|
+
type: 'radio',
|
|
2425
|
+
selectedRowKeys: selectKeys,
|
|
2426
|
+
onChange: keys => setSelectKeys(keys)
|
|
2427
|
+
}}
|
|
2428
|
+
renderMobile={({ dataSource: mobileList = [], renderToolbar, getSelectionProps, getRowKey }) => (
|
|
2429
|
+
<div
|
|
2430
|
+
style={{
|
|
2431
|
+
borderRadius: 12,
|
|
2432
|
+
background: '#f5f7fa',
|
|
2433
|
+
padding: 16
|
|
2434
|
+
}}
|
|
2435
|
+
>
|
|
2436
|
+
{renderToolbar()}
|
|
2437
|
+
<Flex vertical gap={12} style={{ marginTop: 12 }}>
|
|
2438
|
+
{mobileList.map(item => {
|
|
2439
|
+
const selection = getSelectionProps(item);
|
|
2440
|
+
return (
|
|
2441
|
+
<OrderMobileCard
|
|
2442
|
+
key={getRowKey(item)}
|
|
2443
|
+
item={item}
|
|
2444
|
+
selectionType="radio"
|
|
2445
|
+
checked={selection.checked}
|
|
2446
|
+
disabled={selection.disabled}
|
|
2447
|
+
onCheckChange={selection.onChange}
|
|
2448
|
+
/>
|
|
2449
|
+
);
|
|
2450
|
+
})}
|
|
2451
|
+
</Flex>
|
|
2452
|
+
</div>
|
|
2453
|
+
)}
|
|
2454
|
+
/>
|
|
2455
|
+
</div>
|
|
2456
|
+
);
|
|
2457
|
+
};
|
|
2458
|
+
|
|
2277
2459
|
const PresetStringRender = ({ Component }) => {
|
|
2278
2460
|
const [selectKeys, setSelectKeys] = useState([]);
|
|
2279
2461
|
const { sort, sortRender, mobileSortToolbar } = Table.useSort({
|
|
@@ -2319,6 +2501,7 @@ const Examples = ({ Component }) => (
|
|
|
2319
2501
|
<DefaultMobileCards Component={Component} />
|
|
2320
2502
|
<MobileSortExample Component={Component} />
|
|
2321
2503
|
<CustomMobileRender Component={Component} />
|
|
2504
|
+
<CustomMobileRadioRender Component={Component} />
|
|
2322
2505
|
<PresetStringRender Component={Component} />
|
|
2323
2506
|
</Flex>
|
|
2324
2507
|
);
|
|
@@ -2840,10 +3023,11 @@ render(<BaseExample />);
|
|
|
2840
3023
|
| summary | function | - | 总结栏,回调参数包含 `data`、`requestParams`、`refresh`、`reload` 等 fetch 上下文 |
|
|
2841
3024
|
| columnRenderProps | object | `{}` | 列渲染扩展属性,会合并进列 `render` 的 context |
|
|
2842
3025
|
| filter | object | - | 顶部筛选器配置,基于 `@kne/react-filter` 的 `FilterLines`,见下方 |
|
|
2843
|
-
| search | object | - | 顶部搜索框配置,基于 `@kne/react-filter` 的 `SearchInput
|
|
3026
|
+
| search | object | - | 顶部搜索框配置,基于 `@kne/react-filter` 的 `SearchInput`,见下方;移动端 `renderMobile` 激活时,工具栏与下方卡片列表保留间距(勿紧贴) |
|
|
2844
3027
|
| tab | object | - | 顶部 Tab 分类切换,选中值写入 filter value,见下方 |
|
|
2845
3028
|
| tabProps | object | - | 透传给 antd `Tabs` 的额外属性(如 `tabBarExtraContent`) |
|
|
2846
3029
|
| batchActions | array | - | 批量操作下拉菜单项,需配合 `rowSelection` 使用,见下方 |
|
|
3030
|
+
| buttonGroup | object | - | 操作按钮组,透传 `@kne/button-group` 的 `ButtonGroup` 属性;桌面端显示在 `SearchInput` 右侧,移动端通过 `ButtonFooter` 固定在列表底部 |
|
|
2847
3031
|
| selectedRows | array | - | 已选行数据,传给 `batchActions` 的 `onClick` 上下文 |
|
|
2848
3032
|
| className | string | - | 自定义类名 |
|
|
2849
3033
|
| ...fetchProps | - | - | 其余属性透传给 `@kne/react-fetch`(如 `url`、`params`、`auto` 等) |
|
|
@@ -2866,6 +3050,10 @@ render(<BaseExample />);
|
|
|
2866
3050
|
| showTotal | function | - | 自定义总数展示 `(total) => ReactNode` |
|
|
2867
3051
|
| onChange | function | - | 自定义翻页回调 `(page, size) => void`,传入后覆盖默认请求逻辑 |
|
|
2868
3052
|
| onShowSizeChange | function | - | 每页条数变化回调,组件内部已处理持久化 |
|
|
3053
|
+
| forcePagination | boolean | `false` | 移动端(`renderMobile` 激活时)默认改为触底下拉加载;设为 `true` 时强制仍使用分页器 |
|
|
3054
|
+
| mergeList | function | 合并 `pageData` | 下拉加载时合并新旧数据 `(prev, next) => data`,需与 `loader` 返回结构一致 |
|
|
3055
|
+
| loadMore | object | - | 透传给 `@kne/scroll-loader` 的额外配置(如 `completeTips`、`maxFullCount`) |
|
|
3056
|
+
| mobile | object | - | 强制分页时的移动端分页器微调(如 `showSizeChanger`、`showLessItems`) |
|
|
2869
3057
|
|
|
2870
3058
|
#### filter
|
|
2871
3059
|
|
|
@@ -2891,6 +3079,27 @@ render(<BaseExample />);
|
|
|
2891
3079
|
| placeholder | string | - | 占位符 |
|
|
2892
3080
|
| searchDelay | number | `500` | 自动提交防抖时间(毫秒) |
|
|
2893
3081
|
|
|
3082
|
+
#### buttonGroup
|
|
3083
|
+
|
|
3084
|
+
操作按钮组配置,透传给 `@kne/button-group` 的 `ButtonGroup`(如 `list`、`compact` 等)。
|
|
3085
|
+
|
|
3086
|
+
- 桌面端:显示在工具栏右侧(`SearchInput` 右侧);默认 `size="small"`、至少展示 1 个按钮(`showLength` 默认 `1`)、「更多」为三点图标(`moreType="link"`)
|
|
3087
|
+
- 移动端:使用 `ButtonFooter` 渲染在列表底部,按钮组居中;默认至少展示 2 个按钮(`showLength` 默认 `2`)、按钮为正常尺寸,其余收入「更多」
|
|
3088
|
+
|
|
3089
|
+
```jsx
|
|
3090
|
+
<TablePage
|
|
3091
|
+
search={{ name: 'keyword', label: '关键词' }}
|
|
3092
|
+
buttonGroup={{
|
|
3093
|
+
list: [
|
|
3094
|
+
{ type: 'primary', children: '新建', onClick: () => {} },
|
|
3095
|
+
{ children: '导出', onClick: () => {} }
|
|
3096
|
+
]
|
|
3097
|
+
}}
|
|
3098
|
+
loader={...}
|
|
3099
|
+
columns={...}
|
|
3100
|
+
/>
|
|
3101
|
+
```
|
|
3102
|
+
|
|
2894
3103
|
#### tab
|
|
2895
3104
|
|
|
2896
3105
|
顶部 Tab 分类切换。默认选中「全部」(不写入筛选值);切换到具体项时,将 `{ name, label, value: { value, label } }` 写入 filter value,并触发 `reload` 回到第 1 页。桌面端显示在表格边框外侧上方;移动端(含 `renderMobile`)显示在 `SearchInput` 下方。选中值会出现在已选筛选标签中,清除标签会回到「全部」。
|
|
@@ -2951,6 +3160,8 @@ render(<BaseExample />);
|
|
|
2951
3160
|
|
|
2952
3161
|
`TablePage` 的分页器渲染在表格外侧(`antd Pagination`),不会出现在 `Table` 边框内部。表格本身始终设置 `pagination={false}`。当 `dataFormat` 返回的 `total` 为 0(无数据)时,分页器不会渲染。
|
|
2953
3162
|
|
|
3163
|
+
移动端(`renderMobile` 激活)默认使用触底下拉加载(`@kne/scroll-loader` + `react-fetch` 的 `loadMore`),不再展示分页器。若需移动端仍使用分页,请设置 `pagination.forcePagination: true`。
|
|
3164
|
+
|
|
2954
3165
|
#### renderType
|
|
2955
3166
|
|
|
2956
3167
|
通过 `renderType` 选择内部使用的表格组件,默认为 `Table`:
|
|
@@ -3003,11 +3214,36 @@ render(<BaseExample />);
|
|
|
3003
3214
|
| headerStyle | object | - | 表头自定义样式,仅在 `render` 自定义渲染时作用于 `header` |
|
|
3004
3215
|
| onRowSelect | function | - | 行点击回调 `(item, { columns, dataSource }) => void` |
|
|
3005
3216
|
| render | function | - | 自定义渲染 `(props) => ReactNode`,可获取 `header` 和 `renderBody` |
|
|
3006
|
-
| renderMobile | boolean \| function \| string | `true` | 仅移动端生效。`true` 使用默认卡片 List
|
|
3217
|
+
| renderMobile | boolean \| function \| string | `true` | 仅移动端生效。`true` 使用默认卡片 List;为 function 时完全接管渲染(见下方回调参数);为 string 时从 `preset({ renderMobile })` 按名称取渲染函数,未注册则视为未开启 |
|
|
3007
3218
|
| sortRender | function | - | 排序按钮渲染,由 `useSort` 提供(桌面端表头) |
|
|
3008
|
-
| mobileSortToolbar | function | - | 移动端排序工具栏,由 `useSort`
|
|
3219
|
+
| mobileSortToolbar | function | - | 移动端排序工具栏,由 `useSort` 提供;传入 TableView 后由 `renderToolbar` / 默认卡片复用 |
|
|
3009
3220
|
| size | `'small'` \| `'large'` | - | 单元格内边距:默认 `8px`,`small` 为 `4px`,`large` 为 `14px 8px`;可通过 CSS 变量覆盖 |
|
|
3010
3221
|
|
|
3222
|
+
`renderMobile` 为 function 时,TableView 会传入已接好 `rowSelection` / `mobileSortToolbar` 的能力,自定义布局只需选用:
|
|
3223
|
+
|
|
3224
|
+
| 回调参数 | 说明 |
|
|
3225
|
+
|------|------|
|
|
3226
|
+
| `dataSource` | 当前页数据 |
|
|
3227
|
+
| `columns` | 布局后的列配置 |
|
|
3228
|
+
| `rowKey` / `rowSelection` / `context` / `empty` | 与 TableView 一致 |
|
|
3229
|
+
| `renderBody` | 渲染默认移动端卡片 List(含顶部工具栏) |
|
|
3230
|
+
| `renderToolbar` | 渲染组件级工具栏(全选居左、排序居右);可自由决定摆放位置 |
|
|
3231
|
+
| `getRowKey(item)` | 按 `rowKey` 取行 key |
|
|
3232
|
+
| `getSelectionProps(item)` | 返回 `{ checked, disabled, onChange }`,可直接绑到卡片上的 Checkbox / Radio |
|
|
3233
|
+
| `onSelectionChange` | 行选择切换,签名与内部逻辑一致 |
|
|
3234
|
+
|
|
3235
|
+
```jsx
|
|
3236
|
+
renderMobile={({ dataSource, renderToolbar, getSelectionProps, getRowKey }) => (
|
|
3237
|
+
<>
|
|
3238
|
+
{renderToolbar()}
|
|
3239
|
+
{dataSource.map(item => {
|
|
3240
|
+
const selection = getSelectionProps(item);
|
|
3241
|
+
return <MyCard key={getRowKey(item)} item={item} {...selection} />;
|
|
3242
|
+
})}
|
|
3243
|
+
</>
|
|
3244
|
+
)}
|
|
3245
|
+
```
|
|
3246
|
+
|
|
3011
3247
|
单元格 padding 由 CSS 变量控制,可在外层覆盖:
|
|
3012
3248
|
|
|
3013
3249
|
```css
|
|
@@ -3150,7 +3386,7 @@ const sortedData = useMemo(() => Table.sortDataSource(dataSource, sort, columns)
|
|
|
3150
3386
|
| headerStyle | object | - | 表头自定义样式 |
|
|
3151
3387
|
| onRowSelect | function | - | 行点击回调 `(item, { columns, dataSource }) => void` |
|
|
3152
3388
|
| render | function | - | 自定义渲染 `(props) => ReactNode`,`header` 为 `null`,`renderBody` 返回 antd Table |
|
|
3153
|
-
| renderMobile | boolean \| function \| string | `true` |
|
|
3389
|
+
| renderMobile | boolean \| function \| string | `true` | 仅移动端生效,委托 `@kne/table-view` 处理;`true` 为默认卡片 List;为 function 时回调参数同 TableView(见 TableView 文档 `renderMobile` 回调参数);为 string 时从 preset 按名称查找 |
|
|
3154
3390
|
| sortRender | function | - | 排序按钮渲染,由 `useSort` 提供(桌面端表头) |
|
|
3155
3391
|
| mobileSortToolbar | function | - | 移动端排序工具栏,由 `useSort` 提供 |
|
|
3156
3392
|
| pagination | boolean \| object | `false` | 分页配置,默认不显示;传入对象时使用 antd 分页 |
|
package/dist/index.css
CHANGED
|
@@ -422,6 +422,9 @@
|
|
|
422
422
|
border-radius: var(--radius-default, 2px);
|
|
423
423
|
}
|
|
424
424
|
.kne-table-page_sf06r.kne-table-page_D6KGb {
|
|
425
|
+
display: flex;
|
|
426
|
+
flex-direction: column;
|
|
427
|
+
gap: 12px;
|
|
425
428
|
border: none;
|
|
426
429
|
border-radius: 0;
|
|
427
430
|
}
|
|
@@ -476,11 +479,66 @@
|
|
|
476
479
|
border-radius: 0 !important;
|
|
477
480
|
}
|
|
478
481
|
|
|
482
|
+
.kne-table-page_UqVnb {
|
|
483
|
+
width: 100%;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.kne-table-page_fCJem {
|
|
487
|
+
margin-top: 16px;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
.kne-table-page_QUaIh {
|
|
491
|
+
display: flex;
|
|
492
|
+
justify-content: center;
|
|
493
|
+
align-items: center;
|
|
494
|
+
width: 100%;
|
|
495
|
+
box-sizing: border-box;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.kne-table-page_cgfZv {
|
|
499
|
+
width: 100%;
|
|
500
|
+
display: flex;
|
|
501
|
+
justify-content: center;
|
|
502
|
+
}
|
|
503
|
+
.kne-table-page_cgfZv > div {
|
|
504
|
+
width: 100%;
|
|
505
|
+
display: flex;
|
|
506
|
+
justify-content: center;
|
|
507
|
+
align-items: center;
|
|
508
|
+
position: relative;
|
|
509
|
+
}
|
|
510
|
+
.kne-table-page_cgfZv > div > :nth-child(1) {
|
|
511
|
+
position: absolute;
|
|
512
|
+
left: 0;
|
|
513
|
+
right: 0;
|
|
514
|
+
top: 0;
|
|
515
|
+
width: 100%;
|
|
516
|
+
height: 0;
|
|
517
|
+
overflow: hidden;
|
|
518
|
+
pointer-events: none;
|
|
519
|
+
}
|
|
520
|
+
.kne-table-page_cgfZv > div > :nth-child(2) {
|
|
521
|
+
position: absolute;
|
|
522
|
+
width: 0;
|
|
523
|
+
height: 0;
|
|
524
|
+
overflow: hidden;
|
|
525
|
+
pointer-events: none;
|
|
526
|
+
}
|
|
527
|
+
.kne-table-page_cgfZv > div > .ant-space,
|
|
528
|
+
.kne-table-page_cgfZv > div > .ant-space-compact {
|
|
529
|
+
justify-content: center;
|
|
530
|
+
margin-inline: auto;
|
|
531
|
+
flex: 0 0 auto;
|
|
532
|
+
}
|
|
533
|
+
|
|
479
534
|
.kne-table-page_DSTEf.ant-pagination {
|
|
480
535
|
margin-top: 16px;
|
|
481
536
|
display: flex;
|
|
482
537
|
justify-content: flex-end;
|
|
483
538
|
}
|
|
539
|
+
.kne-table-page_DSTEf.ant-pagination.kne-table-page_D6KGb {
|
|
540
|
+
justify-content: center;
|
|
541
|
+
}
|
|
484
542
|
.kne-table-page_DSTEf.ant-pagination.kne-table-page_D6KGb .ant-pagination-prev,
|
|
485
543
|
.kne-table-page_DSTEf.ant-pagination.kne-table-page_D6KGb .ant-pagination-item,
|
|
486
544
|
.kne-table-page_DSTEf.ant-pagination.kne-table-page_D6KGb .ant-pagination-jump-prev,
|
|
@@ -614,11 +672,27 @@
|
|
|
614
672
|
background: var(--color-error-bg-hover, #ffccc7) !important;
|
|
615
673
|
}
|
|
616
674
|
|
|
617
|
-
.kne-table-
|
|
675
|
+
.kne-table-page_t3-57 {
|
|
618
676
|
flex-shrink: 0;
|
|
619
677
|
display: flex;
|
|
620
678
|
align-items: center;
|
|
679
|
+
gap: 8px;
|
|
621
680
|
margin-left: auto;
|
|
681
|
+
min-width: 0;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
.kne-table-page_2sdSC {
|
|
685
|
+
flex-shrink: 0;
|
|
686
|
+
display: flex;
|
|
687
|
+
align-items: center;
|
|
688
|
+
max-width: 100%;
|
|
689
|
+
min-width: 0;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
.kne-table-page_pB5en {
|
|
693
|
+
flex-shrink: 0;
|
|
694
|
+
display: flex;
|
|
695
|
+
align-items: center;
|
|
622
696
|
}
|
|
623
697
|
.kne-table-page_pB5en .ant-input-search {
|
|
624
698
|
background: var(--bg-color-grey-1, #f5f5f5);
|
|
@@ -691,6 +765,9 @@
|
|
|
691
765
|
.kne-table-page_I21Xn.kne-table-page_14SJt.kne-table-page_Y5IR1 .kne-table-page_zuGJv {
|
|
692
766
|
padding-bottom: 8px;
|
|
693
767
|
}
|
|
768
|
+
.kne-table-page_I21Xn.kne-table-page_14SJt.kne-table-page_J-AEV.kne-table-page_Y5IR1 .kne-table-page_zuGJv {
|
|
769
|
+
padding-bottom: 0;
|
|
770
|
+
}
|
|
694
771
|
.kne-table-page_I21Xn.kne-table-page_EImBh .kne-table-page_UTy3R {
|
|
695
772
|
padding-inline: 16px;
|
|
696
773
|
}
|