@gmfe/table-x 2.14.26 → 2.14.30-alpha.0
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/LICENSE +16 -0
- package/package.json +5 -4
- package/src/base/index.js +2 -1
- package/src/base/thead.js +1 -1
- package/src/hoc/sticky_layout.js +149 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present, gmfe contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmfe/table-x",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.30-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gmfe#readme",
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gm-common/tool": "^1.0.0",
|
|
30
|
-
"@gmfe/
|
|
31
|
-
"@gmfe/
|
|
30
|
+
"@gmfe/business": "^2.14.30-alpha.0",
|
|
31
|
+
"@gmfe/locales": "^2.14.30-alpha.0",
|
|
32
|
+
"@gmfe/react": "^2.14.30-alpha.0",
|
|
32
33
|
"classnames": "^2.2.5",
|
|
33
34
|
"lodash": "^4.17.14",
|
|
34
35
|
"prop-types": "^15.7.2",
|
|
@@ -36,5 +37,5 @@
|
|
|
36
37
|
"react-window": "^1.8.5",
|
|
37
38
|
"sortablejs": "^1.10.1"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f7da14010d37550f0a19949fe4a5b3d65301545a"
|
|
40
41
|
}
|
package/src/base/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import classNames from 'classnames'
|
|
|
6
6
|
import _ from 'lodash'
|
|
7
7
|
import THead from './thead'
|
|
8
8
|
import Tr from './tr'
|
|
9
|
+
import { StickyLayout } from '@gmfe/react'
|
|
9
10
|
|
|
10
11
|
// 给定初始值,交由getColumnStyle控制。width逻辑保持跟react-table(v6)的用法一致。
|
|
11
12
|
const defaultColumn = __DEFAULT_COLUMN
|
|
@@ -139,4 +140,4 @@ TableX.defaultProps = {
|
|
|
139
140
|
isTrHighlight: () => false
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
export default TableX
|
|
143
|
+
export default StickyLayout(TableX)
|
package/src/base/thead.js
CHANGED
|
@@ -4,7 +4,7 @@ import Th from './th'
|
|
|
4
4
|
|
|
5
5
|
const THead = ({ headerGroups, totalWidth }) => {
|
|
6
6
|
return (
|
|
7
|
-
<thead className='gm-table-x-thead'>
|
|
7
|
+
<thead className='gm-table-x-thead common-sticky-header'>
|
|
8
8
|
{headerGroups.map((headerGroup, i) => (
|
|
9
9
|
<tr key={i} className='gm-table-x-tr'>
|
|
10
10
|
{headerGroup.headers.map((column, i) => (
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: stanfer
|
|
3
|
+
* @description:
|
|
4
|
+
* @createDate: 2025/11/24 11:05
|
|
5
|
+
* @Version: 1.0
|
|
6
|
+
* @last modify time:
|
|
7
|
+
**/
|
|
8
|
+
import React, { useRef, useEffect } from 'react'
|
|
9
|
+
|
|
10
|
+
function stickyLayout(Component) {
|
|
11
|
+
const StickyLayout = ({ ...rest }) => {
|
|
12
|
+
const currentStickyRef = useRef(null);
|
|
13
|
+
const topSentinelRef = useRef(null);
|
|
14
|
+
const bottomSentinelRef = useRef(null);
|
|
15
|
+
// 统一管理
|
|
16
|
+
const observerRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!currentStickyRef.current) return;
|
|
20
|
+
|
|
21
|
+
const options = {
|
|
22
|
+
root: null, // 相对于浏览器视口
|
|
23
|
+
rootMargin: '0px',
|
|
24
|
+
threshold: 0, // 只要有一个像素进入/离开视口就触发
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
observerRef.current = new IntersectionObserver((entries) => {
|
|
28
|
+
entries.forEach((entry) => {
|
|
29
|
+
const target = entry.target;
|
|
30
|
+
|
|
31
|
+
if (target === topSentinelRef.current) {
|
|
32
|
+
if (entry.isIntersecting) {
|
|
33
|
+
console.log('=======> 顶部进入');
|
|
34
|
+
let heightSum = 0, tableRoot;
|
|
35
|
+
const fullTab = document.querySelectorAll('.gm-framework-full-tabs')
|
|
36
|
+
const commonStickyHeader = document.querySelectorAll('.common-sticky-header')
|
|
37
|
+
const rtTable = document.querySelectorAll('.rt-table')
|
|
38
|
+
const rtTheadHeader = document.querySelectorAll('.rt-thead')
|
|
39
|
+
rtTheadHeader.forEach((el) => {
|
|
40
|
+
el.style.position = 'sticky';
|
|
41
|
+
el.style.top = 0;
|
|
42
|
+
el.style.zIndex = 10;
|
|
43
|
+
heightSum += el.offsetHeight + 10; // 元素本身高 + 上下 10 padding
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
commonStickyHeader.forEach((item, idx) => {
|
|
47
|
+
if (fullTab.length) {
|
|
48
|
+
currentStickyRef.current.style.zIndex = 101;
|
|
49
|
+
}
|
|
50
|
+
// console.log(item.className);
|
|
51
|
+
if (item.className.includes('gm-box-table-header')) {
|
|
52
|
+
heightSum += item.offsetHeight + 10; // 元素本身高 + 上下 10 padding
|
|
53
|
+
// console.log(idx, item.getBoundingClientRect(), 'gm-box-table-header: ', item.getBoundingClientRect().height + 20);
|
|
54
|
+
}
|
|
55
|
+
if (item.className.includes('gm-table-x-thead')) {
|
|
56
|
+
heightSum += item.offsetHeight + 8; // 元素本身高 + 上下 8 padding
|
|
57
|
+
tableRoot = item.parentElement.parentElement;
|
|
58
|
+
// console.log(idx, item.getBoundingClientRect(), 'gm-table-x-thead: ', item.getBoundingClientRect().height + 16);
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (rtTable.length) {
|
|
63
|
+
rtTable.forEach((el) => {
|
|
64
|
+
if (fullTab.length) {
|
|
65
|
+
el.style.maxHeight = `calc(100vh - ${heightSum + (fullTab.length * 40) + 50}px)`; // +50 顶部导航栏
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
el.style.maxHeight = `calc(100vh - ${heightSum + 50}px)`; // +50 顶部导航栏
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
if (tableRoot) {
|
|
72
|
+
if (fullTab.length) {
|
|
73
|
+
tableRoot.style.maxHeight = `calc(100vh - ${heightSum + (fullTab.length * 40) + 50}px)`; // +50 顶部导航栏
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
tableRoot.style.maxHeight = `calc(100vh - ${heightSum + 50}px)`; // +50 顶部导航栏
|
|
77
|
+
}
|
|
78
|
+
// currentStickyRef.current.style.maxHeight = 'unset';
|
|
79
|
+
console.log('currentStickyRef 实例:', currentStickyRef.current.style);
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
currentStickyRef.current.style.maxHeight = '50%'; // TODO: 这块需要之后要走外部参数
|
|
83
|
+
console.log('顶部离开 <========');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (target === bottomSentinelRef.current) {
|
|
87
|
+
if (entry.isIntersecting) {
|
|
88
|
+
console.log('=======> 底部进入');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
console.log('底部离开 <========');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}, options);
|
|
95
|
+
|
|
96
|
+
if (topSentinelRef.current) {
|
|
97
|
+
observerRef.current.observe(topSentinelRef.current);
|
|
98
|
+
}
|
|
99
|
+
if (bottomSentinelRef.current) {
|
|
100
|
+
observerRef.current.observe(bottomSentinelRef.current);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return () => {
|
|
104
|
+
if (observerRef.current) {
|
|
105
|
+
observerRef.current.disconnect();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}, [])
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div ref={currentStickyRef} className='common-sticky-layout'>
|
|
112
|
+
<div
|
|
113
|
+
ref={topSentinelRef}
|
|
114
|
+
sentinel="topSentinel"
|
|
115
|
+
style={{
|
|
116
|
+
position: 'absolute',
|
|
117
|
+
top: '0',
|
|
118
|
+
left: '0',
|
|
119
|
+
width: '100%',
|
|
120
|
+
height: '1px', // 尽量小,不占空间
|
|
121
|
+
pointerEvents: 'none', // 防止它拦截任何鼠标事件
|
|
122
|
+
backgroundColor: 'transparent', // 完全透明
|
|
123
|
+
}}
|
|
124
|
+
/>
|
|
125
|
+
<Component {...rest} />
|
|
126
|
+
<div
|
|
127
|
+
ref={bottomSentinelRef}
|
|
128
|
+
sentinel="bottomSentinel"
|
|
129
|
+
style={{
|
|
130
|
+
position: 'absolute',
|
|
131
|
+
bottom: '0',
|
|
132
|
+
left: '0',
|
|
133
|
+
width: '100%',
|
|
134
|
+
height: '1px',
|
|
135
|
+
pointerEvents: 'none',
|
|
136
|
+
backgroundColor: 'transparent',
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
StickyLayout.propTypes = StickyLayout.propTypes;
|
|
144
|
+
StickyLayout.defaultProps = StickyLayout.defaultProps;
|
|
145
|
+
|
|
146
|
+
return StickyLayout
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default stickyLayout
|