@cqsjjb/jjb-react-admin-component 3.3.5 → 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 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,64 +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
- // 自定义包裹样式
59
- wrapperStyle?: React.CSSProperties;
60
11
  }
61
12
 
62
13
  interface TableFc extends React.FC<OverTableProps> {
63
14
  }
64
15
 
65
16
  declare const Table: TableFc;
66
- export default Table;
17
+ export default Table;
package/Table/index.js CHANGED
@@ -1,101 +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, { useRef, useEffect, useState, useCallback } from '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
- import { antPrefix } from './utils';
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 ref = useRef(null);
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
- enableAutoScrollY = true,
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
- wrapperStyle = {},
26
- ...restProps
15
+ storeIndex
27
16
  } = props;
28
- const [scrollY, setScrollY] = useState(undefined);
29
- const timerRef = useRef(null);
30
- const calcTableScrollY = () => {
31
- const tableBody = ref.current?.querySelector?.(tableBodyCls);
32
- const tableBodyRect = tableBody?.getBoundingClientRect();
33
- const tableFooter = ref.current?.querySelector?.(tableFooterCls);
34
- const tableFooterRect = tableFooter?.getBoundingClientRect();
35
- const tablePagination = ref.current?.querySelector?.(tablePaginationCls);
36
- const tablePaginationRect = tablePagination?.getBoundingClientRect();
37
- const tableFooterHeight = tableFooterRect?.height || 0;
38
- const tablePaginationMargin = 32;
39
- const tablePaginationHeight = tablePaginationRect?.height || 0;
40
- const border = 2;
41
- const margin = 20;
42
- const scrollY = window.innerHeight - tableBodyRect.top - tableFooterHeight - tablePaginationHeight - tablePaginationMargin - border - margin;
43
- return scrollY;
44
- };
45
- const debouncedCalcScrollY = useCallback(() => {
46
- if (timerRef.current) {
47
- clearTimeout(timerRef.current);
48
- }
49
- timerRef.current = setTimeout(() => {
50
- const height = calcTableScrollY();
51
- if (height) {
52
- setScrollY(height);
53
- }
54
- }, 150);
55
- }, []);
56
- useEffect(() => {
57
- 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()));
58
28
 
59
- // 创建 ResizeObserver 监听元素尺寸变化
60
- const resizeObserver = new ResizeObserver(() => {
61
- // 等待 table-pagination 元素生成后再计算
62
- debouncedCalcScrollY();
63
- });
64
- const mutationObserver = new MutationObserver(() => {
65
- debouncedCalcScrollY();
66
- });
67
- mutationObserver.observe(ref.current, {
68
- childList: true,
69
- subtree: true,
70
- attributes: true
71
- });
29
+ // 初始化首次计算
30
+ setTimeout(() => calcTableHeight(), 500);
72
31
 
73
- // 开始观察 ref.current 的尺寸变化
74
- resizeObserver.observe(ref.current);
32
+ // 执行-监听-缩放
33
+ resizeObserver.observe(document.body);
34
+ // 执行-监听-DOM树是否发生变化
35
+ mutationObserver.observe(document.body, {
36
+ subtree: true,
37
+ childList: true
38
+ });
39
+ }
75
40
  return () => {
76
- if (timerRef.current) {
77
- clearTimeout(timerRef.current);
41
+ if (mutationObserver && resizeObserver && enabledResizer) {
42
+ resizeObserver.unobserve(document.body);
43
+ mutationObserver.disconnect(document.body);
78
44
  }
79
- resizeObserver.disconnect();
80
- mutationObserver.disconnect();
81
45
  };
82
- }, [ref, enableAutoScrollY, debouncedCalcScrollY]);
83
- return /*#__PURE__*/React.createElement("div", {
84
- ref: ref,
85
- style: {
86
- height: '100%',
87
- ...wrapperStyle
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'
88
83
  }
89
- }, /*#__PURE__*/React.createElement(ProTable, _extends({
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({
90
92
  ghost: true,
91
93
  columnEmptyText: true,
94
+ size: size,
92
95
  search: false,
93
- scroll: enableAutoScrollY ? {
94
- y: scrollY || 0
95
- } : undefined,
96
+ scroll: scroll,
96
97
  className: `${antPrefix}-gbs-pro-table`,
97
- options: options
98
- }, restProps, {
99
- columns: restProps.columns
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
100
117
  })));
101
118
  }
package/Table/index.less CHANGED
@@ -1,15 +1,13 @@
1
- @com-prefix-cls: if(isdefined(@ant-prefix), @ant-prefix, ant);
2
-
3
- .@{com-prefix-cls} {
1
+ .@{ant-prefix} {
4
2
  &-gbs-pro-table {
5
- .@{com-prefix-cls}-pro-card {
3
+ .@{ant-prefix}-pro-card {
6
4
  &-body {
7
- .@{com-prefix-cls}-pro-table-list-toolbar {
5
+ .@{ant-prefix}-pro-table-list-toolbar {
8
6
  &-container {
9
- padding-block: 0;
7
+ padding-top: 0;
10
8
  }
11
9
  }
12
10
  }
13
11
  }
14
12
  }
15
- }
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-react-admin-component",
3
- "version": "3.3.5",
3
+ "version": "3.3.6",
4
4
  "description": "jjb-react-admin-组件库@new",
5
5
  "main": "index.js",
6
6
  "author": "jjb-front-team",