ztxkui 4.2.18-39 → 4.2.18-40

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.
@@ -92,6 +92,6 @@ var BasicTable = function (_a) {
92
92
  React.createElement("br", null),
93
93
  React.createElement("b", null, "\u5217\u4F38\u7F29\uFF1B"),
94
94
  "isResizableColumn\u5C5E\u6027\u9ED8\u8BA4\u4E3Atrue\uFF0C\u5982\u679C\u4E0D\u9700\u8981\u5217\u4F38\u7F29\u53EF\u4EE5\u4F20\u5165false"),
95
- React.createElement(Table, { dataSource: dataSource, columns: columns, rowKey: "id", scroll: { x: 400, y: 300 } })));
95
+ React.createElement(Table, { dataSource: dataSource, columns: columns, rowKey: "id", scroll: { x: 400, y: 300 }, isOpenVirtualScrollBar: true })));
96
96
  };
97
97
  export default BasicTable;
@@ -561,7 +561,7 @@ var EditableTable = function () {
561
561
  });
562
562
  }
563
563
  },
564
- }, scroll: { x: 1200, y: 400 }, showDelAllBtn: true, delAllChange: onDelAllChange, rowSelection: {
564
+ }, isOpenVirtualScrollBar: true, scroll: { x: 1200, y: 400 }, showDelAllBtn: true, delAllChange: onDelAllChange, rowSelection: {
565
565
  type: 'checkbox',
566
566
  }, summaryFixed: true, summaryConfig: [
567
567
  {
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ interface IVituralScrollBarOptions {
3
+ isOpen?: boolean;
4
+ }
5
+ export default function useVituralScrollBar(containerDomRef: any, options: IVituralScrollBarOptions): {
6
+ createMiniMap: JSX.Element;
7
+ };
8
+ export {};
@@ -0,0 +1,205 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+ import { Alert } from 'antd';
3
+ import throttle from 'lodash/throttle';
4
+ var miniMapContainerWidth = 100;
5
+ var miniMapContainerHeight = 50;
6
+ export default function useVituralScrollBar(containerDomRef, options) {
7
+ var isOpen = options.isOpen;
8
+ var alertRef = useRef(null);
9
+ var miniMapContainerRef = useRef(null);
10
+ var miniMapThumbRef = useRef(null);
11
+ var isFirstRef = useRef(false);
12
+ // 创建迷你地图,用于拖动滚动条位置
13
+ var createMiniMap = useMemo(function () {
14
+ if (!isOpen) {
15
+ return null;
16
+ }
17
+ return (React.createElement(React.Fragment, null,
18
+ React.createElement("div", { id: "minimap-container", ref: miniMapContainerRef, style: {
19
+ position: 'absolute',
20
+ width: miniMapContainerWidth,
21
+ height: miniMapContainerHeight,
22
+ backgroundColor: '#f0f0f0',
23
+ top: '5px',
24
+ right: '20px',
25
+ zIndex: 999,
26
+ opacity: 0.7,
27
+ display: 'none',
28
+ cursor: 'move',
29
+ } },
30
+ React.createElement("div", { ref: alertRef, style: {
31
+ display: 'none',
32
+ position: 'absolute',
33
+ top: miniMapContainerHeight,
34
+ left: -miniMapContainerWidth,
35
+ width: 2 * miniMapContainerWidth,
36
+ } },
37
+ React.createElement(Alert, { message: "\u8BD5\u8BD5\u62D6\u52A8\u5C0F\u84DD\u5757\u6EDA\u52A8\u8868\u683C", type: "info", closable: true, style: { padding: '4px 8px', fontSize: '13px' } })),
38
+ React.createElement("div", { id: "minimap-thumb", ref: miniMapThumbRef, style: {
39
+ position: 'absolute',
40
+ width: 20,
41
+ height: 10,
42
+ backgroundColor: '#1566d2',
43
+ cursor: 'pointer',
44
+ }, title: "\u62D6\u52A8\u6211\uFF0C\u53EF\u6EDA\u52A8\u8868\u683C\uFF01" }))));
45
+ }, [isOpen]);
46
+ useEffect(function () {
47
+ var containerDom = containerDomRef.current;
48
+ var miniMapContainerDom = miniMapContainerRef.current;
49
+ var minimapThumbDom = miniMapThumbRef.current;
50
+ if (!isOpen) {
51
+ return;
52
+ }
53
+ if (!containerDom) {
54
+ return;
55
+ }
56
+ // 更新迷你地图的位置和大小
57
+ var updateMiniMap = throttle(function () {
58
+ if (!miniMapContainerRef.current) {
59
+ console.error('请将迷你地图放置在容器中...');
60
+ return;
61
+ }
62
+ var scrollTableBody = containerDom.querySelector('.ant-table-body');
63
+ var clientWidth = scrollTableBody.clientWidth;
64
+ var clientHeight = scrollTableBody.clientHeight;
65
+ var scrollWidth = scrollTableBody.scrollWidth;
66
+ var scrollHeight = scrollTableBody.scrollHeight;
67
+ var minimapThumbDom = miniMapThumbRef.current;
68
+ // 计算缩放比例
69
+ var scaleX = miniMapContainerWidth / scrollWidth;
70
+ var scaleY = miniMapContainerHeight / scrollHeight;
71
+ // 设置迷你地图的尺寸
72
+ minimapThumbDom.style.width = clientWidth * scaleX + 'px';
73
+ minimapThumbDom.style.height = clientHeight * scaleY + 'px';
74
+ // 更新迷你地图位置
75
+ updateThumbPosition();
76
+ }, 50);
77
+ // 更新迷你地图拇指的位置
78
+ var updateThumbPosition = throttle(function () {
79
+ var scrollTableBody = containerDom.querySelector('.ant-table-body');
80
+ var scrollTop = scrollTableBody.scrollTop;
81
+ var scrollLeft = scrollTableBody.scrollLeft;
82
+ var scrollHeight = scrollTableBody.scrollHeight;
83
+ var scrollWidth = scrollTableBody.scrollWidth;
84
+ var clientHeight = scrollTableBody.clientHeight;
85
+ var clientWidth = scrollTableBody.clientWidth;
86
+ var miniMapContainerDom = miniMapContainerRef.current;
87
+ var minimapThumbDom = miniMapThumbRef.current;
88
+ var thumbHeight = parseInt(minimapThumbDom.style.height, 10);
89
+ var thumbWidth = parseInt(minimapThumbDom.style.width, 10);
90
+ var top = (scrollTop / (scrollHeight - clientHeight)) *
91
+ (miniMapContainerDom.offsetHeight - thumbHeight);
92
+ var left = (scrollLeft / (scrollWidth - clientWidth)) *
93
+ (miniMapContainerDom.offsetWidth - thumbWidth);
94
+ minimapThumbDom.style.top = top + 'px';
95
+ minimapThumbDom.style.left = left + 'px';
96
+ }, 50);
97
+ // 鼠标进入时,显示当前可滚动区域的滚动条信息
98
+ var mouseenterFn = function () {
99
+ miniMapContainerDom.style.display = 'block';
100
+ if (!isFirstRef.current) {
101
+ isFirstRef.current = true;
102
+ alertRef.current.style.display = 'block';
103
+ }
104
+ };
105
+ // 鼠标进入时,移除当前可滚动区域的滚动条信息
106
+ var mouseleaveFn = function () {
107
+ miniMapContainerDom.style.display = 'none';
108
+ };
109
+ containerDom.addEventListener('mouseenter', mouseenterFn);
110
+ containerDom.addEventListener('mouseleave', mouseleaveFn);
111
+ // 监听容器滚动,更新迷你地图位置
112
+ var scrollTableBody = containerDom.querySelector('.ant-table-body');
113
+ scrollTableBody.addEventListener('scroll', updateThumbPosition);
114
+ // 迷你地图拇指拖拽事件
115
+ var isDragging = false;
116
+ var minimapThumbMousedownFn = function (e) {
117
+ isDragging = true;
118
+ e.preventDefault(); // 阻止默认行为
119
+ e.stopPropagation(); // 阻止冒泡
120
+ };
121
+ minimapThumbDom.addEventListener('mousedown', minimapThumbMousedownFn);
122
+ var windowMousemoveFn = throttle(function (e) {
123
+ if (isDragging) {
124
+ var rect = miniMapContainerDom.getBoundingClientRect();
125
+ var containerTop = rect.top;
126
+ var containerLeft = rect.left;
127
+ var containerHeight = miniMapContainerDom.offsetHeight;
128
+ var containerWidth = miniMapContainerDom.offsetWidth;
129
+ var thumbHeight = minimapThumbDom.offsetHeight;
130
+ var thumbWidth = minimapThumbDom.offsetWidth;
131
+ // 计算新的顶部和左侧位置
132
+ var newTop = e.clientY - containerTop - thumbHeight / 2;
133
+ var newLeft = e.clientX - containerLeft - thumbWidth / 2;
134
+ // 确保新位置在容器内
135
+ newTop = Math.max(0, Math.min(containerHeight - thumbHeight, newTop));
136
+ newLeft = Math.max(0, Math.min(containerWidth - thumbWidth, newLeft));
137
+ // 更新迷你地图拇指的位置
138
+ minimapThumbDom.style.top = newTop + 'px';
139
+ minimapThumbDom.style.left = newLeft + 'px';
140
+ // 根据迷你地图更新大容器的滚动位置
141
+ scrollTableBody.scrollTop =
142
+ (newTop / (containerHeight - thumbHeight)) *
143
+ (scrollTableBody.scrollHeight - scrollTableBody.clientHeight);
144
+ scrollTableBody.scrollLeft =
145
+ (newLeft / (containerWidth - thumbWidth)) *
146
+ (scrollTableBody.scrollWidth - scrollTableBody.clientWidth);
147
+ }
148
+ }, 50);
149
+ window.addEventListener('mousemove', windowMousemoveFn);
150
+ // 迷你地图拖拽事件
151
+ var isMapDragging = false;
152
+ var minimapMousedownFn = function (e) {
153
+ isMapDragging = true;
154
+ e.preventDefault(); // 阻止默认行为
155
+ e.stopPropagation(); // 阻止冒泡
156
+ };
157
+ miniMapContainerDom.addEventListener('mousedown', minimapMousedownFn);
158
+ var windowMapMousemoveFn = throttle(function (e) {
159
+ if (isMapDragging) {
160
+ var rect = containerDom.getBoundingClientRect();
161
+ var containerTop = rect.top;
162
+ var containerLeft = rect.left;
163
+ var containerHeight = scrollTableBody.offsetHeight;
164
+ var containerWidth = scrollTableBody.offsetWidth;
165
+ var thumbHeight = miniMapContainerDom.offsetHeight;
166
+ var thumbWidth = miniMapContainerDom.offsetWidth;
167
+ // 计算新的顶部和左侧位置
168
+ var newTop = e.clientY - containerTop - thumbHeight / 2;
169
+ var newLeft = e.clientX - containerLeft - thumbWidth / 2;
170
+ // 确保新位置在容器内
171
+ newTop = Math.max(0, Math.min(containerHeight - thumbHeight, newTop));
172
+ newLeft = Math.max(0, Math.min(containerWidth - thumbWidth, newLeft));
173
+ // 更新迷你地图拇指的位置
174
+ miniMapContainerDom.style.top = newTop + 'px';
175
+ miniMapContainerDom.style.left = newLeft + 'px';
176
+ }
177
+ }, 50);
178
+ window.addEventListener('mousemove', windowMapMousemoveFn);
179
+ // 地图的拖拽 和 拇指的拖拽 公用一个 window mouseUp事件
180
+ var windowMouseupFn = function () {
181
+ isDragging = false;
182
+ isMapDragging = false;
183
+ };
184
+ window.addEventListener('mouseup', windowMouseupFn);
185
+ // 监听窗口大小变化以更新迷你地图
186
+ window.addEventListener('resize', updateMiniMap);
187
+ // 初始化更新迷你地图位置大小
188
+ updateMiniMap();
189
+ return function () {
190
+ containerDom.removeEventListener('mouseenter', mouseenterFn);
191
+ containerDom.removeEventListener('mouseleave', mouseleaveFn);
192
+ scrollTableBody.removeEventListener('scroll', updateThumbPosition);
193
+ minimapThumbDom.removeEventListener('mousedown', minimapThumbMousedownFn);
194
+ window.removeEventListener('mouseup', windowMouseupFn);
195
+ window.removeEventListener('mousemove', windowMousemoveFn);
196
+ miniMapContainerDom.removeEventListener('mousedown', minimapMousedownFn);
197
+ window.removeEventListener('mousemove', windowMapMousemoveFn);
198
+ window.removeEventListener('resize', updateMiniMap);
199
+ };
200
+ // eslint-disable-next-line react-hooks/exhaustive-deps
201
+ }, [isOpen]);
202
+ return {
203
+ createMiniMap: createMiniMap,
204
+ };
205
+ }
@@ -74,6 +74,8 @@ export interface IProps<RecordType> extends Omit<TableProps<RecordType>, 'column
74
74
  }) => void;
