@chaoswise/ui 2.6.7 → 2.6.8

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.
@@ -95,37 +95,29 @@ var CWTable = function CWTable(_ref, ref) {
95
95
  isRealTimeDrag = _ref$isRealTimeDrag === void 0 ? true : _ref$isRealTimeDrag,
96
96
  rest = _objectWithoutProperties(_ref, _excluded);
97
97
  var prefix = rest.getPrefixCls();
98
- var _useState = useState(1),
98
+ //filterDropDown和表格联用控制表格的列是否显示
99
+ var _useState = useState([]),
99
100
  _useState2 = _slicedToArray(_useState, 2),
100
- scrollY = _useState2[0],
101
- setScrollY = _useState2[1]; // Fixed: 0 header 元素丢失
102
- var _useState3 = useState(0),
101
+ showCols = _useState2[0],
102
+ setShowCols = _useState2[1];
103
+ //异步加载设置loading
104
+ var _useState3 = useState(''),
103
105
  _useState4 = _slicedToArray(_useState3, 2),
104
- tableWrapperHeight = _useState4[0],
105
- setTableWrapperHeight = _useState4[1];
106
- //filterDropDown和表格联用控制表格的列是否显示
106
+ loading = _useState4[0],
107
+ setLoading = _useState4[1];
107
108
  var _useState5 = useState([]),
108
109
  _useState6 = _slicedToArray(_useState5, 2),
109
- showCols = _useState6[0],
110
- setShowCols = _useState6[1];
111
- //异步加载设置loading
110
+ tableColumn = _useState6[0],
111
+ setTableColumn = _useState6[1];
112
+ // 编辑行,编辑中的那一行的id
112
113
  var _useState7 = useState(''),
113
114
  _useState8 = _slicedToArray(_useState7, 2),
114
- loading = _useState8[0],
115
- setLoading = _useState8[1];
115
+ editingKey = _useState8[0],
116
+ setEditingKey = _useState8[1];
116
117
  var _useState9 = useState([]),
117
118
  _useState10 = _slicedToArray(_useState9, 2),
118
- tableColumn = _useState10[0],
119
- setTableColumn = _useState10[1];
120
- // 编辑行,编辑中的那一行的id
121
- var _useState11 = useState(''),
122
- _useState12 = _slicedToArray(_useState11, 2),
123
- editingKey = _useState12[0],
124
- setEditingKey = _useState12[1];
125
- var _useState13 = useState([]),
126
- _useState14 = _slicedToArray(_useState13, 2),
127
- finalDataSource = _useState14[0],
128
- setFinalDataSource = _useState14[1];
119
+ finalDataSource = _useState10[0],
120
+ setFinalDataSource = _useState10[1];
129
121
 
130
122
  // 重写onChange
131
123
  var sorterInfo = useRef({}); // header中也会修改sorterInfo中的属性
@@ -188,13 +180,13 @@ var CWTable = function CWTable(_ref, ref) {
188
180
  };
189
181
 
190
182
  // 设置前端分页
191
- var _useState15 = useState({
183
+ var _useState11 = useState({
192
184
  current: 1,
193
185
  pageSize: 30
194
186
  }),
195
- _useState16 = _slicedToArray(_useState15, 2),
196
- pageInfo = _useState16[0],
197
- setPageInfo = _useState16[1];
187
+ _useState12 = _slicedToArray(_useState11, 2),
188
+ pageInfo = _useState12[0],
189
+ setPageInfo = _useState12[1];
198
190
  // 设置搜索字段
199
191
  var searchInfo = useRef({}); // 搜索信息
200
192
  var watcher = useRef(null); // null
@@ -238,7 +230,7 @@ var CWTable = function CWTable(_ref, ref) {
238
230
  _columnFilter$isShowS = columnFilter.isShowSelectAll,
239
231
  isShowSelectAll = _columnFilter$isShowS === void 0 ? false : _columnFilter$isShowS;
240
232
  var resetSortDataSource = function resetSortDataSource() {
241
- var _dataSource = _toConsumableArray(dataSource);
233
+ var _dataSource = dataSource;
242
234
  if (frontPagination) {
243
235
  var _current = pagination.current,
244
236
  _pageSize = pagination.pageSize,
@@ -267,10 +259,10 @@ var CWTable = function CWTable(_ref, ref) {
267
259
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
268
260
  var entry = _step.value;
269
261
  var _className = entry.target.className;
270
- var height = entry.contentRect.height;
262
+ var _height = entry.contentRect.height;
271
263
  var offsetHeight = entry.target.offsetHeight;
272
264
  if (_className.includes('cw-common-table')) {
273
- outerHeight = height;
265
+ outerHeight = _height;
274
266
  }
275
267
  if (_className.includes('cw-table-extra-header-area')) {
276
268
  extraHeaderHeight = offsetHeight; // padding不计算高度
@@ -281,21 +273,39 @@ var CWTable = function CWTable(_ref, ref) {
281
273
  if (_className.includes('cw-table-pagination-box')) {
282
274
  paginationHeight = offsetHeight;
283
275
  }
284
- if (_className.includes('-table-header')) {
285
- tableHeaderHeight = height;
286
- }
287
276
  }
288
-
289
- // 计算表格高度
290
277
  } catch (err) {
291
278
  _iterator.e(err);
292
279
  } finally {
293
280
  _iterator.f();
294
281
  }
282
+ if (showHeader) {
283
+ var tableHeaderDom = tableRef.current.querySelector(".".concat(prefix, "-table-thead"));
284
+ if (tableHeaderDom) {
285
+ var _tableHeaderDom$getBo = tableHeaderDom.getBoundingClientRect(),
286
+ height = _tableHeaderDom$getBo.height;
287
+ tableHeaderHeight = height;
288
+ }
289
+ }
290
+ // 计算表格高度
295
291
  var tableWrapperHeight = outerHeight - searchBarHeight - extraHeaderHeight - paginationHeight;
296
292
  var scrollY = tableWrapperHeight - tableHeaderHeight - 2;
297
- setTableWrapperHeight(tableWrapperHeight);
298
- setScrollY(scrollY);
293
+ tableRef.current.style.height = "".concat(tableWrapperHeight, "px");
294
+ var maxHeight = "".concat(scrollY, "px");
295
+ if (finalDataSource.length !== 0) {
296
+ tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.height = maxHeight;
297
+ tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.maxHeight = maxHeight;
298
+ var allFixedBodyInnerDom = tableRef.current.querySelectorAll(".".concat(prefix, "-table-body-inner"));
299
+ if (allFixedBodyInnerDom) {
300
+ allFixedBodyInnerDom.forEach(function (fixedBody) {
301
+ fixedBody.style.maxHeight = maxHeight;
302
+ });
303
+ }
304
+ } else {
305
+ tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.height = 'unset';
306
+ tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.maxHeight = "unset";
307
+ tableRef.current.querySelector(".".concat(prefix, "-table-placeholder")).style.height = maxHeight;
308
+ }
299
309
  });
300
310
  watcher.current.observe(outContainerRef.current);
301
311
  watcher.current.observe(extraHeaderContainerRef.current);
@@ -319,23 +329,7 @@ var CWTable = function CWTable(_ref, ref) {
319
329
  (_watcher$current4 = watcher.current) === null || _watcher$current4 === void 0 || _watcher$current4.unobserve(paginationContainerRef.current);
320
330
  }
321
331
  };
322
- }, [autoHeight]);
323
- useEffect(function () {
324
- if (!autoHeight) {
325
- return;
326
- }
327
- var tableHeaderDom;
328
- if (showHeader) {
329
- tableHeaderDom = tableRef.current.querySelector(".".concat(prefix, "-table-header"));
330
- watcher.current.observe(tableHeaderDom);
331
- }
332
- return function () {
333
- if (tableHeaderDom) {
334
- var _watcher$current5;
335
- (_watcher$current5 = watcher.current) === null || _watcher$current5 === void 0 || _watcher$current5.unobserve(tableHeaderDom);
336
- }
337
- };
338
- }, [showHeader, autoHeight]);
332
+ }, [autoHeight, finalDataSource, showHeader]);
339
333
  var editMode = '';
