@cqsjjb/jjb-react-admin-component 3.0.7 → 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.
@@ -0,0 +1,13 @@
1
+ // @ts-ignore
2
+ import * as React from 'react';
3
+ import { ComponentProps } from '../types';
4
+
5
+ interface MediaQueryProps extends ComponentProps {
6
+ disabled?: boolean;
7
+ }
8
+
9
+ interface MediaQueryFc extends React.FC<MediaQueryProps> {
10
+ }
11
+
12
+ declare const MediaQuery: MediaQueryFc;
13
+ export default MediaQuery;
@@ -0,0 +1,91 @@
1
+ import React from 'react';
2
+ const MEDIA_QUERY_LIST = {
3
+ MAX_WIDTH_479: '(max-width: 479px)',
4
+ MIN_WIDTH_480_AND_MAX_WIDTH_599: '(min-width: 480px) and (max-width: 599px)',
5
+ MIN_WIDTH_600_AND_MAX_WIDTH_899: '(min-width: 600px) and (max-width: 899px)',
6
+ MIN_WIDTH_900_AND_MAX_WIDTH_1199: '(min-width: 900px) and (max-width: 1199px)',
7
+ MIN_WIDTH_1200_AND_MAX_WIDTH_1439: '(min-width: 1200px) and (max-width: 1439px)',
8
+ MIN_WIDTH_1440: '(min-width: 1440px)'
9
+ };
10
+ export default class MediaQuery extends React.Component {
11
+ state = {
12
+ media: undefined
13
+ };
14
+ componentDidMount() {
15
+ const {
16
+ disabled
17
+ } = this.props;
18
+ if (disabled) {
19
+ return;
20
+ }
21
+
22
+ // 超小
23
+ this.ultraSmall = window.matchMedia(MEDIA_QUERY_LIST.MAX_WIDTH_479);
24
+ // 正常小
25
+ this.normalSmall = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_480_AND_MAX_WIDTH_599);
26
+ // 中等
27
+ this.normalMiddle = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_600_AND_MAX_WIDTH_899);
28
+ // 正常大
29
+ this.normalLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_900_AND_MAX_WIDTH_1199);
30
+ // 超大
31
+ this.superLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1200_AND_MAX_WIDTH_1439);
32
+ // 超宽
33
+ this.normalHuge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1440);
34
+ this.handleMediaQueryChange();
35
+ this.ultraSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
36
+ this.normalSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
37
+ this.normalMiddle.addEventListener('change', this.handleMediaQueryChange.bind(this));
38
+ this.normalLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
39
+ this.superLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
40
+ this.normalHuge.addEventListener('change', this.handleMediaQueryChange.bind(this));
41
+ }
42
+ componentWillUnmount() {
43
+ this.ultraSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
44
+ this.normalSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
45
+ this.normalMiddle.removeEventListener('change', this.handleMediaQueryChange.bind(this));
46
+ this.normalLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
47
+ this.superLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
48
+ this.normalHuge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
49
+ }
50
+ handleMediaQueryChange() {
51
+ const {
52
+ disabled
53
+ } = this.props;
54
+ if (disabled) {
55
+ return;
56
+ }
57
+ let media;
58
+ if (this.ultraSmall.matches) {
59
+ media = this.ultraSmall.media;
60
+ } else if (this.normalSmall.matches) {
61
+ media = this.normalSmall.media;
62
+ } else if (this.normalMiddle.matches) {
63
+ media = this.normalMiddle.media;
64
+ } else if (this.normalLarge.matches) {
65
+ media = this.normalLarge.media;
66
+ } else if (this.superLarge.matches) {
67
+ media = this.superLarge.media;
68
+ } else if (this.normalHuge.matches) {
69
+ media = this.normalHuge.media;
70
+ }
71
+ this.setState({
72
+ media: Object.keys(MEDIA_QUERY_LIST).find(key => media === MEDIA_QUERY_LIST[key])
73
+ });
74
+ }
75
+ get children() {
76
+ return this.props.children;
77
+ }
78
+ render() {
79
+ const {
80
+ media
81
+ } = this.state;
82
+ const {
83
+ children
84
+ } = this.props;
85
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (Array.isArray(children) ? children : [].concat(children)).map((item, key) => ( /*#__PURE__*/React.createElement(item.type, {
86
+ key,
87
+ ...item.props,
88
+ ['data-media-query']: media
89
+ }))));
90
+ }
91
+ }
@@ -0,0 +1,104 @@
1
+ import React from 'react';
2
+
3
+ const MEDIA_QUERY_LIST = {
4
+ MAX_WIDTH_479: '(max-width: 479px)',
5
+ MIN_WIDTH_480_AND_MAX_WIDTH_599: '(min-width: 480px) and (max-width: 599px)',
6
+ MIN_WIDTH_600_AND_MAX_WIDTH_899: '(min-width: 600px) and (max-width: 899px)',
7
+ MIN_WIDTH_900_AND_MAX_WIDTH_1199: '(min-width: 900px) and (max-width: 1199px)',
8
+ MIN_WIDTH_1200_AND_MAX_WIDTH_1439: '(min-width: 1200px) and (max-width: 1439px)',
9
+ MIN_WIDTH_1440: '(min-width: 1440px)'
10
+ };
11
+
12
+ export default class MediaQuery extends React.Component {
13
+ state = {
14
+ media: undefined
15
+ };
16
+
17
+ componentDidMount () {
18
+ const { disabled } = this.props;
19
+
20
+ if (disabled) {
21
+ return;
22
+ }
23
+
24
+ // 超小
25
+ this.ultraSmall = window.matchMedia(MEDIA_QUERY_LIST.MAX_WIDTH_479);
26
+ // 正常小
27
+ this.normalSmall = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_480_AND_MAX_WIDTH_599);
28
+ // 中等
29
+ this.normalMiddle = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_600_AND_MAX_WIDTH_899);
30
+ // 正常大
31
+ this.normalLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_900_AND_MAX_WIDTH_1199);
32
+ // 超大
33
+ this.superLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1200_AND_MAX_WIDTH_1439);
34
+ // 超宽
35
+ this.normalHuge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1440);
36
+
37
+ this.handleMediaQueryChange();
38
+
39
+ this.ultraSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
40
+ this.normalSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
41
+ this.normalMiddle.addEventListener('change', this.handleMediaQueryChange.bind(this));
42
+ this.normalLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
43
+ this.superLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
44
+ this.normalHuge.addEventListener('change', this.handleMediaQueryChange.bind(this));
45
+ }
46
+
47
+ componentWillUnmount () {
48
+ this.ultraSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
49
+ this.normalSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
50
+ this.normalMiddle.removeEventListener('change', this.handleMediaQueryChange.bind(this));
51
+ this.normalLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
52
+ this.superLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
53
+ this.normalHuge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
54
+ }
55
+
56
+ handleMediaQueryChange () {
57
+ const { disabled } = this.props;
58
+
59
+ if (disabled) {
60
+ return;
61
+ }
62
+
63
+ let media;
64
+
65
+ if (this.ultraSmall.matches) {
66
+ media = this.ultraSmall.media;
67
+ } else if (this.normalSmall.matches) {
68
+ media = this.normalSmall.media;
69
+ } else if (this.normalMiddle.matches) {
70
+ media = this.normalMiddle.media;
71
+ } else if (this.normalLarge.matches) {
72
+ media = this.normalLarge.media;
73
+ } else if (this.superLarge.matches) {
74
+ media = this.superLarge.media;
75
+ } else if (this.normalHuge.matches) {
76
+ media = this.normalHuge.media;
77
+ }
78
+
79
+ this.setState({ media: Object.keys(MEDIA_QUERY_LIST).find(key => media === MEDIA_QUERY_LIST[ key ]) });
80
+ }
81
+
82
+ get children () {
83
+ return this.props.children;
84
+ }
85
+
86
+ render () {
87
+ const { media } = this.state;
88
+ const { children } = this.props;
89
+
90
+ return (
91
+ <>
92
+ {(Array.isArray(children)
93
+ ? children
94
+ : [].concat(children)).map((item, key) => (
95
+ React.createElement(item.type, {
96
+ key,
97
+ ...item.props,
98
+ [ 'data-media-query' ]: media
99
+ })
100
+ ))}
101
+ </>
102
+ );
103
+ }
104
+ }
@@ -2,7 +2,7 @@
2
2
  import * as React from 'react';
3
3
  import { ComponentProps } from '../types';
4
4
 
5
- interface searchFormProps extends ComponentProps {
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 searchFormFc extends React.FC<searchFormProps> {
48
+ interface SearchFormFc extends React.FC<SearchFormProps> {
49
49
  }
50
50
 
51
- declare const searchForm: searchFormFc;
52
- export default searchForm;
51
+ declare const SearchForm: SearchFormFc;
52
+ export default SearchForm;
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ .@{ant-prefix} {
2
+ &-gbs-pro-table {
3
+ .@{ant-prefix}-pro-card {
4
+ &-body {
5
+ .@{ant-prefix}-pro-table-list-toolbar {
6
+ &-container {
7
+ padding-top: 0;
8
+ }
9
+ }
10
+ }
11
+ }
12
+ }
13
+ }
@@ -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.7",
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": "^4.21.0",
16
- "@ant-design/pro-layout": "^7.17.16"
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
  }