bhd-components 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{6a77b797.esm.es5.development.js → 88060020.esm.es5.development.js} +18680 -17303
- package/dist/e40d2239.esm.es5.production.js +228 -0
- package/dist/table.esm.es5.development.css +32 -18
- package/dist/table.esm.es5.development.js +59 -210
- package/dist/table.esm.es5.production.css +1 -1
- package/dist/table.esm.es5.production.js +1 -1
- package/es2017/icons/index.d.ts +1 -0
- package/es2017/icons/index.js +1 -0
- package/es2017/index.d.ts +2 -2
- package/es2017/index.js +2 -2
- package/es2017/table/index.d.ts +10 -1
- package/es2017/table/index.js +46 -19
- package/es2017/table/index.module.less +12 -0
- package/es2017/table/{index/347/232/204/345/211/257/346/234/254.js → index22.js} +11 -40
- package/esm/icons/index.d.ts +1 -0
- package/esm/icons/index.js +1 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/table/index.d.ts +10 -1
- package/esm/table/index.js +48 -19
- package/esm/table/index.module.less +12 -0
- package/esm/table/{index/347/232/204/345/211/257/346/234/254.js → index22.js} +11 -42
- package/package.json +3 -2
- package/dist/7fed7be7.esm.es5.production.js +0 -211
- /package/es2017/table/{index/347/232/204/345/211/257/346/234/254.d.ts" → index22.d.ts} +0 -0
- /package/esm/table/{index/347/232/204/345/211/257/346/234/254.d.ts" → index22.d.ts} +0 -0
package/es2017/table/index.js
CHANGED
|
@@ -8,25 +8,43 @@ import { Table as AntdTable } from "antd";
|
|
|
8
8
|
import TextTootip from "../textTootip";
|
|
9
9
|
const widthPercentage = /^\d+%$/;
|
|
10
10
|
const widthPx = /^\d+px$/;
|
|
11
|
+
/* 获取元素的宽度 */ const getElementPadding = (node)=>{
|
|
12
|
+
let computedStyle = {};
|
|
13
|
+
if (window.getComputedStyle) computedStyle = getComputedStyle(node, null);
|
|
14
|
+
else computedStyle = node.currentStyle; //兼容IE的写法
|
|
15
|
+
return parseFloat(computedStyle["padding-left"]) + parseFloat(computedStyle["padding-right"]);
|
|
16
|
+
};
|
|
17
|
+
//获取宽度
|
|
18
|
+
const getParentWidth = (node)=>{
|
|
19
|
+
try {
|
|
20
|
+
while(node && node.nodeName !== "TD")node = node.parentElement;
|
|
21
|
+
let padding = getElementPadding(node);
|
|
22
|
+
return node.clientWidth - padding;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
11
27
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
12
28
|
//传入的参数为onCell==>需要进行函数合并
|
|
13
29
|
const Table = (props)=>{
|
|
14
|
-
const
|
|
30
|
+
const tableRef = useRef(null);
|
|
31
|
+
const timerRef = useRef({
|
|
32
|
+
timer: null
|
|
33
|
+
});
|
|
15
34
|
const { defaultWidthRang =[
|
|
16
35
|
180,
|
|
17
36
|
240,
|
|
18
37
|
320
|
|
19
|
-
] } = props;
|
|
38
|
+
] , isFixedLeft =true , isFixedRight =true } = props;
|
|
20
39
|
const [columns, setColumns] = useState(props.columns || []);
|
|
21
40
|
const [scrollObject, setScrollObject] = useState(props.scroll || undefined);
|
|
22
41
|
let { columnTootipClassName , columnTootipColor } = props;
|
|
23
42
|
const initColumns = ()=>{
|
|
24
|
-
let { columns: selfColumns
|
|
43
|
+
let { columns: selfColumns } = initColumnsWidth(props.columns, tableRef.current.offsetWidth);
|
|
25
44
|
setColumns(selfColumns);
|
|
26
45
|
let obj = scrollObject ? scrollObject : {};
|
|
27
46
|
obj = _object_spread_props(_object_spread({}, obj), {
|
|
28
|
-
|
|
29
|
-
x: ref.current.offsetWidth
|
|
47
|
+
x: tableRef.current.offsetWidth
|
|
30
48
|
});
|
|
31
49
|
setScrollObject(obj);
|
|
32
50
|
};
|
|
@@ -62,7 +80,7 @@ const Table = (props)=>{
|
|
|
62
80
|
};
|
|
63
81
|
item.render = (text)=>{
|
|
64
82
|
return /*#__PURE__*/ _jsx(TextTootip, {
|
|
65
|
-
width:
|
|
83
|
+
width: (e)=>getParentWidth(e.target),
|
|
66
84
|
title: text,
|
|
67
85
|
trigger: "hover",
|
|
68
86
|
overlayClassName: columnTootipClassName || styles.columnTootipClassName,
|
|
@@ -91,6 +109,7 @@ const Table = (props)=>{
|
|
|
91
109
|
}
|
|
92
110
|
return item;
|
|
93
111
|
});
|
|
112
|
+
// console.log("diffdiff",diff,tableWidth,minWidth,avgWidth,columns,autoNum)
|
|
94
113
|
columns = columns.map((item, index)=>{
|
|
95
114
|
//存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
|
|
96
115
|
if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
|
|
@@ -98,7 +117,8 @@ const Table = (props)=>{
|
|
|
98
117
|
});
|
|
99
118
|
} else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
|
|
100
119
|
columns = columns.map((item, index)=>{
|
|
101
|
-
if (
|
|
120
|
+
if (isFixedLeft && index === 0) item.fixed = "left";
|
|
121
|
+
if (isFixedRight && index === columns.length - 1) item.fixed = "right";
|
|
102
122
|
if (item.width === "auto") item.width = item.widthRang[1];
|
|
103
123
|
return item;
|
|
104
124
|
});
|
|
@@ -117,6 +137,7 @@ const Table = (props)=>{
|
|
|
117
137
|
}, obj.style)
|
|
118
138
|
});
|
|
119
139
|
};
|
|
140
|
+
console.log("宽度宽度", item, item.width, item.widthRang);
|
|
120
141
|
return item;
|
|
121
142
|
});
|
|
122
143
|
return {
|
|
@@ -124,11 +145,18 @@ const Table = (props)=>{
|
|
|
124
145
|
scrollWidth
|
|
125
146
|
};
|
|
126
147
|
};
|
|
148
|
+
const onResize = ()=>{
|
|
149
|
+
clearTimeout(timerRef.current.timer);
|
|
150
|
+
timerRef.current.timer = setTimeout(()=>{
|
|
151
|
+
initColumns();
|
|
152
|
+
}, 1000);
|
|
153
|
+
};
|
|
127
154
|
useEffect(()=>{
|
|
128
155
|
initColumns();
|
|
129
|
-
|
|
156
|
+
window.addEventListener("resize", onResize);
|
|
130
157
|
return ()=>{
|
|
131
|
-
|
|
158
|
+
clearTimeout(timerRef.current.timer);
|
|
159
|
+
window.removeEventListener("resize", onResize);
|
|
132
160
|
};
|
|
133
161
|
}, [
|
|
134
162
|
props.columns
|
|
@@ -138,23 +166,22 @@ const Table = (props)=>{
|
|
|
138
166
|
}, props), {
|
|
139
167
|
columns,
|
|
140
168
|
scroll: scrollObject || {
|
|
141
|
-
x: "
|
|
169
|
+
x: "auto"
|
|
142
170
|
}
|
|
143
171
|
});
|
|
144
|
-
console.log("scrollObjectscrollObject", scrollObject, config);
|
|
145
172
|
return /*#__PURE__*/ _jsx("div", {
|
|
146
173
|
className: styles.Table,
|
|
147
|
-
ref:
|
|
174
|
+
ref: tableRef,
|
|
148
175
|
children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
|
|
149
176
|
});
|
|
150
177
|
};
|
|
151
178
|
// let BhdTable=Provider(Table)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
179
|
+
Table.SELECTION_COLUMN = AntdTable.SELECTION_COLUMN;
|
|
180
|
+
Table.EXPAND_COLUMN = AntdTable.EXPAND_COLUMN;
|
|
181
|
+
Table.SELECTION_ALL = AntdTable.SELECTION_ALL;
|
|
182
|
+
Table.SELECTION_INVERT = AntdTable.SELECTION_INVERT;
|
|
183
|
+
Table.SELECTION_NONE = AntdTable.SELECTION_NONE;
|
|
184
|
+
Table.Column = AntdTable.Column;
|
|
185
|
+
Table.ColumnGroup = AntdTable.ColumnGroup;
|
|
159
186
|
// Table.Summary = AntdTable.Summary;
|
|
160
187
|
export default Table;
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
&:last-child {
|
|
55
55
|
padding-right: 40px;
|
|
56
56
|
}
|
|
57
|
+
/* 多选框 距右的距离 */
|
|
58
|
+
&.bhd-table-selection-column{
|
|
59
|
+
padding-inline-end:16px;
|
|
60
|
+
}
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
@@ -67,6 +71,14 @@
|
|
|
67
71
|
.bhd-table-tbody > tr.bhd-table-row-selected > td {
|
|
68
72
|
background: #ffffff;
|
|
69
73
|
}
|
|
74
|
+
|
|
75
|
+
/* scroll 固定列 设置overflow:hidden 阴影消失问题 */
|
|
76
|
+
.bhd-table-cell-fix-left-first::after,.bhd-table-cell-fix-left-last::after{
|
|
77
|
+
right: 2px;
|
|
78
|
+
}
|
|
79
|
+
.bhd-table-cell-fix-right-first::after,.bhd-table-cell-fix-right-last::after{
|
|
80
|
+
left: 2px;
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
}
|
|
@@ -8,43 +8,25 @@ import { Table as AntdTable } from "antd";
|
|
|
8
8
|
import TextTootip from "../textTootip";
|
|
9
9
|
const widthPercentage = /^\d+%$/;
|
|
10
10
|
const widthPx = /^\d+px$/;
|
|
11
|
-
/* 获取元素的宽度 */ const getElementPadding = (node)=>{
|
|
12
|
-
let computedStyle = {};
|
|
13
|
-
if (window.getComputedStyle) computedStyle = getComputedStyle(node, null);
|
|
14
|
-
else computedStyle = node.currentStyle; //兼容IE的写法
|
|
15
|
-
return parseFloat(computedStyle["padding-left"]) + parseFloat(computedStyle["padding-right"]);
|
|
16
|
-
};
|
|
17
|
-
//获取宽度
|
|
18
|
-
const getParentWidth = (node)=>{
|
|
19
|
-
try {
|
|
20
|
-
while(node && node.nodeName !== "TD")node = node.parentElement;
|
|
21
|
-
let padding = getElementPadding(node);
|
|
22
|
-
return node.clientWidth - padding;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
11
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
28
12
|
//传入的参数为onCell==>需要进行函数合并
|
|
29
13
|
const Table = (props)=>{
|
|
30
|
-
const
|
|
31
|
-
const timerRef = useRef({
|
|
32
|
-
timer: null
|
|
33
|
-
});
|
|
14
|
+
const ref = useRef(null);
|
|
34
15
|
const { defaultWidthRang =[
|
|
35
16
|
180,
|
|
36
17
|
240,
|
|
37
18
|
320
|
|
38
|
-
]
|
|
19
|
+
] } = props;
|
|
39
20
|
const [columns, setColumns] = useState(props.columns || []);
|
|
40
21
|
const [scrollObject, setScrollObject] = useState(props.scroll || undefined);
|
|
41
22
|
let { columnTootipClassName , columnTootipColor } = props;
|
|
42
23
|
const initColumns = ()=>{
|
|
43
|
-
let { columns: selfColumns } = initColumnsWidth(props.columns,
|
|
24
|
+
let { columns: selfColumns , scrollWidth } = initColumnsWidth(props.columns, ref.current.offsetWidth);
|
|
44
25
|
setColumns(selfColumns);
|
|
45
26
|
let obj = scrollObject ? scrollObject : {};
|
|
46
27
|
obj = _object_spread_props(_object_spread({}, obj), {
|
|
47
|
-
x:
|
|
28
|
+
// x: scrollWidth,
|
|
29
|
+
x: ref.current.offsetWidth
|
|
48
30
|
});
|
|
49
31
|
setScrollObject(obj);
|
|
50
32
|
};
|
|
@@ -80,7 +62,7 @@ const Table = (props)=>{
|
|
|
80
62
|
};
|
|
81
63
|
item.render = (text)=>{
|
|
82
64
|
return /*#__PURE__*/ _jsx(TextTootip, {
|
|
83
|
-
width:
|
|
65
|
+
width: item.width,
|
|
84
66
|
title: text,
|
|
85
67
|
trigger: "hover",
|
|
86
68
|
overlayClassName: columnTootipClassName || styles.columnTootipClassName,
|
|
@@ -109,7 +91,6 @@ const Table = (props)=>{
|
|
|
109
91
|
}
|
|
110
92
|
return item;
|
|
111
93
|
});
|
|
112
|
-
console.log("diffdiff", diff, tableWidth, minWidth, avgWidth, columns, autoNum);
|
|
113
94
|
columns = columns.map((item, index)=>{
|
|
114
95
|
//存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
|
|
115
96
|
if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
|
|
@@ -117,8 +98,7 @@ const Table = (props)=>{
|
|
|
117
98
|
});
|
|
118
99
|
} else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
|
|
119
100
|
columns = columns.map((item, index)=>{
|
|
120
|
-
if (
|
|
121
|
-
if (isFixedRight && index === columns.length - 1) item.fixed = "right";
|
|
101
|
+
if (index === 0 || index === columns.length - 1) item.fixed = index === 0 ? "left" : "right";
|
|
122
102
|
if (item.width === "auto") item.width = item.widthRang[1];
|
|
123
103
|
return item;
|
|
124
104
|
});
|
|
@@ -137,7 +117,6 @@ const Table = (props)=>{
|
|
|
137
117
|
}, obj.style)
|
|
138
118
|
});
|
|
139
119
|
};
|
|
140
|
-
console.log("宽度宽度", item, item.width, item.widthRang);
|
|
141
120
|
return item;
|
|
142
121
|
});
|
|
143
122
|
return {
|
|
@@ -145,34 +124,26 @@ const Table = (props)=>{
|
|
|
145
124
|
scrollWidth
|
|
146
125
|
};
|
|
147
126
|
};
|
|
148
|
-
const onResize = ()=>{
|
|
149
|
-
clearTimeout(timerRef.current.timer);
|
|
150
|
-
timerRef.current.timer = setTimeout(()=>{
|
|
151
|
-
initColumns();
|
|
152
|
-
}, 1000);
|
|
153
|
-
};
|
|
154
127
|
useEffect(()=>{
|
|
155
128
|
initColumns();
|
|
156
|
-
window.addEventListener("resize",
|
|
129
|
+
window.addEventListener("resize", initColumns);
|
|
157
130
|
return ()=>{
|
|
158
|
-
|
|
159
|
-
window.removeEventListener("resize", onResize);
|
|
131
|
+
window.removeEventListener("resize", initColumns);
|
|
160
132
|
};
|
|
161
133
|
}, [
|
|
162
134
|
props.columns
|
|
163
135
|
]);
|
|
164
|
-
console.log("宽度宽度", scrollObject);
|
|
165
136
|
let config = _object_spread_props(_object_spread({
|
|
166
137
|
bordered: false
|
|
167
138
|
}, props), {
|
|
168
139
|
columns,
|
|
169
140
|
scroll: scrollObject || {
|
|
170
|
-
x: "
|
|
141
|
+
x: "none"
|
|
171
142
|
}
|
|
172
143
|
});
|
|
173
144
|
return /*#__PURE__*/ _jsx("div", {
|
|
174
145
|
className: styles.Table,
|
|
175
|
-
ref:
|
|
146
|
+
ref: ref,
|
|
176
147
|
children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
|
|
177
148
|
});
|
|
178
149
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@ant-design/icons';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@ant-design/icons";
|
package/esm/index.d.ts
CHANGED
|
@@ -68,6 +68,6 @@ export { default as QRCode } from 'antd/es/qrcode';
|
|
|
68
68
|
export { default as version } from 'antd/es/version';
|
|
69
69
|
export { default as Provider } from "./provider";
|
|
70
70
|
export { default as TextTootip } from "./textTootip";
|
|
71
|
-
export { default as zh_CN } from "antd/locale/
|
|
72
|
-
export { default as en_US } from "antd/locale/
|
|
71
|
+
export { default as zh_CN } from "antd/locale/zh_CN";
|
|
72
|
+
export { default as en_US } from "antd/locale/en_US";
|
|
73
73
|
export { default as Table } from "./table";
|
package/esm/index.js
CHANGED
|
@@ -70,6 +70,6 @@ export { default as QRCode } from "antd/es/qrcode";
|
|
|
70
70
|
export { default as version } from "antd/es/version";
|
|
71
71
|
/* 自定义修改 */ export { default as Provider } from "./provider/index";
|
|
72
72
|
export { default as TextTootip } from "./textTootip/index";
|
|
73
|
-
export { default as zh_CN } from "antd/locale/
|
|
74
|
-
export { default as en_US } from "antd/locale/
|
|
73
|
+
export { default as zh_CN } from "antd/locale/zh_CN";
|
|
74
|
+
export { default as en_US } from "antd/locale/en_US";
|
|
75
75
|
export { default as Table } from "./table/index"; //改写table逻辑
|
package/esm/table/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const Table:
|
|
2
|
+
declare const Table: {
|
|
3
|
+
(props: any): JSX.Element;
|
|
4
|
+
SELECTION_COLUMN: {};
|
|
5
|
+
EXPAND_COLUMN: {};
|
|
6
|
+
SELECTION_ALL: "SELECT_ALL";
|
|
7
|
+
SELECTION_INVERT: "SELECT_INVERT";
|
|
8
|
+
SELECTION_NONE: "SELECT_NONE";
|
|
9
|
+
Column: typeof import("antd/es/table/Column").default;
|
|
10
|
+
ColumnGroup: typeof import("antd/es/table/ColumnGroup").default;
|
|
11
|
+
};
|
|
3
12
|
export default Table;
|
package/esm/table/index.js
CHANGED
|
@@ -9,25 +9,43 @@ import { Table as AntdTable } from "antd";
|
|
|
9
9
|
import TextTootip from "../textTootip";
|
|
10
10
|
var widthPercentage = /^\d+%$/;
|
|
11
11
|
var widthPx = /^\d+px$/;
|
|
12
|
+
/* 获取元素的宽度 */ var getElementPadding = function(node) {
|
|
13
|
+
var computedStyle = {};
|
|
14
|
+
if (window.getComputedStyle) computedStyle = getComputedStyle(node, null);
|
|
15
|
+
else computedStyle = node.currentStyle; //兼容IE的写法
|
|
16
|
+
return parseFloat(computedStyle["padding-left"]) + parseFloat(computedStyle["padding-right"]);
|
|
17
|
+
};
|
|
18
|
+
//获取宽度
|
|
19
|
+
var getParentWidth = function(node) {
|
|
20
|
+
try {
|
|
21
|
+
while(node && node.nodeName !== "TD")node = node.parentElement;
|
|
22
|
+
var padding = getElementPadding(node);
|
|
23
|
+
return node.clientWidth - padding;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
12
28
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
13
29
|
//传入的参数为onCell==>需要进行函数合并
|
|
14
30
|
var Table = function(props) {
|
|
15
|
-
var
|
|
31
|
+
var tableRef = useRef(null);
|
|
32
|
+
var timerRef = useRef({
|
|
33
|
+
timer: null
|
|
34
|
+
});
|
|
16
35
|
var _props_defaultWidthRang = props.defaultWidthRang, defaultWidthRang = _props_defaultWidthRang === void 0 ? [
|
|
17
36
|
180,
|
|
18
37
|
240,
|
|
19
38
|
320
|
|
20
|
-
] : _props_defaultWidthRang;
|
|
39
|
+
] : _props_defaultWidthRang, _props_isFixedLeft = props.isFixedLeft, isFixedLeft = _props_isFixedLeft === void 0 ? true : _props_isFixedLeft, _props_isFixedRight = props.isFixedRight, isFixedRight = _props_isFixedRight === void 0 ? true : _props_isFixedRight;
|
|
21
40
|
var _useState = _sliced_to_array(useState(props.columns || []), 2), columns = _useState[0], setColumns = _useState[1];
|
|
22
41
|
var _useState1 = _sliced_to_array(useState(props.scroll || undefined), 2), scrollObject = _useState1[0], setScrollObject = _useState1[1];
|
|
23
42
|
var columnTootipClassName = props.columnTootipClassName, columnTootipColor = props.columnTootipColor;
|
|
24
43
|
var initColumns = function() {
|
|
25
|
-
var _initColumnsWidth = initColumnsWidth(props.columns,
|
|
44
|
+
var _initColumnsWidth = initColumnsWidth(props.columns, tableRef.current.offsetWidth), selfColumns = _initColumnsWidth.columns;
|
|
26
45
|
setColumns(selfColumns);
|
|
27
46
|
var obj = scrollObject ? scrollObject : {};
|
|
28
47
|
obj = _object_spread_props(_object_spread({}, obj), {
|
|
29
|
-
|
|
30
|
-
x: ref.current.offsetWidth
|
|
48
|
+
x: tableRef.current.offsetWidth
|
|
31
49
|
});
|
|
32
50
|
setScrollObject(obj);
|
|
33
51
|
};
|
|
@@ -65,7 +83,9 @@ var Table = function(props) {
|
|
|
65
83
|
};
|
|
66
84
|
item.render = function(text) {
|
|
67
85
|
return /*#__PURE__*/ _jsx(TextTootip, {
|
|
68
|
-
width:
|
|
86
|
+
width: function(e) {
|
|
87
|
+
return getParentWidth(e.target);
|
|
88
|
+
},
|
|
69
89
|
title: text,
|
|
70
90
|
trigger: "hover",
|
|
71
91
|
overlayClassName: columnTootipClassName || styles.columnTootipClassName,
|
|
@@ -94,6 +114,7 @@ var Table = function(props) {
|
|
|
94
114
|
}
|
|
95
115
|
return item;
|
|
96
116
|
});
|
|
117
|
+
// console.log("diffdiff",diff,tableWidth,minWidth,avgWidth,columns,autoNum)
|
|
97
118
|
columns = columns.map(function(item, index) {
|
|
98
119
|
//存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
|
|
99
120
|
if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
|
|
@@ -101,7 +122,8 @@ var Table = function(props) {
|
|
|
101
122
|
});
|
|
102
123
|
} else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
|
|
103
124
|
columns = columns.map(function(item, index) {
|
|
104
|
-
if (
|
|
125
|
+
if (isFixedLeft && index === 0) item.fixed = "left";
|
|
126
|
+
if (isFixedRight && index === columns.length - 1) item.fixed = "right";
|
|
105
127
|
if (item.width === "auto") item.width = item.widthRang[1];
|
|
106
128
|
return item;
|
|
107
129
|
});
|
|
@@ -120,6 +142,7 @@ var Table = function(props) {
|
|
|
120
142
|
}, obj.style)
|
|
121
143
|
});
|
|
122
144
|
};
|
|
145
|
+
console.log("宽度宽度", item, item.width, item.widthRang);
|
|
123
146
|
return item;
|
|
124
147
|
});
|
|
125
148
|
return {
|
|
@@ -127,11 +150,18 @@ var Table = function(props) {
|
|
|
127
150
|
scrollWidth: scrollWidth
|
|
128
151
|
};
|
|
129
152
|
};
|
|
153
|
+
var onResize = function() {
|
|
154
|
+
clearTimeout(timerRef.current.timer);
|
|
155
|
+
timerRef.current.timer = setTimeout(function() {
|
|
156
|
+
initColumns();
|
|
157
|
+
}, 1000);
|
|
158
|
+
};
|
|
130
159
|
useEffect(function() {
|
|
131
160
|
initColumns();
|
|
132
|
-
|
|
161
|
+
window.addEventListener("resize", onResize);
|
|
133
162
|
return function() {
|
|
134
|
-
|
|
163
|
+
clearTimeout(timerRef.current.timer);
|
|
164
|
+
window.removeEventListener("resize", onResize);
|
|
135
165
|
};
|
|
136
166
|
}, [
|
|
137
167
|
props.columns
|
|
@@ -141,23 +171,22 @@ var Table = function(props) {
|
|
|
141
171
|
}, props), {
|
|
142
172
|
columns: columns,
|
|
143
173
|
scroll: scrollObject || {
|
|
144
|
-
x: "
|
|
174
|
+
x: "auto"
|
|
145
175
|
}
|
|
146
176
|
});
|
|
147
|
-
console.log("scrollObjectscrollObject", scrollObject, config);
|
|
148
177
|
return /*#__PURE__*/ _jsx("div", {
|
|
149
178
|
className: styles.Table,
|
|
150
|
-
ref:
|
|
179
|
+
ref: tableRef,
|
|
151
180
|
children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
|
|
152
181
|
});
|
|
153
182
|
};
|
|
154
183
|
// let BhdTable=Provider(Table)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
Table.SELECTION_COLUMN = AntdTable.SELECTION_COLUMN;
|
|
185
|
+
Table.EXPAND_COLUMN = AntdTable.EXPAND_COLUMN;
|
|
186
|
+
Table.SELECTION_ALL = AntdTable.SELECTION_ALL;
|
|
187
|
+
Table.SELECTION_INVERT = AntdTable.SELECTION_INVERT;
|
|
188
|
+
Table.SELECTION_NONE = AntdTable.SELECTION_NONE;
|
|
189
|
+
Table.Column = AntdTable.Column;
|
|
190
|
+
Table.ColumnGroup = AntdTable.ColumnGroup;
|
|
162
191
|
// Table.Summary = AntdTable.Summary;
|
|
163
192
|
export default Table;
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
&:last-child {
|
|
55
55
|
padding-right: 40px;
|
|
56
56
|
}
|
|
57
|
+
/* 多选框 距右的距离 */
|
|
58
|
+
&.bhd-table-selection-column{
|
|
59
|
+
padding-inline-end:16px;
|
|
60
|
+
}
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
@@ -67,6 +71,14 @@
|
|
|
67
71
|
.bhd-table-tbody > tr.bhd-table-row-selected > td {
|
|
68
72
|
background: #ffffff;
|
|
69
73
|
}
|
|
74
|
+
|
|
75
|
+
/* scroll 固定列 设置overflow:hidden 阴影消失问题 */
|
|
76
|
+
.bhd-table-cell-fix-left-first::after,.bhd-table-cell-fix-left-last::after{
|
|
77
|
+
right: 2px;
|
|
78
|
+
}
|
|
79
|
+
.bhd-table-cell-fix-right-first::after,.bhd-table-cell-fix-right-last::after{
|
|
80
|
+
left: 2px;
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
}
|
|
@@ -9,43 +9,25 @@ import { Table as AntdTable } from "antd";
|
|
|
9
9
|
import TextTootip from "../textTootip";
|
|
10
10
|
var widthPercentage = /^\d+%$/;
|
|
11
11
|
var widthPx = /^\d+px$/;
|
|
12
|
-
/* 获取元素的宽度 */ var getElementPadding = function(node) {
|
|
13
|
-
var computedStyle = {};
|
|
14
|
-
if (window.getComputedStyle) computedStyle = getComputedStyle(node, null);
|
|
15
|
-
else computedStyle = node.currentStyle; //兼容IE的写法
|
|
16
|
-
return parseFloat(computedStyle["padding-left"]) + parseFloat(computedStyle["padding-right"]);
|
|
17
|
-
};
|
|
18
|
-
//获取宽度
|
|
19
|
-
var getParentWidth = function(node) {
|
|
20
|
-
try {
|
|
21
|
-
while(node && node.nodeName !== "TD")node = node.parentElement;
|
|
22
|
-
var padding = getElementPadding(node);
|
|
23
|
-
return node.clientWidth - padding;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
12
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
29
13
|
//传入的参数为onCell==>需要进行函数合并
|
|
30
14
|
var Table = function(props) {
|
|
31
|
-
var
|
|
32
|
-
var timerRef = useRef({
|
|
33
|
-
timer: null
|
|
34
|
-
});
|
|
15
|
+
var ref = useRef(null);
|
|
35
16
|
var _props_defaultWidthRang = props.defaultWidthRang, defaultWidthRang = _props_defaultWidthRang === void 0 ? [
|
|
36
17
|
180,
|
|
37
18
|
240,
|
|
38
19
|
320
|
|
39
|
-
] : _props_defaultWidthRang
|
|
20
|
+
] : _props_defaultWidthRang;
|
|
40
21
|
var _useState = _sliced_to_array(useState(props.columns || []), 2), columns = _useState[0], setColumns = _useState[1];
|
|
41
22
|
var _useState1 = _sliced_to_array(useState(props.scroll || undefined), 2), scrollObject = _useState1[0], setScrollObject = _useState1[1];
|
|
42
23
|
var columnTootipClassName = props.columnTootipClassName, columnTootipColor = props.columnTootipColor;
|
|
43
24
|
var initColumns = function() {
|
|
44
|
-
var _initColumnsWidth = initColumnsWidth(props.columns,
|
|
25
|
+
var _initColumnsWidth = initColumnsWidth(props.columns, ref.current.offsetWidth), selfColumns = _initColumnsWidth.columns, scrollWidth = _initColumnsWidth.scrollWidth;
|
|
45
26
|
setColumns(selfColumns);
|
|
46
27
|
var obj = scrollObject ? scrollObject : {};
|
|
47
28
|
obj = _object_spread_props(_object_spread({}, obj), {
|
|
48
|
-
x:
|
|
29
|
+
// x: scrollWidth,
|
|
30
|
+
x: ref.current.offsetWidth
|
|
49
31
|
});
|
|
50
32
|
setScrollObject(obj);
|
|
51
33
|
};
|
|
@@ -83,9 +65,7 @@ var Table = function(props) {
|
|
|
83
65
|
};
|
|
84
66
|
item.render = function(text) {
|
|
85
67
|
return /*#__PURE__*/ _jsx(TextTootip, {
|
|
86
|
-
width:
|
|
87
|
-
return getParentWidth(e.target);
|
|
88
|
-
},
|
|
68
|
+
width: item.width,
|
|
89
69
|
title: text,
|
|
90
70
|
trigger: "hover",
|
|
91
71
|
overlayClassName: columnTootipClassName || styles.columnTootipClassName,
|
|
@@ -114,7 +94,6 @@ var Table = function(props) {
|
|
|
114
94
|
}
|
|
115
95
|
return item;
|
|
116
96
|
});
|
|
117
|
-
console.log("diffdiff", diff, tableWidth, minWidth, avgWidth, columns, autoNum);
|
|
118
97
|
columns = columns.map(function(item, index) {
|
|
119
98
|
//存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
|
|
120
99
|
if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
|
|
@@ -122,8 +101,7 @@ var Table = function(props) {
|
|
|
122
101
|
});
|
|
123
102
|
} else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
|
|
124
103
|
columns = columns.map(function(item, index) {
|
|
125
|
-
if (
|
|
126
|
-
if (isFixedRight && index === columns.length - 1) item.fixed = "right";
|
|
104
|
+
if (index === 0 || index === columns.length - 1) item.fixed = index === 0 ? "left" : "right";
|
|
127
105
|
if (item.width === "auto") item.width = item.widthRang[1];
|
|
128
106
|
return item;
|
|
129
107
|
});
|
|
@@ -142,7 +120,6 @@ var Table = function(props) {
|
|
|
142
120
|
}, obj.style)
|
|
143
121
|
});
|
|
144
122
|
};
|
|
145
|
-
console.log("宽度宽度", item, item.width, item.widthRang);
|
|
146
123
|
return item;
|
|
147
124
|
});
|
|
148
125
|
return {
|
|
@@ -150,34 +127,26 @@ var Table = function(props) {
|
|
|
150
127
|
scrollWidth: scrollWidth
|
|
151
128
|
};
|
|
152
129
|
};
|
|
153
|
-
var onResize = function() {
|
|
154
|
-
clearTimeout(timerRef.current.timer);
|
|
155
|
-
timerRef.current.timer = setTimeout(function() {
|
|
156
|
-
initColumns();
|
|
157
|
-
}, 1000);
|
|
158
|
-
};
|
|
159
130
|
useEffect(function() {
|
|
160
131
|
initColumns();
|
|
161
|
-
window.addEventListener("resize",
|
|
132
|
+
window.addEventListener("resize", initColumns);
|
|
162
133
|
return function() {
|
|
163
|
-
|
|
164
|
-
window.removeEventListener("resize", onResize);
|
|
134
|
+
window.removeEventListener("resize", initColumns);
|
|
165
135
|
};
|
|
166
136
|
}, [
|
|
167
137
|
props.columns
|
|
168
138
|
]);
|
|
169
|
-
console.log("宽度宽度", scrollObject);
|
|
170
139
|
var config = _object_spread_props(_object_spread({
|
|
171
140
|
bordered: false
|
|
172
141
|
}, props), {
|
|
173
142
|
columns: columns,
|
|
174
143
|
scroll: scrollObject || {
|
|
175
|
-
x: "
|
|
144
|
+
x: "none"
|
|
176
145
|
}
|
|
177
146
|
});
|
|
178
147
|
return /*#__PURE__*/ _jsx("div", {
|
|
179
148
|
className: styles.Table,
|
|
180
|
-
ref:
|
|
149
|
+
ref: ref,
|
|
181
150
|
children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
|
|
182
151
|
});
|
|
183
152
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bhd-components",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "组件功能描述",
|
|
5
5
|
"files": [
|
|
6
6
|
"esm",
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"component"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@ant-design/icons": "^5.0.1",
|
|
48
49
|
"@ice/jsx-runtime": "^0.2.0",
|
|
49
50
|
"@swc/helpers": "^0.4.14",
|
|
50
|
-
"antd": "^5.
|
|
51
|
+
"antd": "^5.4.6",
|
|
51
52
|
"less": "^4.1.3",
|
|
52
53
|
"less-loader": "^11.1.0"
|
|
53
54
|
},
|