@cqsjjb/jjb-react-admin-component 3.0.8 → 3.0.9
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/MediaQuery/index.d.ts +4 -4
- package/SearchForm/index.d.ts +4 -4
- package/Table/index.d.ts +15 -0
- package/Table/index.js +86 -0
- package/Table/index.less +13 -0
- package/Table/index.mjs +116 -0
- package/Table/utils.js +99 -0
- package/package.json +5 -3
package/MediaQuery/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ComponentProps } from '../types';
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface MediaQueryProps extends ComponentProps {
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
interface
|
|
9
|
+
interface MediaQueryFc extends React.FC<MediaQueryProps> {
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
declare const
|
|
13
|
-
export default
|
|
12
|
+
declare const MediaQuery: MediaQueryFc;
|
|
13
|
+
export default MediaQuery;
|
package/SearchForm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ComponentProps } from '../types';
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface SearchFormProps extends ComponentProps {
|
|
6
6
|
/**
|
|
7
7
|
* @description form实例
|
|
8
8
|
*/
|
|
@@ -45,8 +45,8 @@ interface searchFormProps extends ComponentProps {
|
|
|
45
45
|
onReset?: (values: { [ p: string ]: any }) => void;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
interface
|
|
48
|
+
interface SearchFormFc extends React.FC<SearchFormProps> {
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
declare const
|
|
52
|
-
export default
|
|
51
|
+
declare const SearchForm: SearchFormFc;
|
|
52
|
+
export default SearchForm;
|
package/Table/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import type { TableProps } from 'antd';
|
|
5
|
+
|
|
6
|
+
interface OverTableProps extends TableProps {
|
|
7
|
+
// 是否禁用内容区滚动,默认true
|
|
8
|
+
disabledResizer?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface TableFc extends React.FC<OverTableProps> {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare const Table: TableFc;
|
|
15
|
+
export default Table;
|
package/Table/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ProTable } from '@ant-design/pro-components';
|
|
4
|
+
import { useAntdResizableHeader } from 'use-antd-resizable-header';
|
|
5
|
+
import { getElementAbsRect, antPrefix, className, setTableSize, getTableSize, getPersistenceKey } from './utils';
|
|
6
|
+
import './index.less';
|
|
7
|
+
require('use-antd-resizable-header/dist/style.css');
|
|
8
|
+
export default function TablePro(props) {
|
|
9
|
+
const [size, setSize] = React.useState(getTableSize() || 'default');
|
|
10
|
+
const [tableHeight, setTableHeight] = React.useState(0);
|
|
11
|
+
const persistenceKey = getPersistenceKey();
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
if (!props.disabledResizer) {
|
|
14
|
+
let observer;
|
|
15
|
+
const table = document.querySelector(className('pro-table'));
|
|
16
|
+
observer = new ResizeObserver(() => {
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
const tBody = document.querySelector(className('table-body'));
|
|
19
|
+
const tFooter = document.querySelector(className('table-footer'));
|
|
20
|
+
const tPagination = document.querySelector(className('table-pagination'));
|
|
21
|
+
const tBodyNativeRect = tBody.getBoundingClientRect();
|
|
22
|
+
const tFooterAbsRect = getElementAbsRect(tFooter);
|
|
23
|
+
const tPaginationAbsRect = getElementAbsRect(tPagination);
|
|
24
|
+
const gap = 24;
|
|
25
|
+
const height = window.innerHeight - (gap + tBodyNativeRect.y + tFooterAbsRect.absHeight + tPaginationAbsRect.absHeight);
|
|
26
|
+
setTableHeight(height);
|
|
27
|
+
}, 100);
|
|
28
|
+
});
|
|
29
|
+
observer.observe(table);
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
if (observer && !props.disabledResizer) {
|
|
33
|
+
observer.unobserve(table);
|
|
34
|
+
observer.disconnect();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
setTableSize(size);
|
|
40
|
+
}, [size]);
|
|
41
|
+
const {
|
|
42
|
+
components,
|
|
43
|
+
resizableColumns,
|
|
44
|
+
tableWidth,
|
|
45
|
+
resetColumns
|
|
46
|
+
// refresh
|
|
47
|
+
} = useAntdResizableHeader({
|
|
48
|
+
columns: props.columns,
|
|
49
|
+
columnsState: {
|
|
50
|
+
persistenceKey: persistenceKey.resizable,
|
|
51
|
+
persistenceType: 'localStorage'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const scroll = {
|
|
55
|
+
x: tableWidth
|
|
56
|
+
};
|
|
57
|
+
if (!props.disabledResizer) {
|
|
58
|
+
scroll.y = tableHeight;
|
|
59
|
+
}
|
|
60
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProTable, _extends({}, props, {
|
|
61
|
+
ghost: true,
|
|
62
|
+
columnEmptyText: true,
|
|
63
|
+
size: size,
|
|
64
|
+
search: false,
|
|
65
|
+
scroll: scroll,
|
|
66
|
+
columns: resizableColumns,
|
|
67
|
+
className: `${antPrefix}-gbs-pro-table`,
|
|
68
|
+
options: {
|
|
69
|
+
reload: false,
|
|
70
|
+
fullScreen: true,
|
|
71
|
+
setting: {
|
|
72
|
+
checkedReset: true,
|
|
73
|
+
extra: /*#__PURE__*/React.createElement("a", {
|
|
74
|
+
className: `${antPrefix}-pro-table-column-setting-action-rest-button`,
|
|
75
|
+
onClick: resetColumns
|
|
76
|
+
}, "\u91CD\u7F6E\u5217\u5BBD")
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
components: components,
|
|
80
|
+
columnsState: {
|
|
81
|
+
persistenceKey: persistenceKey.columnState,
|
|
82
|
+
persistenceType: 'localStorage'
|
|
83
|
+
},
|
|
84
|
+
onSizeChange: setSize
|
|
85
|
+
})));
|
|
86
|
+
}
|
package/Table/index.less
ADDED
package/Table/index.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ProTable } from '@ant-design/pro-components';
|
|
4
|
+
import { useAntdResizableHeader } from 'use-antd-resizable-header';
|
|
5
|
+
|
|
6
|
+
import { getElementAbsRect, antPrefix, className, setTableSize, getTableSize, getPersistenceKey } from './utils';
|
|
7
|
+
|
|
8
|
+
import './index.less';
|
|
9
|
+
|
|
10
|
+
require('use-antd-resizable-header/dist/style.css');
|
|
11
|
+
|
|
12
|
+
export default function TablePro(props) {
|
|
13
|
+
const [ size, setSize ] = React.useState(getTableSize() || 'default');
|
|
14
|
+
const [ tableHeight, setTableHeight ] = React.useState(0);
|
|
15
|
+
|
|
16
|
+
const persistenceKey = getPersistenceKey();
|
|
17
|
+
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (!props.disabledResizer) {
|
|
20
|
+
let observer;
|
|
21
|
+
const table = document.querySelector(className('pro-table'));
|
|
22
|
+
|
|
23
|
+
observer = new ResizeObserver(() => {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
const tBody = document.querySelector(className('table-body'));
|
|
26
|
+
const tFooter = document.querySelector(className('table-footer'));
|
|
27
|
+
const tPagination = document.querySelector(className('table-pagination'));
|
|
28
|
+
|
|
29
|
+
const tBodyNativeRect = tBody.getBoundingClientRect();
|
|
30
|
+
const tFooterAbsRect = getElementAbsRect(tFooter);
|
|
31
|
+
const tPaginationAbsRect = getElementAbsRect(tPagination);
|
|
32
|
+
|
|
33
|
+
const gap = 24;
|
|
34
|
+
|
|
35
|
+
const height = window.innerHeight - (
|
|
36
|
+
gap +
|
|
37
|
+
tBodyNativeRect.y +
|
|
38
|
+
tFooterAbsRect.absHeight +
|
|
39
|
+
tPaginationAbsRect.absHeight
|
|
40
|
+
);
|
|
41
|
+
setTableHeight(height);
|
|
42
|
+
}, 100);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
observer.observe(table);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
if (observer && !props.disabledResizer) {
|
|
50
|
+
observer.unobserve(table);
|
|
51
|
+
observer.disconnect();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
setTableSize(size);
|
|
57
|
+
}, [ size ]);
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
components,
|
|
61
|
+
resizableColumns,
|
|
62
|
+
tableWidth,
|
|
63
|
+
resetColumns
|
|
64
|
+
// refresh
|
|
65
|
+
} = useAntdResizableHeader({
|
|
66
|
+
columns: props.columns,
|
|
67
|
+
columnsState: {
|
|
68
|
+
persistenceKey: persistenceKey.resizable,
|
|
69
|
+
persistenceType: 'localStorage'
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const scroll = {
|
|
74
|
+
x: tableWidth
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (!props.disabledResizer) {
|
|
78
|
+
scroll.y = tableHeight;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
<ProTable
|
|
84
|
+
{...props}
|
|
85
|
+
ghost
|
|
86
|
+
columnEmptyText
|
|
87
|
+
size={size}
|
|
88
|
+
search={false}
|
|
89
|
+
scroll={scroll}
|
|
90
|
+
columns={resizableColumns}
|
|
91
|
+
className={`${antPrefix}-gbs-pro-table`}
|
|
92
|
+
options={{
|
|
93
|
+
reload: false,
|
|
94
|
+
fullScreen: true,
|
|
95
|
+
setting: {
|
|
96
|
+
checkedReset: true,
|
|
97
|
+
extra: (
|
|
98
|
+
<a
|
|
99
|
+
className={`${antPrefix}-pro-table-column-setting-action-rest-button`}
|
|
100
|
+
onClick={resetColumns}
|
|
101
|
+
>
|
|
102
|
+
重置列宽
|
|
103
|
+
</a>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}}
|
|
107
|
+
components={components}
|
|
108
|
+
columnsState={{
|
|
109
|
+
persistenceKey: persistenceKey.columnState,
|
|
110
|
+
persistenceType: 'localStorage'
|
|
111
|
+
}}
|
|
112
|
+
onSizeChange={setSize}
|
|
113
|
+
/>
|
|
114
|
+
</>
|
|
115
|
+
);
|
|
116
|
+
}
|
package/Table/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { tools } from '@cqsjjb/jjb-common-lib';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param ele {HTMLElement}
|
|
5
|
+
* @return {{absHeight: number, absWidth: number}}
|
|
6
|
+
*/
|
|
7
|
+
export function getElementAbsRect(ele) {
|
|
8
|
+
if (!ele) {
|
|
9
|
+
return {
|
|
10
|
+
absWidth: 0,
|
|
11
|
+
absHeight: 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const style = getElementRect(ele);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
absHeight: tools.arrayHelper.sum([
|
|
19
|
+
style.height,
|
|
20
|
+
style.marginTop,
|
|
21
|
+
style.marginBottom,
|
|
22
|
+
style.borderTopWidth,
|
|
23
|
+
style.borderBottomWidth,
|
|
24
|
+
...(style.boxSizing === 'content-box'
|
|
25
|
+
? [
|
|
26
|
+
style.paddingTop,
|
|
27
|
+
style.paddingBottom
|
|
28
|
+
]
|
|
29
|
+
: [])
|
|
30
|
+
]),
|
|
31
|
+
absWidth: tools.arrayHelper.sum([
|
|
32
|
+
style.width,
|
|
33
|
+
style.marginLeft,
|
|
34
|
+
style.marginRight,
|
|
35
|
+
style.borderLeftWidth,
|
|
36
|
+
style.borderRightWidth,
|
|
37
|
+
...(style.boxSizing === 'content-box'
|
|
38
|
+
? [
|
|
39
|
+
style.paddingLeft,
|
|
40
|
+
style.paddingRight
|
|
41
|
+
]
|
|
42
|
+
: [])
|
|
43
|
+
])
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param ele {HTMLElement}
|
|
49
|
+
* @return {{paddingRight: number, marginLeft: number, marginRight: number, paddingBottom: number, borderLeftWidth: number, borderTopWidth: number, borderRightWidth: number, width: number, marginBottom: number, paddingTop: number, borderBottomWidth: number, paddingLeft: number, marginTop: number, height: number, boxSizing: string}}
|
|
50
|
+
*/
|
|
51
|
+
export function getElementRect(ele) {
|
|
52
|
+
let style;
|
|
53
|
+
try {
|
|
54
|
+
style = window.getComputedStyle(ele);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
style = {};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
width: parseFloat(style[ 'width' ] || '0'),
|
|
60
|
+
height: parseFloat(style[ 'height' ] || '0'),
|
|
61
|
+
marginTop: parseFloat(style[ 'margin-top' ] || '0'),
|
|
62
|
+
marginBottom: parseFloat(style[ 'margin-bottom' ] || '0'),
|
|
63
|
+
marginLeft: parseFloat(style[ 'margin-left' ] || '0'),
|
|
64
|
+
marginRight: parseFloat(style[ 'margin-bottom' ] || '0'),
|
|
65
|
+
borderTopWidth: parseFloat(style[ 'border-top-width' ] || '0'),
|
|
66
|
+
borderBottomWidth: parseFloat(style[ 'border-bottom-width' ] || '0'),
|
|
67
|
+
borderLeftWidth: parseFloat(style[ 'border-left-width' ] || '0'),
|
|
68
|
+
borderRightWidth: parseFloat(style[ 'border-right-width' ] || '0'),
|
|
69
|
+
paddingTop: parseFloat(style[ 'padding-top' ] || '0'),
|
|
70
|
+
paddingBottom: parseFloat(style[ 'padding-bottom' ] || '0'),
|
|
71
|
+
paddingLeft: parseFloat(style[ 'padding-left' ] || '0'),
|
|
72
|
+
paddingRight: parseFloat(style[ 'padding-right' ] || '0'),
|
|
73
|
+
boxSizing: style[ 'box-sizing' ]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const antPrefix = process.env.app.antd[ 'ant-prefix' ];
|
|
78
|
+
|
|
79
|
+
export function className(name) {
|
|
80
|
+
return `.${antPrefix}-${name}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getPersistenceKey() {
|
|
84
|
+
const basename = process.env?.app?.basename;
|
|
85
|
+
const pathname = decodeURIComponent(window.location.pathname);
|
|
86
|
+
return {
|
|
87
|
+
size: `${basename}#${pathname}#size`,
|
|
88
|
+
resizable: `${basename}#${pathname}#resizable`,
|
|
89
|
+
columnState: `${basename}#${pathname}#columnState`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getTableSize() {
|
|
94
|
+
return window.localStorage.getItem(getPersistenceKey().size);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function setTableSize(value) {
|
|
98
|
+
return window.localStorage.setItem(getPersistenceKey().size, value);
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqsjjb/jjb-react-admin-component",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"description": "jjb-react-admin-组件库@new",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "jjb-front-team",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"axios": "^1.6.5",
|
|
13
13
|
"spark-md5": "^3.0.2",
|
|
14
14
|
"classnames": "^2.5.1",
|
|
15
|
-
"antd-img-crop": "
|
|
16
|
-
"@ant-design/pro-layout": "
|
|
15
|
+
"antd-img-crop": "latest",
|
|
16
|
+
"@ant-design/pro-layout": "latest",
|
|
17
|
+
"use-antd-resizable-header": "latest",
|
|
18
|
+
"@ant-design/pro-components": "latest"
|
|
17
19
|
}
|
|
18
20
|
}
|