@chaoswise/ui 2.6.7 → 2.6.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.
@@ -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
  };
@@ -36,7 +36,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
36
36
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
37
37
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
38
38
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
39
- import React, { useState, useEffect, Fragment, forwardRef, useMemo } from "react";
39
+ import React, { useState, useEffect, Fragment, forwardRef, useMemo, useCallback } from "react";
40
40
  import { filterTreeByName, filterTree, filterTreeByNameTable, filterObj, getNotSelectKeys, getKeysAndTitle, getBottomKey, renderLeafNodetree, renderRelationNode, createTitle } from "./utils";
41
41
  import classnames from "classnames";
42
42
  import Drag from "./Drag";
@@ -257,21 +257,6 @@ var QuickTransfer = /*#__PURE__*/forwardRef(function (props, ref) {
257
257
  return !i.disabled;
258
258
  }));
259
259
  setCheckValue(finalCheckValue);
260
- var newData = [];
261
- var listCheckedKeys_ = [];
262
- dataSource.forEach(function (item, index) {
263
- if (isMath(item.title, saveSearchValueLeft)) {
264
- newData.push(dataSource[index]);
265
- }
266
- });
267
- listCheckedKeys_ = newData.filter(function (item) {
268
- return finalCheckValue.find(function (i) {
269
- return i.key == item.key;
270
- });
271
- }).map(function (item) {
272
- return item.key;
273
- });
274
- setListCheckedStyle(listCheckedKeys_, newData);
275
260
  }
276
261
  //回显table
277
262
  if (type === "table") {
@@ -287,19 +272,51 @@ var QuickTransfer = /*#__PURE__*/forwardRef(function (props, ref) {
287
272
  }
288
273
  }
289
274
  }
290
- }, [targetKeys, dataSource, saveSearchValueLeft]);
291
- //触发前端自定义搜索
275
+ }, [targetKeys, dataSource]);
292
276
  useEffect(function () {
293
- if (searchValueLeft !== undefined) {
294
- handleSearch(searchValueLeft);
277
+ // 左侧受控值绑定
278
+ if (searchValueLeft !== undefined && searchValueLeft !== saveSearchValueLeft) {
295
279
  // 初始化搜索结果
296
280
  setSaveSearchValueLeft(searchValueLeft);
297
281
  }
298
- if (searchValueRight !== undefined) {
282
+ }, [searchValueLeft, saveSearchValueLeft]);
283
+ useEffect(function () {
284
+ // 右侧受控值绑定
285
+ if (searchValueRight !== undefined && searchValueRight !== saveSearchValueRight) {
299
286
  // 初始化搜索结果
300
287
  setSaveSearchValueRight(searchValueRight);
301
288
  }
302
- }, [searchValueLeft, searchValueRight]);
289
+ }, [searchValueRight, saveSearchValueRight]);
290
+
291
+ // 左侧搜索框输入触发
292
+ var handleSearch = useCallback(function (searchValue) {
293
+ var newData = [];
294
+ var listCheckedKeys_ = [];
295
+ if (type === "list") {
296
+ dataSource.forEach(function (item, index) {
297
+ if (isMath(item.title, searchValue)) {
298
+ newData.push(dataSource[index]);
299
+ }
300
+ });
301
+ listCheckedKeys_ = newData.filter(function (item) {
302
+ return checkValue.find(function (i) {
303
+ return i.key == item.key;
304
+ });
305
+ }).map(function (item) {
306
+ return item.key;
307
+ });
308
+ setData(newData);
309
+ setListCheckedStyle(listCheckedKeys_, newData);
310
+ }
311
+ if (type === "table") {
312
+ newData = filterTreeByNameTable(dataSource, searchValue, searchColumns ? searchColumns : newSearchColumns);
313
+ setData(newData);
314
+ }
315
+ }, [dataSource, checkValue]);
316
+ useEffect(function () {
317
+ handleSearch(saveSearchValueLeft);
318
+ }, [handleSearch, saveSearchValueLeft]);
319
+
303
320
  //获取左侧列表选中的key
304
321
  useEffect(function () {
305
322
  if (getTargetKeys) {
@@ -347,35 +364,6 @@ var QuickTransfer = /*#__PURE__*/forwardRef(function (props, ref) {
347
364
  setIndeterminate(!!listCheckedKeys.length && listCheckedKeys.length < dataSource.length);
348
365
  setCheckAll(listCheckedKeys.length === dataSource.length);
349
366
  };
350
- // 左侧搜索框输入触发
351
- var handleSearch = function handleSearch(searchValue) {
352
- var newData = [];
353
- var listCheckedKeys_ = [];
354
- if (type === "list") {
355
- dataSource.forEach(function (item, index) {
356
- if (isMath(item.title, searchValue)) {
357
- newData.push(dataSource[index]);
358
- }
359
- });
360
- listCheckedKeys_ = newData.filter(function (item) {
361
- return checkValue.find(function (i) {
362
- return i.key == item.key;
363
- });
364
- }).map(function (item) {
365
- return item.key;
366
- });
367
- setData(newData);
368
- setListCheckedStyle(listCheckedKeys_, newData);
369
- }
370
- // if (type === "tree") {
371
- // newData = filterTree(dataSource, searchValue);
372
- // setData(newData);
373
- // }
374
- if (type === "table") {
375
- newData = filterTreeByNameTable(dataSource, searchValue, searchColumns ? searchColumns : newSearchColumns);
376
- setData(newData);
377
- }
378
- };
379
367
 
380
368
  //type为list 左侧列表选中触发的事件
381
369
  var onChangeChecked = function onChangeChecked(e, value) {
@@ -595,17 +583,15 @@ var QuickTransfer = /*#__PURE__*/forwardRef(function (props, ref) {
595
583
  var showSearchChange = function showSearchChange(e) {
596
584
  onSearchChange && onSearchChange(e);
597
585
  onLeftSearchChange && onLeftSearchChange(e);
598
- // 保存搜索结果
599
- if (searchValueLeft === undefined) {
600
- handleSearch(e.target.value);
601
- setSaveSearchValueLeft(e.target.value);
602
- }
586
+ // 保存搜索结果,实时保存不然受控模式中文会有问题
587
+ // if (searchValueLeft === undefined) {
588
+ setSaveSearchValueLeft(e.target.value);
589
+ // handleSearch(e.target.value);
590
+ // }
603
591
  };
604
592
  var showSearchChangeRight = function showSearchChangeRight(e) {
605
593
  onRightSearchChange(e);
606
- if (searchValueRight === undefined) {
607
- setSaveSearchValueRight(e.target.value);
608
- }
594
+ setSaveSearchValueRight(e.target.value);
609
595
  };
610
596
  // 全选状态改变触发
611
597
  var onCheckAllChange = function onCheckAllChange(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaoswise/ui",
3
- "version": "2.6.7",
3
+ "version": "2.6.9",
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": "b2d08aba1d82098b6b14d2086af3d1cc8262dcd8"
153
153
  }