75
75
  /** 文本域是否以模态框的形式弹出 */
76
76
  isModalInput?: boolean;
77
+ /** 是否开启模拟滚动条 */
78
+ isOpenVirtualScrollBar?: boolean;
77
79
  }
78
80
  /**
79
81
  * TodoList
@@ -73,6 +73,7 @@ import TableEnhanceCell from './table-enhance-cell';
73
73
  import TableResizableTitle from './table-resizable-title';
74
74
  import useColumns, { setDynamicKey, getStorage, } from './hooks/useColumns';
75
75
  import useSelectSubtotal from './hooks/useSelectSubtotal';
76
+ import useVituralScrollBar from './hooks/useVituralScrollBar';
76
77
  import getSummaryData from './utils/getSummaryData';
77
78
  import { domFind,
78
79
  // domParentsUntil,
@@ -132,7 +133,7 @@ function Table(props) {
132
133
  var _a, _b;
133
134
  var className = props.className, scroll = props.scroll, _c = props.pagination, pagination = _c === void 0 ? false : _c, _d = props.bordered, bordered = _d === void 0 ? true : _d, _columns = props.columns, initColumns = props.initColumns, dataSource = props.dataSource, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, delIconText = props.delIconText, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, summaryConfig = props.summaryConfig, summaryFixed = props.summaryFixed, summary = props.summary, onMoveRow = props.onMoveRow, onEditableSave = props.onEditableSave, onDynamicChange = props.onDynamicChange, _e = props.isResizableColumn, isResizableColumn = _e === void 0 ? true : _e, configInfo = props.configInfo, tableHandleRef = props.tableHandleRef, tableName = props.tableName, isFlex = props.isFlex, onTableChange = props.onTableChange, rowSelection = props.rowSelection, showInnerPagination = props.showInnerPagination, defaultInnerPageSize = props.defaultInnerPageSize, virtualTableKey = props.virtualTableKey, _f = props.isSort, isSort = _f === void 0 ? false : _f, onSortChange = props.onSortChange, onFillDownChange = props.onFillDownChange, _g = props.isModalInput, isModalInput = _g === void 0 ? true : _g,
134
135
  // onRow,
135
- restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "hiddenColumnDynamicIcon", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize", "virtualTableKey", "isSort", "onSortChange", "onFillDownChange", "isModalInput"]);
136
+ isOpenVirtualScrollBar = props.isOpenVirtualScrollBar, restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "hiddenColumnDynamicIcon", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize", "virtualTableKey", "isSort", "onSortChange", "onFillDownChange", "isModalInput", "isOpenVirtualScrollBar"]);
136
137
  var onChange = restProps.onChange;
137
138
  var classes = classNames('zt-table', className, {
138
139
  'zt-table--flex': isFlex,
@@ -816,9 +817,13 @@ function Table(props) {
816
817
  vComponents,
817
818
  ]);
818
819
  var tipRef = useSelectSubtotal(tableRef, { onMoveRow: onMoveRow, onEditableSave: onEditableSave }).tipRef;
820
+ var createMiniMap = useVituralScrollBar(tableRef, {
821
+ isOpen: isOpenVirtualScrollBar,
822
+ }).createMiniMap;
819
823
  return (React.createElement("div", { style: isFlex
820
824
  ? { position: 'relative', overflow: 'hidden', flex: 1 }
821
825
  : { position: 'relative', overflow: 'hidden' }, ref: tableRef },
826
+ createMiniMap,
822
827
  React.createElement(DndProvider, { backend: HTML5Backend, context: window },
823
828
  React.createElement(AntTable, __assign({ className: classes, bordered: bordered, pagination: showInnerPagination
824
829
  ? pagination
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.2.18-39",
3
+ "version": "4.2.18-40",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",