@gmfe/table-x 2.14.30-beta.4 → 2.14.30
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 +226 -0
- package/package.json +4 -4
- package/src/base/td.js +1 -1
- package/src/base/tr.js +2 -2
- package/src/index.js +0 -4
- package/src/index.less +3 -155
- package/src/util/index.js +6 -8
- package/src/hoc/two_level_header_table_x/flatten_helper.js +0 -29
- package/src/hoc/two_level_header_table_x/rebuild_helper.js +0 -95
- package/src/hoc/two_level_header_table_x/table_x.js +0 -169
- package/src/hoc/two_level_header_table_x/td.js +0 -126
- package/src/hoc/two_level_header_table_x/thead.js +0 -293
- package/src/hoc/two_level_header_table_x/tr.js +0 -53
- package/src/hoc/two_level_header_table_x/transform_helper.js +0 -165
- package/src/hoc/two_level_header_table_x.js +0 -36
package/README.md
CHANGED
|
@@ -1,3 +1,229 @@
|
|
|
1
|
+
# @gmfe/table-x
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@gmfe/table-x` 是基于 [react-table v7](https://github.com/tannerlinsley/react-table)(7.0.0-rc.11)封装的高级表格组件包,是 `@gmfe/table` 的升级版本。采用 Hooks API 和 Context API,提供更现代的表格功能扩展。支持虚拟滚动、选择、展开、固定列、排序、子表格、自定义列和可编辑表格等功能。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gmfe/table-x
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
### 基础表格
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import React from 'react'
|
|
19
|
+
import { TableX } from '@gmfe/table-x'
|
|
20
|
+
|
|
21
|
+
const columns = [
|
|
22
|
+
{ Header: '名称', accessor: 'name' },
|
|
23
|
+
{ Header: '年龄', accessor: 'age' }
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
const data = [
|
|
27
|
+
{ value: 1, name: '张三', age: 28 },
|
|
28
|
+
{ value: 2, name: '李四', age: 32 }
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return <TableX columns={columns} data={data} />
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 带选择功能的表格
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
import React, { useState } from 'react'
|
|
40
|
+
import { TableX, selectTableXHOC } from '@gmfe/table-x'
|
|
41
|
+
|
|
42
|
+
const SelectTableX = selectTableXHOC(TableX)
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
const [selected, setSelected] = useState([])
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SelectTableX
|
|
49
|
+
columns={columns}
|
|
50
|
+
data={data}
|
|
51
|
+
selected={selected}
|
|
52
|
+
onSelect={(selected) => setSelected(selected)}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 虚拟滚动表格
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
import { TableXVirtualized } from '@gmfe/table-x'
|
|
62
|
+
|
|
63
|
+
function App() {
|
|
64
|
+
return (
|
|
65
|
+
<TableXVirtualized
|
|
66
|
+
columns={columns}
|
|
67
|
+
data={largeData}
|
|
68
|
+
virtualizedHeight={600}
|
|
69
|
+
virtualizedItemSize={40}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### TableX
|
|
78
|
+
|
|
79
|
+
基础表格组件。
|
|
80
|
+
|
|
81
|
+
| 属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
82
|
+
|------|------|------|--------|------|
|
|
83
|
+
| columns | 列定义 | `array` | - | 是 |
|
|
84
|
+
| data | 表格数据 | `array` | - | 是 |
|
|
85
|
+
| loading | 是否加载中 | `boolean` | `false` | 否 |
|
|
86
|
+
| keyField | 行唯一标识字段 | `string` | `'value'` | 否 |
|
|
87
|
+
| tiled | 是否平铺 | `boolean` | `false` | 否 |
|
|
88
|
+
| isTrDisable | 行禁用判断函数 | `function(row): boolean` | `() => false` | 否 |
|
|
89
|
+
| isTrHighlight | 行高亮判断函数 | `function(row): boolean` | `() => false` | 否 |
|
|
90
|
+
| SubComponent | 展开行渲染函数 | `function(row)` | - | 否 |
|
|
91
|
+
| onScroll | 滚动回调 | `function` | - | 否 |
|
|
92
|
+
| className | 自定义类名 | `string` | - | 否 |
|
|
93
|
+
| style | 自定义样式 | `object` | - | 否 |
|
|
94
|
+
|
|
95
|
+
### TableXVirtualized
|
|
96
|
+
|
|
97
|
+
虚拟滚动表格组件,继承 TableX 的所有属性,额外支持:
|
|
98
|
+
|
|
99
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
100
|
+
|----------|------|------|--------|------|
|
|
101
|
+
| virtualizedHeight | 表格容器高度 | `number` | - | 是 |
|
|
102
|
+
| virtualizedItemSize | 行高(数字或函数) | `number \| function` | - | 是 |
|
|
103
|
+
| refVirtualized | 虚拟列表 ref | `object \| function` | - | 否 |
|
|
104
|
+
|
|
105
|
+
### HOC 组件
|
|
106
|
+
|
|
107
|
+
#### selectTableXHOC(TableX)
|
|
108
|
+
|
|
109
|
+
选择功能表格 HOC。
|
|
110
|
+
|
|
111
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
112
|
+
|----------|------|------|--------|------|
|
|
113
|
+
| selected | 已选中项数组 | `array` | - | 是 |
|
|
114
|
+
| onSelect | 选中回调 | `function(selected: array)` | - | 是 |
|
|
115
|
+
| selectType | 选择类型 | `'checkbox' \| 'radio'` | `'checkbox'` | 否 |
|
|
116
|
+
| keyField | 行唯一标识字段 | `string` | `'value'` | 否 |
|
|
117
|
+
| isSelectorDisable | 行选择禁用函数 | `function(row): boolean` | `() => false` | 否 |
|
|
118
|
+
| batchActionBar | 自定义批量操作栏 | `ReactElement` | - | 否 |
|
|
119
|
+
| fixedSelect | 是否固定选择列 | `boolean` | `false` | 否 |
|
|
120
|
+
|
|
121
|
+
#### expandTableXHOC(TableX)
|
|
122
|
+
|
|
123
|
+
展开行表格 HOC。
|
|
124
|
+
|
|
125
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
126
|
+
|----------|------|------|--------|------|
|
|
127
|
+
| SubComponent | 展开内容渲染函数 | `function(row)` | - | 是 |
|
|
128
|
+
| expanded | 展开行对象(受控模式) | `object` | - | 否 |
|
|
129
|
+
| onExpand | 展开/折叠回调 | `function(expanded: object)` | - | 否 |
|
|
130
|
+
| fixedExpand | 是否固定展开列 | `boolean` | `false` | 否 |
|
|
131
|
+
|
|
132
|
+
#### fixedColumnsTableXHOC(TableX)
|
|
133
|
+
|
|
134
|
+
固定列 HOC。列定义中通过 `fixed: 'left'` 或 `fixed: 'right'` 指定固定方向。固定列需要设置 `width` 属性。
|
|
135
|
+
|
|
136
|
+
#### sortableTableXHOC(TableX)
|
|
137
|
+
|
|
138
|
+
可拖拽排序表格 HOC。
|
|
139
|
+
|
|
140
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
141
|
+
|----------|------|------|--------|------|
|
|
142
|
+
| onSortChange | 排序变化回调 | `function(data: array)` | - | 是 |
|
|
143
|
+
| keyField | 行唯一标识字段 | `string` | `'value'` | 否 |
|
|
144
|
+
|
|
145
|
+
#### editTableXHOC(TableX)
|
|
146
|
+
|
|
147
|
+
可编辑表格 HOC,添加 `.gm-table-x-edit-table` 样式类。
|
|
148
|
+
|
|
149
|
+
#### subTableXHOC(TableX)
|
|
150
|
+
|
|
151
|
+
子表格 HOC,添加缩进列。
|
|
152
|
+
|
|
153
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
154
|
+
|----------|------|------|--------|------|
|
|
155
|
+
| subTableIndent | 子表格缩进宽度 | `number` | `TABLE_X.WIDTH_FUN` | 否 |
|
|
156
|
+
|
|
157
|
+
#### diyTableXHOC(TableX)
|
|
158
|
+
|
|
159
|
+
自定义列管理 HOC。
|
|
160
|
+
|
|
161
|
+
| 额外属性 | 说明 | 类型 | 默认值 | 必填 |
|
|
162
|
+
|----------|------|------|--------|------|
|
|
163
|
+
| id | 唯一标识,用于保存列配置到 localStorage | `string` | - | 是 |
|
|
164
|
+
| diyGroupSorting | 分组排序配置 | `array` | - | 是 |
|
|
165
|
+
|
|
166
|
+
- 列定义中需要 `diyGroupName` 和 `Header`(或 `diyItemText`)字段。
|
|
167
|
+
|
|
168
|
+
### TableXUtil
|
|
169
|
+
|
|
170
|
+
表格工具集。
|
|
171
|
+
|
|
172
|
+
| 属性/方法 | 说明 |
|
|
173
|
+
|-----------|------|
|
|
174
|
+
| `TABLE_X` | 表格常量配置(宽度、高度等) |
|
|
175
|
+
| `BatchActionBar` | 批量操作栏组件 |
|
|
176
|
+
| `OperationHeader` | 操作列表头组件 |
|
|
177
|
+
| `OperationDelete` | 删除操作组件 |
|
|
178
|
+
| `OperationRecover` | 恢复操作组件 |
|
|
179
|
+
| `OperationDetail` | 详情操作组件 |
|
|
180
|
+
| `OperationCell` | 操作单元格组件 |
|
|
181
|
+
| `OperationRowEdit` | 行编辑操作组件 |
|
|
182
|
+
| `OperationIconTip` | 图标提示操作组件 |
|
|
183
|
+
| `EditButton` | 编辑按钮组件 |
|
|
184
|
+
| `EditOperation` | 编辑操作组件 |
|
|
185
|
+
| `SortHeader` | 排序表头组件 |
|
|
186
|
+
|
|
187
|
+
## 示例
|
|
188
|
+
|
|
189
|
+
### 多功能组合
|
|
190
|
+
|
|
191
|
+
```jsx
|
|
192
|
+
import { TableX, selectTableXHOC, expandTableXHOC, fixedColumnsTableXHOC } from '@gmfe/table-x'
|
|
193
|
+
|
|
194
|
+
// HOC 组合:选择 + 展开 + 固定列
|
|
195
|
+
const EnhancedTable = fixedColumnsTableXHOC(selectTableXHOC(expandTableXHOC(TableX)))
|
|
196
|
+
|
|
197
|
+
const columns = [
|
|
198
|
+
{ Header: '名称', accessor: 'name', fixed: 'left', width: 200 },
|
|
199
|
+
{ Header: '描述', accessor: 'desc' },
|
|
200
|
+
{ Header: '操作', accessor: 'action', fixed: 'right', width: 150 }
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
function App() {
|
|
204
|
+
return (
|
|
205
|
+
<EnhancedTable
|
|
206
|
+
columns={columns}
|
|
207
|
+
data={data}
|
|
208
|
+
selected={selected}
|
|
209
|
+
onSelect={setSelected}
|
|
210
|
+
SubComponent={(row) => <div>展开内容:{row.original.name}</div>}
|
|
211
|
+
/>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## 注意事项
|
|
217
|
+
|
|
218
|
+
- `keyField` 默认为 `'value'`,确保数据中有该字段作为行唯一标识。
|
|
219
|
+
- 固定列必须设置 `width` 属性,否则会报错。
|
|
220
|
+
- `show: false` 的列会被自动过滤。
|
|
221
|
+
- 虚拟列表(`TableXVirtualized`)适用于大数据量场景,需要指定 `virtualizedHeight` 和 `virtualizedItemSize`。
|
|
222
|
+
- `selectTableXHOC` 不再提供 `onSelectAll` 回调,选中全部的逻辑通过 `isSelectorDisable` 和内部计算实现。
|
|
223
|
+
- 此包需要 `styled-components ^5.1.0` 作为 peer dependency。
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
1
227
|
## tableX 踩的坑,阅读后改代码更自信
|
|
2
228
|
|
|
3
229
|
- 注意不要随意升级版本,目前使用 7.0.0-rc.11
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmfe/table-x",
|
|
3
|
-
"version": "2.14.30
|
|
3
|
+
"version": "2.14.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gmfe#readme",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gm-common/tool": "^1.0.0",
|
|
30
|
-
"@gmfe/locales": "^2.14.
|
|
31
|
-
"@gmfe/react": "2.14.
|
|
30
|
+
"@gmfe/locales": "^2.14.30",
|
|
31
|
+
"@gmfe/react": "^2.14.30",
|
|
32
32
|
"classnames": "^2.2.5",
|
|
33
33
|
"lodash": "^4.17.14",
|
|
34
34
|
"prop-types": "^15.7.2",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"react-window": "^1.8.5",
|
|
37
37
|
"sortablejs": "^1.10.1"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "ecae7979e69fc5e3bb1185fe84f82f00dfca1159"
|
|
40
40
|
}
|
package/src/base/td.js
CHANGED
package/src/base/tr.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import React from 'react'
|
|
4
|
-
import Td from '
|
|
4
|
+
import Td from './td'
|
|
5
5
|
|
|
6
6
|
const Tr = ({
|
|
7
7
|
row,
|
|
@@ -10,7 +10,7 @@ const Tr = ({
|
|
|
10
10
|
style,
|
|
11
11
|
totalWidth,
|
|
12
12
|
isTrDisable,
|
|
13
|
-
isTrHighlight
|
|
13
|
+
isTrHighlight,
|
|
14
14
|
}) => {
|
|
15
15
|
const props = {
|
|
16
16
|
...row.getRowProps(),
|
package/src/index.js
CHANGED
|
@@ -7,8 +7,6 @@ import sortableTableXHOC from './hoc/sortable_table_x'
|
|
|
7
7
|
import subTableXHOC from './hoc/sub_table_x'
|
|
8
8
|
import editTableXHOC from './hoc/edit_table_x'
|
|
9
9
|
import diyTableXHOC from './hoc/diy_table_x'
|
|
10
|
-
import twoLevelHeaderTableXHOC from './hoc/two_level_header_table_x'
|
|
11
|
-
import TwoLevelTableX from './hoc/two_level_header_table_x/table_x'
|
|
12
10
|
|
|
13
11
|
import {
|
|
14
12
|
TABLE_X,
|
|
@@ -44,8 +42,6 @@ const TableXUtil = {
|
|
|
44
42
|
export {
|
|
45
43
|
TableXUtil,
|
|
46
44
|
TableX,
|
|
47
|
-
TwoLevelTableX,
|
|
48
|
-
twoLevelHeaderTableXHOC,
|
|
49
45
|
TableXVirtualized,
|
|
50
46
|
selectTableXHOC,
|
|
51
47
|
expandTableXHOC,
|
package/src/index.less
CHANGED
|
@@ -19,70 +19,6 @@
|
|
|
19
19
|
transform: translateZ(0);
|
|
20
20
|
display: block; // 覆盖table 默认display
|
|
21
21
|
|
|
22
|
-
// 当有两级表头时,表格需要使用表格布局来支持 rowspan
|
|
23
|
-
&.gm-table-x-table-two-level {
|
|
24
|
-
display: table !important;
|
|
25
|
-
.gm-table-x-tbody {
|
|
26
|
-
display: table-row-group !important;
|
|
27
|
-
.gm-table-x-tr {
|
|
28
|
-
display: table-row !important;
|
|
29
|
-
height: 60px;
|
|
30
|
-
.gm-table-x-td {
|
|
31
|
-
display: table-cell !important;
|
|
32
|
-
flex: none !important;
|
|
33
|
-
flex-grow: unset !important;
|
|
34
|
-
flex-shrink: unset !important;
|
|
35
|
-
flex-basis: unset !important;
|
|
36
|
-
box-sizing: border-box;
|
|
37
|
-
padding: 8px;
|
|
38
|
-
white-space: normal;
|
|
39
|
-
word-wrap: break-word;
|
|
40
|
-
word-break: break-all;
|
|
41
|
-
vertical-align: middle;
|
|
42
|
-
text-align: center;
|
|
43
|
-
&:first-child {
|
|
44
|
-
padding-left: 20px;
|
|
45
|
-
}
|
|
46
|
-
&:last-child {
|
|
47
|
-
padding-right: 20px;
|
|
48
|
-
}
|
|
49
|
-
&.gm-table-x-icon-column {
|
|
50
|
-
padding-right: 5px;
|
|
51
|
-
padding-left: 5px;
|
|
52
|
-
.gm-table-x-icon.gm-popover-active {
|
|
53
|
-
color: @brand-primary;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
img {
|
|
57
|
-
max-width: 100%;
|
|
58
|
-
max-height: 60px;
|
|
59
|
-
object-fit: contain;
|
|
60
|
-
vertical-align: middle;
|
|
61
|
-
display: block;
|
|
62
|
-
margin: 0 auto;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 保持与原版 TableX 一致的 expand 样式
|
|
66
|
-
.gm-table-x-expand {
|
|
67
|
-
font-size: 14px;
|
|
68
|
-
padding-top: 2px;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 二级表头的固定列边框处理(使用 inset box-shadow 创建边框,确保滚动时边框始终可见)
|
|
72
|
-
&.gm-table-x-fixed-left {
|
|
73
|
-
border-right: none !important;
|
|
74
|
-
box-shadow: inset -1px 0 0 0 @gm-table-x-border-color;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
&.gm-table-x-fixed-right {
|
|
78
|
-
border-left: none !important;
|
|
79
|
-
box-shadow: inset 1px 0 0 0 @gm-table-x-border-color;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
22
|
.gm-table-x-tr {
|
|
87
23
|
display: flex;
|
|
88
24
|
min-height: 60px;
|
|
@@ -144,77 +80,6 @@
|
|
|
144
80
|
}
|
|
145
81
|
}
|
|
146
82
|
|
|
147
|
-
// 二级表头样式
|
|
148
|
-
// 注意:为了支持 rowspan,二级表头需要使用原生的表格布局模型
|
|
149
|
-
.gm-table-x-thead-two-level {
|
|
150
|
-
display: table-header-group !important;
|
|
151
|
-
|
|
152
|
-
.gm-table-x-tr-first-level {
|
|
153
|
-
display: table-row !important;
|
|
154
|
-
|
|
155
|
-
.gm-table-x-th-first-level {
|
|
156
|
-
// 第一级表头样式
|
|
157
|
-
display: table-cell !important;
|
|
158
|
-
border: none !important;
|
|
159
|
-
vertical-align: middle;
|
|
160
|
-
text-align: center;
|
|
161
|
-
padding: 8px;
|
|
162
|
-
flex: none !important;
|
|
163
|
-
// 确保固定列有背景色,这样边框才能正确显示
|
|
164
|
-
background: @gm-table-x-header-bg !important;
|
|
165
|
-
position: relative;
|
|
166
|
-
|
|
167
|
-
// 使用伪元素创建所有边框
|
|
168
|
-
&::before {
|
|
169
|
-
content: '';
|
|
170
|
-
position: absolute;
|
|
171
|
-
top: 0;
|
|
172
|
-
left: 0;
|
|
173
|
-
right: 0;
|
|
174
|
-
bottom: 0;
|
|
175
|
-
border: 1px solid #d8dee7;
|
|
176
|
-
border-bottom-width: 2px;
|
|
177
|
-
pointer-events: none;
|
|
178
|
-
z-index: 1;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
.gm-table-x-tr-second-level {
|
|
184
|
-
display: table-row !important;
|
|
185
|
-
.gm-table-x-th-second-level {
|
|
186
|
-
// 第二级表头样式
|
|
187
|
-
display: table-cell !important;
|
|
188
|
-
border: none !important;
|
|
189
|
-
vertical-align: middle;
|
|
190
|
-
text-align: center;
|
|
191
|
-
padding: 8px;
|
|
192
|
-
flex: none !important;
|
|
193
|
-
flex-grow: unset !important;
|
|
194
|
-
flex-shrink: unset !important;
|
|
195
|
-
flex-basis: unset !important;
|
|
196
|
-
box-sizing: border-box;
|
|
197
|
-
// 确保固定列有背景色,这样边框才能正确显示
|
|
198
|
-
background: @gm-table-x-header-bg !important;
|
|
199
|
-
position: relative;
|
|
200
|
-
|
|
201
|
-
// 使用伪元素创建所有边框(除了顶部,因为顶部由一级表头的底部边框覆盖)
|
|
202
|
-
&::before {
|
|
203
|
-
content: '';
|
|
204
|
-
position: absolute;
|
|
205
|
-
top: 0;
|
|
206
|
-
left: 0;
|
|
207
|
-
right: 0;
|
|
208
|
-
bottom: 0;
|
|
209
|
-
border: 1px solid #d8dee7;
|
|
210
|
-
border-top: none;
|
|
211
|
-
pointer-events: none;
|
|
212
|
-
z-index: 1;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
83
|
.gm-table-x-tbody {
|
|
219
84
|
display: block; // 覆盖tbody 默认display
|
|
220
85
|
|
|
@@ -346,30 +211,13 @@
|
|
|
346
211
|
position: sticky !important;
|
|
347
212
|
z-index: 1;
|
|
348
213
|
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// 表头固定列需要更高的 z-index
|
|
352
|
-
.gm-table-x-th {
|
|
353
|
-
&.gm-table-x-fixed-left,
|
|
354
|
-
&.gm-table-x-fixed-right {
|
|
355
|
-
z-index: 11 !important;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
214
|
|
|
359
|
-
// tbody 单元格固定列使用 inset box-shadow
|
|
360
|
-
.gm-table-x-td {
|
|
361
215
|
&.gm-table-x-fixed-left {
|
|
362
|
-
border-right:
|
|
363
|
-
// 使用 box-shadow 创建边框,确保在滚动时边框始终可见
|
|
364
|
-
// inset box-shadow 会创建内部阴影,不会随内容滚动
|
|
365
|
-
box-shadow: inset -1px 0 0 0 @gm-table-x-border-color !important;
|
|
216
|
+
border-right: 1px solid @gm-table-x-border-color !important;
|
|
366
217
|
}
|
|
367
218
|
|
|
368
219
|
&.gm-table-x-fixed-right {
|
|
369
|
-
border-left:
|
|
370
|
-
// 使用 box-shadow 创建边框,确保在滚动时边框始终可见
|
|
371
|
-
// inset box-shadow 会创建内部阴影,不会随内容滚动
|
|
372
|
-
box-shadow: inset 1px 0 0 0 @gm-table-x-border-color !important;
|
|
220
|
+
border-left: 1px solid @gm-table-x-border-color !important;
|
|
373
221
|
}
|
|
374
222
|
}
|
|
375
223
|
}
|
|
@@ -584,7 +432,7 @@
|
|
|
584
432
|
}
|
|
585
433
|
}
|
|
586
434
|
|
|
587
|
-
.gm-react-table-x-diy-modal-content
|
|
435
|
+
.gm-react-table-x-diy-modal-content{
|
|
588
436
|
border-top: 1px solid @gm-table-x-border-color;
|
|
589
437
|
border-bottom: 1px solid @gm-table-x-border-color;
|
|
590
438
|
}
|
package/src/util/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import PropTypes from 'prop-types'
|
|
|
5
5
|
import _ from 'lodash'
|
|
6
6
|
import SVGEmpty from '../../svg/empty.svg'
|
|
7
7
|
import { Flex, EVENT_TYPE } from '@gmfe/react'
|
|
8
|
-
import BatchActionBar from '
|
|
9
|
-
import SortHeader from '
|
|
8
|
+
import BatchActionBar from './batch_action_bar'
|
|
9
|
+
import SortHeader from './sort_header'
|
|
10
10
|
import {
|
|
11
11
|
OperationHeader,
|
|
12
12
|
OperationDelete,
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
OperationCell,
|
|
16
16
|
OperationRowEdit,
|
|
17
17
|
OperationIconTip
|
|
18
|
-
} from '
|
|
19
|
-
import { EditButton, EditOperation } from '
|
|
18
|
+
} from './operation'
|
|
19
|
+
import { EditButton, EditOperation } from './edit'
|
|
20
20
|
|
|
21
21
|
const TABLE_X_SELECT_ID = 'table_x_select_id'
|
|
22
22
|
const TABLE_X_EXPAND_ID = 'table_x_expand_id'
|
|
@@ -83,14 +83,12 @@ const Empty = () => {
|
|
|
83
83
|
)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const Loading = (
|
|
86
|
+
const Loading = () => {
|
|
87
87
|
return (
|
|
88
88
|
<Mask
|
|
89
89
|
style={{
|
|
90
|
-
backgroundColor: 'rgba(255,255,255,0.8)'
|
|
91
|
-
...style
|
|
90
|
+
backgroundColor: 'rgba(255,255,255,0.8)'
|
|
92
91
|
}}
|
|
93
|
-
{...rest}
|
|
94
92
|
>
|
|
95
93
|
{getLocale('加载数据中...')}
|
|
96
94
|
</Mask>
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 扁平化 columns(用于 select 和 diy 处理)
|
|
3
|
-
* 将带有 subColumns 的 columns 展开为扁平结构
|
|
4
|
-
*
|
|
5
|
-
* 对于有 subColumns 的列,会给每个 subColumn 添加:
|
|
6
|
-
* - parentKey: 父级列的 id(用于重建时识别分组)
|
|
7
|
-
* - parentHeader: 父级列的 Header(用于重建时显示一级表头)
|
|
8
|
-
* - parentFixed: 父级列的 fixed 属性(用于重建时设置 fixed)
|
|
9
|
-
*/
|
|
10
|
-
export function flattenColumnsForSelectAndDiy(columns) {
|
|
11
|
-
const flattened = []
|
|
12
|
-
columns.forEach(column => {
|
|
13
|
-
if (column.subColumns && column.subColumns.length > 0) {
|
|
14
|
-
column.subColumns.forEach(subCol => {
|
|
15
|
-
const { fixed: _subColFixed, ...subColWithoutFixed } = subCol
|
|
16
|
-
flattened.push({
|
|
17
|
-
...subColWithoutFixed,
|
|
18
|
-
parentKey: column.id || column.Header, // 父级标识
|
|
19
|
-
parentHeader: column.Header,
|
|
20
|
-
parentFixed: column.fixed
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
} else {
|
|
24
|
-
// 没有 subColumns,直接添加
|
|
25
|
-
flattened.push(column)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
return flattened
|
|
29
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TABLE_X_SELECT_ID,
|
|
3
|
-
TABLE_X_DIY_ID,
|
|
4
|
-
TABLE_X_EXPAND_ID
|
|
5
|
-
} from '../../util'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 根据扁平化的 columns 重建嵌套结构
|
|
9
|
-
* 输入:
|
|
10
|
-
* - flatColumns: 处理后的扁平 columns(每个 subColumn 都带有 parentKey、parentHeader、parentFixed 属性)
|
|
11
|
-
* 输出:重建的嵌套结构(严格按照 flatColumns 的顺序输出)
|
|
12
|
-
*/
|
|
13
|
-
export function rebuildNestedColumnsFromFlat(flatColumns) {
|
|
14
|
-
const nested = []
|
|
15
|
-
const specialColumnIds = [
|
|
16
|
-
TABLE_X_SELECT_ID,
|
|
17
|
-
TABLE_X_DIY_ID,
|
|
18
|
-
TABLE_X_EXPAND_ID
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
// 普通列(排除特殊列)
|
|
22
|
-
const normalCols = flatColumns.filter(
|
|
23
|
-
col => !specialColumnIds.includes(col.id)
|
|
24
|
-
)
|
|
25
|
-
// 收集分组数据:parentKey -> { parentHeader, parentFixed, subCols: [] }
|
|
26
|
-
const groupMap = new Map()
|
|
27
|
-
|
|
28
|
-
// 遍历一次:收集所有分组的数据
|
|
29
|
-
normalCols.forEach(col => {
|
|
30
|
-
if (col.parentKey) {
|
|
31
|
-
// 有 parentKey:二级分类的子列
|
|
32
|
-
if (!groupMap.has(col.parentKey)) {
|
|
33
|
-
groupMap.set(col.parentKey, {
|
|
34
|
-
parentHeader: col.parentHeader,
|
|
35
|
-
parentFixed: col.parentFixed,
|
|
36
|
-
subCols: []
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
// 移除临时属性并添加到分组
|
|
40
|
-
const {
|
|
41
|
-
parentKey: _p,
|
|
42
|
-
parentHeader: _h,
|
|
43
|
-
parentFixed: parentFixedValue,
|
|
44
|
-
...colWithoutParent
|
|
45
|
-
} = col
|
|
46
|
-
const { fixed: _subColFixed, ...colWithoutFixed } = colWithoutParent
|
|
47
|
-
groupMap.get(col.parentKey).subCols.push({
|
|
48
|
-
...colWithoutFixed,
|
|
49
|
-
fixed: parentFixedValue
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// 再次遍历:按 flatColumns 的顺序输出普通列
|
|
55
|
-
const processedGroups = new Set()
|
|
56
|
-
|
|
57
|
-
normalCols.forEach(col => {
|
|
58
|
-
if (col.parentKey) {
|
|
59
|
-
// 有 parentKey:在第一次遇到的位置输出分组
|
|
60
|
-
if (!processedGroups.has(col.parentKey)) {
|
|
61
|
-
processedGroups.add(col.parentKey)
|
|
62
|
-
const group = groupMap.get(col.parentKey)
|
|
63
|
-
const visibleSubCols = group.subCols.filter(
|
|
64
|
-
subCol => subCol.show !== false
|
|
65
|
-
)
|
|
66
|
-
if (visibleSubCols.length > 0) {
|
|
67
|
-
nested.push({
|
|
68
|
-
Header: group.parentHeader,
|
|
69
|
-
id: col.parentKey,
|
|
70
|
-
fixed: group.parentFixed,
|
|
71
|
-
subColumns: visibleSubCols
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
// 无 parentKey:单独列,直接输出
|
|
77
|
-
if (col.show !== false) {
|
|
78
|
-
nested.push(col)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
// 特殊列(select、diy、expand)的处理
|
|
84
|
-
// 从 flatColumns 中提取特殊列,保持它们在 flatColumns 中的相对顺序
|
|
85
|
-
const specialCols = flatColumns.filter(col =>
|
|
86
|
-
specialColumnIds.includes(col.id)
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
// 分离 fixed: 'left' 的特殊列和其他特殊列
|
|
90
|
-
const leftFixedSpecialCols = specialCols.filter(col => col.fixed === 'left')
|
|
91
|
-
const otherSpecialCols = specialCols.filter(col => col.fixed !== 'left')
|
|
92
|
-
|
|
93
|
-
// 按顺序:fixed: 'left' 的特殊列 -> 普通列 -> 其他特殊列
|
|
94
|
-
return [...leftFixedSpecialCols, ...nested, ...otherSpecialCols]
|
|
95
|
-
}
|