340
334
  columns.find(function (v) {
341
335
  var _v$form;
@@ -414,39 +408,25 @@ var CWTable = function CWTable(_ref, ref) {
414
408
  useEffect(function () {
415
409
  resizeColsRef.current = tableColumn;
416
410
  }, [tableColumn]);
417
-
411
+ var _pagination = useMemo(function () {
412
+ return pagination ? pagination : {};
413
+ }, [pagination]);
418
414
  // 设置分页页码
419
415
  useEffect(function () {
420
- if (pagination) {
421
- setPageInfo(function (prePageInfo) {
422
- var newPageInfo = _objectSpread({}, prePageInfo);
423
- var defaultCurrent = pagination.defaultCurrent,
424
- defaultPageSize = pagination.defaultPageSize;
425
- if (defaultCurrent) {
426
- newPageInfo.current = defaultCurrent;
427
- }
428
- if (defaultPageSize) {
429
- newPageInfo.pageSize = defaultPageSize;
430
- }
431
- return newPageInfo;
432
- });
433
- }
434
- }, [pagination]);
416
+ setPageInfo(function (prePageInfo) {
417
+ var newPageInfo = _objectSpread({}, prePageInfo);
418
+ if (_pagination.defaultCurrent) {
419
+ newPageInfo.current = _pagination.defaultCurrent;
420
+ }
421
+ if (_pagination.defaultPageSize) {
422
+ newPageInfo.pageSize = _pagination.defaultPageSize;
423
+ }
424
+ return newPageInfo;
425
+ });
426
+ }, [_pagination.defaultCurrent, _pagination.defaultPageSize]);
435
427
  var _showCols = useMemo(function () {
436
428
  return columnFilter.hasOwnProperty('showColumns') ? showColumns : showCols;
437
429
  }, [showColumns, showCols]);
438
- useEffect(function () {
439
- if (!autoHeight) {
440
- return;
441
- }
442
- var maxHeight = "".concat(scrollY, "px");
443
- if (finalDataSource.length !== 0) {
444
- tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.height = maxHeight;
445
- } else {
446
- tableRef.current.querySelector(".".concat(prefix, "-table-body")).style.height = 'unset';
447
- tableRef.current.querySelector(".".concat(prefix, "-table-placeholder")).style.height = maxHeight;
448
- }
449
- }, [scrollY, finalDataSource]);
450
430
 
451
431
  // 表格滚动到底触发函数
452
432
  useEffect(function () {
@@ -514,9 +494,9 @@ var CWTable = function CWTable(_ref, ref) {
514
494
  return _showCols.includes(col.dataIndex);
515
495
  });
516
496
  };
517
- var bodyScroll = autoHeight ? merge({
518
- y: scrollY
519
- }, scroll) : scroll;
497
+ var bodyScroll = autoHeight ? merge(scroll, {
498
+ y: 1
499
+ }) : scroll;
520
500
 
521
501
  // 表格数据有children时点击展开的函数
522
502
  var onExpand = function onExpand(expanded, record) {
@@ -657,14 +637,6 @@ var CWTable = function CWTable(_ref, ref) {
657
637
  onShowSizeChange: onShowSizeChange,
658
638
  size: size == 'small' ? 'small' : ''
659
639
  });
660
- // if (frontPagination) {
661
- // return {
662
- // ...common,
663
- // current: pageInfo.current,
664
- // pageSize: pageInfo.pageSize,
665
- // total: dataSource.length,
666
- // }
667
- // }
668
640
  return _objectSpread(_objectSpread({}, common), {}, {
669
641
  current: current || pageInfo.current,
670
642
  pageSize: pageSize || pageInfo.pageSize,
@@ -791,8 +763,7 @@ var CWTable = function CWTable(_ref, ref) {
791
763
  })), /*#__PURE__*/React.createElement("div", {
792
764
  className: "cw-table-wrapper-main",
793
765
  style: {
794
- // padding: Object.keys(searchBar).length > 0 && '0 32px',
795
- height: autoHeight ? tableWrapperHeight : 'auto'
766
+ height: "auto"
796
767
  },
797
768
  ref: tableRef
798
769
  }, /*#__PURE__*/React.createElement(EditableContext.Provider, {
@@ -828,14 +799,9 @@ var CWTable = function CWTable(_ref, ref) {
828
799
  expandedRowRender: expandedRowRender,
829
800
  loading: Boolean(loading)
830
801
  }, rest)))))), /*#__PURE__*/React.createElement("div", {
831
- className: classnames({
832
- 'cw-table-pagination-box': true,
833
- 'cw-table-pagination-box-none': !dataSource.length || !pagination
834
- })
835
- // style={{
836
- // padding: Object.keys(searchBar).length > 0 && '0 32px'
837
- // }}
838
- ,
802
+ className: classnames("cw-table-pagination-box", {
803
+ 'cw-table-pagination-box-none': !finalDataSource.length || !pagination
804
+ }),
839
805
  ref: paginationContainerRef
840
806
  }, /*#__PURE__*/React.createElement(_Pagination, getPaginationOption())));
841
807
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaoswise/ui",
3
- "version": "2.6.7",
3
+ "version": "2.6.8",
4
4
  "description": "公共UI库",
5
5
  "keywords": [
6
6
  "ui",
@@ -149,5 +149,5 @@
149
149
  "access": "public"
150
150
  },
151
151
  "license": "MIT",
152
- "gitHead": "fe06e4858602753c10139ad38f812f6c5aeb8146"
152
+ "gitHead": "9862a1d4a1f6556dd1fb953637e9bec805b4ea9a"
153
153
  }