@cqsjjb/jjb-react-admin-component 3.3.4 → 3.3.6
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/Table/README.md +1 -1
- package/Table/index.d.ts +3 -50
- package/Table/index.js +97 -78
- package/Table/index.less +5 -7
- package/package.json +1 -1
package/Table/README.md
CHANGED
|
@@ -33,4 +33,4 @@ function App() {
|
|
|
33
33
|
| disabledResizer | 是否禁用内容区滚动,设置true自动将适配内容区滚动高度 | `boolean` | false |
|
|
34
34
|
| storeIndex | 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖 | `number` | - |
|
|
35
35
|
|
|
36
|
-
其他属性参考 https://ant-design.antgroup.com/components/table-cn#api
|
|
36
|
+
其他属性参考 https://ant-design.antgroup.com/components/table-cn#api
|
package/Table/index.d.ts
CHANGED
|
@@ -3,62 +3,15 @@ import * as React from 'react';
|
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import type { TableProps } from 'antd';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* 列设置配置项
|
|
8
|
-
*/
|
|
9
|
-
export interface SettingOptionType {
|
|
10
|
-
/** 是否可拖拽排序 */
|
|
11
|
-
draggable?: boolean;
|
|
12
|
-
/** 是否显示复选框 */
|
|
13
|
-
checkable?: boolean;
|
|
14
|
-
/** 是否显示列表项选项 */
|
|
15
|
-
showListItemOption?: boolean;
|
|
16
|
-
/** 重置时是否恢复选中状态 */
|
|
17
|
-
checkedReset?: boolean;
|
|
18
|
-
/** 列表高度 */
|
|
19
|
-
listsHeight?: number;
|
|
20
|
-
/** 额外内容 */
|
|
21
|
-
extra?: React.ReactNode;
|
|
22
|
-
/** 子元素 */
|
|
23
|
-
children?: React.ReactNode;
|
|
24
|
-
/** 自定义设置图标 */
|
|
25
|
-
settingIcon?: React.ReactNode;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ProTable options 配置项
|
|
30
|
-
*/
|
|
31
|
-
export interface OptionConfig {
|
|
32
|
-
/** 是否显示密度切换 */
|
|
33
|
-
density?: boolean;
|
|
34
|
-
/** 是否显示全屏按钮,或自定义函数 */
|
|
35
|
-
fullScreen?: boolean | ((e: React.MouseEvent<HTMLSpanElement>, action?: any) => void);
|
|
36
|
-
/** 是否显示刷新按钮,或自定义函数 */
|
|
37
|
-
reload?: boolean | ((e: React.MouseEvent<HTMLSpanElement>, action?: any) => void);
|
|
38
|
-
/** 列设置配置 */
|
|
39
|
-
setting?: boolean | SettingOptionType;
|
|
40
|
-
/** 搜索配置 */
|
|
41
|
-
search?: boolean | {
|
|
42
|
-
name?: string;
|
|
43
|
-
[key: string]: any;
|
|
44
|
-
};
|
|
45
|
-
/** 自定义刷新图标 */
|
|
46
|
-
reloadIcon?: React.ReactNode;
|
|
47
|
-
/** 自定义密度图标 */
|
|
48
|
-
densityIcon?: React.ReactNode;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
6
|
export interface OverTableProps extends TableProps {
|
|
7
|
+
// 是否禁用内容区滚动,默认-false
|
|
8
|
+
disabledResizer?: boolean;
|
|
52
9
|
// 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖
|
|
53
10
|
storeIndex?: string;
|
|
54
|
-
// 是否启用自动计算滚动高度,默认-true
|
|
55
|
-
enableAutoScrollY?: boolean;
|
|
56
|
-
// ProTable options 配置项
|
|
57
|
-
options?: OptionConfig | false;
|
|
58
11
|
}
|
|
59
12
|
|
|
60
13
|
interface TableFc extends React.FC<OverTableProps> {
|
|
61
14
|
}
|
|
62
15
|
|
|
63
16
|
declare const Table: TableFc;
|
|
64
|
-
export default Table;
|
|
17
|
+
export default Table;
|
package/Table/index.js
CHANGED
|
@@ -1,99 +1,118 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { tools } from '@cqsjjb/jjb-common-lib';
|
|
3
4
|
import { ProTable } from '@ant-design/pro-components';
|
|
5
|
+
import { useAntdResizableHeader } from 'use-antd-resizable-header';
|
|
6
|
+
import { antPrefix, setTableSize, getTableSize, getPersistenceKey } from './utils';
|
|
4
7
|
import './index.less';
|
|
5
|
-
|
|
8
|
+
require('use-antd-resizable-header/dist/style.css');
|
|
6
9
|
export default function TablePro(props) {
|
|
7
10
|
const prefix = antPrefix || 'ant';
|
|
8
11
|
const baseCls = `.${prefix}-table`;
|
|
9
|
-
const
|
|
12
|
+
const tableCls = `${baseCls}-wrapper`;
|
|
10
13
|
const tableBodyCls = `${baseCls}-body`;
|
|
11
|
-
const tablePaginationCls = `${baseCls}-pagination`;
|
|
12
|
-
const tableFooterCls = `${baseCls}-footer`;
|
|
13
14
|
const {
|
|
14
|
-
|
|
15
|
-
options = {
|
|
16
|
-
reload: false,
|
|
17
|
-
density: true,
|
|
18
|
-
fullScreen: true,
|
|
19
|
-
setting: {
|
|
20
|
-
checkedReset: true,
|
|
21
|
-
draggable: false,
|
|
22
|
-
checkable: true
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
...restProps
|
|
15
|
+
storeIndex
|
|
26
16
|
} = props;
|
|
27
|
-
const [
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const tablePaginationHeight = tablePaginationRect?.height || 0;
|
|
39
|
-
const border = 2;
|
|
40
|
-
const margin = 20;
|
|
41
|
-
const scrollY = window.innerHeight - tableBodyRect.top - tableFooterHeight - tablePaginationHeight - tablePaginationMargin - border - margin;
|
|
42
|
-
return scrollY;
|
|
43
|
-
};
|
|
44
|
-
const debouncedCalcScrollY = useCallback(() => {
|
|
45
|
-
if (timerRef.current) {
|
|
46
|
-
clearTimeout(timerRef.current);
|
|
47
|
-
}
|
|
48
|
-
timerRef.current = setTimeout(() => {
|
|
49
|
-
const height = calcTableScrollY();
|
|
50
|
-
if (height) {
|
|
51
|
-
setScrollY(height);
|
|
52
|
-
}
|
|
53
|
-
}, 150);
|
|
54
|
-
}, []);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!ref.current || !enableAutoScrollY) return;
|
|
17
|
+
const [size, setSize] = React.useState(getTableSize(storeIndex) || 'default');
|
|
18
|
+
const [tableHeight, setTableHeight] = React.useState(0);
|
|
19
|
+
const persistenceKey = getPersistenceKey(storeIndex);
|
|
20
|
+
const enabledResizer = tools.isUndefined(props.disabledResizer);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
let mutationObserver, resizeObserver;
|
|
23
|
+
if (enabledResizer) {
|
|
24
|
+
// 监听-DOM树
|
|
25
|
+
mutationObserver = new MutationObserver(mutations => mutations.forEach(() => calcTableHeight()));
|
|
26
|
+
// 监听-缩放
|
|
27
|
+
resizeObserver = new ResizeObserver(entries => entries.forEach(() => calcTableHeight()));
|
|
57
28
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// 等待 table-pagination 元素生成后再计算
|
|
61
|
-
debouncedCalcScrollY();
|
|
62
|
-
});
|
|
63
|
-
const mutationObserver = new MutationObserver(() => {
|
|
64
|
-
debouncedCalcScrollY();
|
|
65
|
-
});
|
|
66
|
-
mutationObserver.observe(ref.current, {
|
|
67
|
-
childList: true,
|
|
68
|
-
subtree: true,
|
|
69
|
-
attributes: true
|
|
70
|
-
});
|
|
29
|
+
// 初始化首次计算
|
|
30
|
+
setTimeout(() => calcTableHeight(), 500);
|
|
71
31
|
|
|
72
|
-
|
|
73
|
-
|
|
32
|
+
// 执行-监听-缩放
|
|
33
|
+
resizeObserver.observe(document.body);
|
|
34
|
+
// 执行-监听-DOM树是否发生变化
|
|
35
|
+
mutationObserver.observe(document.body, {
|
|
36
|
+
subtree: true,
|
|
37
|
+
childList: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
74
40
|
return () => {
|
|
75
|
-
if (
|
|
76
|
-
|
|
41
|
+
if (mutationObserver && resizeObserver && enabledResizer) {
|
|
42
|
+
resizeObserver.unobserve(document.body);
|
|
43
|
+
mutationObserver.disconnect(document.body);
|
|
77
44
|
}
|
|
78
|
-
resizeObserver.disconnect();
|
|
79
|
-
mutationObserver.disconnect();
|
|
80
45
|
};
|
|
81
|
-
}, [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
46
|
+
}, []);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
setTableSize(size, storeIndex);
|
|
49
|
+
}, [size]);
|
|
50
|
+
|
|
51
|
+
// 计算高度
|
|
52
|
+
const calcTableHeight = () => {
|
|
53
|
+
try {
|
|
54
|
+
// table元素
|
|
55
|
+
const tableEl = document.querySelector(tableCls);
|
|
56
|
+
// table-body元素
|
|
57
|
+
const tableBodyEl = document.querySelector(tableBodyCls);
|
|
58
|
+
if (tableBodyEl && tableEl) {
|
|
59
|
+
// 获取table元素的矩形数据
|
|
60
|
+
const tableRect = tableEl.getBoundingClientRect();
|
|
61
|
+
// 获取table-body元素的矩形数据
|
|
62
|
+
const tableBodyRect = tableBodyEl.getBoundingClientRect();
|
|
63
|
+
// 获取底部的高度差
|
|
64
|
+
const bottomHeight = tableRect.bottom - tableBodyRect.bottom;
|
|
65
|
+
// 计算最终值
|
|
66
|
+
setTableHeight(innerHeight - tableBodyRect.top - bottomHeight - (window.__IN_BASE__ ? 38 : 22));
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
window.console['error'](e);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const {
|
|
73
|
+
components,
|
|
74
|
+
resizableColumns,
|
|
75
|
+
tableWidth,
|
|
76
|
+
resetColumns
|
|
77
|
+
// refresh
|
|
78
|
+
} = useAntdResizableHeader({
|
|
79
|
+
columns: props.columns,
|
|
80
|
+
columnsState: {
|
|
81
|
+
persistenceKey: persistenceKey.resizable,
|
|
82
|
+
persistenceType: 'localStorage'
|
|
86
83
|
}
|
|
87
|
-
}
|
|
84
|
+
});
|
|
85
|
+
const scroll = {
|
|
86
|
+
x: tableWidth
|
|
87
|
+
};
|
|
88
|
+
if (enabledResizer) {
|
|
89
|
+
scroll.y = tableHeight;
|
|
90
|
+
}
|
|
91
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProTable, _extends({
|
|
88
92
|
ghost: true,
|
|
89
93
|
columnEmptyText: true,
|
|
94
|
+
size: size,
|
|
90
95
|
search: false,
|
|
91
|
-
scroll:
|
|
92
|
-
y: scrollY || 0
|
|
93
|
-
} : undefined,
|
|
96
|
+
scroll: scroll,
|
|
94
97
|
className: `${antPrefix}-gbs-pro-table`,
|
|
95
|
-
options:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
options: {
|
|
99
|
+
reload: false,
|
|
100
|
+
fullScreen: true,
|
|
101
|
+
setting: {
|
|
102
|
+
checkedReset: true,
|
|
103
|
+
extra: /*#__PURE__*/React.createElement("a", {
|
|
104
|
+
className: `${antPrefix}-pro-table-column-setting-action-rest-button`,
|
|
105
|
+
onClick: resetColumns
|
|
106
|
+
}, "\u91CD\u7F6E\u5217\u5BBD")
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
components: components,
|
|
110
|
+
columnsState: {
|
|
111
|
+
persistenceKey: persistenceKey.columnState,
|
|
112
|
+
persistenceType: 'localStorage'
|
|
113
|
+
},
|
|
114
|
+
onSizeChange: setSize
|
|
115
|
+
}, props, {
|
|
116
|
+
columns: resizableColumns
|
|
98
117
|
})));
|
|
99
118
|
}
|
package/Table/index.less
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
.@{com-prefix-cls} {
|
|
1
|
+
.@{ant-prefix} {
|
|
4
2
|
&-gbs-pro-table {
|
|
5
|
-
.@{
|
|
3
|
+
.@{ant-prefix}-pro-card {
|
|
6
4
|
&-body {
|
|
7
|
-
.@{
|
|
5
|
+
.@{ant-prefix}-pro-table-list-toolbar {
|
|
8
6
|
&-container {
|
|
9
|
-
padding-
|
|
7
|
+
padding-top: 0;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
}
|
|
13
|
+
}
|