@teamix/pro 1.5.33 → 1.5.34

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.
Files changed (59) hide show
  1. package/dist/pro.all.min.css +1 -1
  2. package/dist/pro.css +1 -1
  3. package/dist/pro.js +755 -208
  4. package/dist/pro.min.css +1 -1
  5. package/dist/pro.min.js +1 -1
  6. package/dist/pro.xconsole.min.css +1 -1
  7. package/es/form/Components/FormItem2/index.js +0 -1
  8. package/es/form/Components/SelectTable2/index.d.ts +97 -0
  9. package/es/form/Components/SelectTable2/index.js +39 -0
  10. package/es/form/ProForm/index.js +3 -1
  11. package/es/form/SchemaForm/adapterDecorator.js +1 -1
  12. package/es/form/SchemaForm/adapterType.js +2 -1
  13. package/es/global.scss +9 -0
  14. package/es/index.d.ts +1 -1
  15. package/es/index.js +1 -1
  16. package/es/table/components/Cell/index.d.ts +17 -0
  17. package/es/table/components/Cell/index.js +219 -0
  18. package/es/table/components/Layout/index.js +9 -7
  19. package/es/table/components/Pagination/index.d.ts +5 -4
  20. package/es/table/components/Pagination/index.js +5 -3
  21. package/es/table/components/TableContent/index.d.ts +7 -0
  22. package/es/table/components/TableContent/index.js +23 -0
  23. package/es/table/index.js +118 -126
  24. package/es/table/index.scss +1 -1
  25. package/es/table/typing.d.ts +9 -2
  26. package/es/table/utils/genAutoWidthColumns.d.ts +2 -2
  27. package/es/table/utils/genAutoWidthColumns.js +65 -16
  28. package/es/table/utils/genProColumnToColumn.js +39 -4
  29. package/es/table/utils/processColumns.d.ts +8 -0
  30. package/es/table/utils/processColumns.js +39 -0
  31. package/es/table/utils/useTableSelection.js +54 -5
  32. package/es/xconsole.scss +4 -4
  33. package/lib/form/Components/FormItem2/index.js +0 -1
  34. package/lib/form/Components/SelectTable2/index.d.ts +97 -0
  35. package/lib/form/Components/SelectTable2/index.js +47 -0
  36. package/lib/form/ProForm/index.js +3 -1
  37. package/lib/form/SchemaForm/adapterDecorator.js +1 -1
  38. package/lib/form/SchemaForm/adapterType.js +2 -1
  39. package/lib/global.scss +9 -0
  40. package/lib/index.d.ts +1 -1
  41. package/lib/index.js +1 -1
  42. package/lib/table/components/Cell/index.d.ts +17 -0
  43. package/lib/table/components/Cell/index.js +224 -0
  44. package/lib/table/components/Layout/index.js +8 -6
  45. package/lib/table/components/Pagination/index.d.ts +5 -4
  46. package/lib/table/components/Pagination/index.js +4 -2
  47. package/lib/table/components/TableContent/index.d.ts +7 -0
  48. package/lib/table/components/TableContent/index.js +34 -0
  49. package/lib/table/index.js +120 -128
  50. package/lib/table/index.scss +1 -1
  51. package/lib/table/typing.d.ts +9 -2
  52. package/lib/table/utils/genAutoWidthColumns.d.ts +2 -2
  53. package/lib/table/utils/genAutoWidthColumns.js +64 -15
  54. package/lib/table/utils/genProColumnToColumn.js +38 -3
  55. package/lib/table/utils/processColumns.d.ts +8 -0
  56. package/lib/table/utils/processColumns.js +46 -0
  57. package/lib/table/utils/useTableSelection.js +57 -5
  58. package/lib/xconsole.scss +4 -4
  59. package/package.json +1 -1
package/es/table/index.js CHANGED
@@ -5,6 +5,9 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
5
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
11
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
12
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -13,23 +16,18 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
13
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
17
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
18
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
- import React, { useState, useEffect, useRef, useMemo } from 'react';
19
+ import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
20
20
  import { Table, Checkbox } from '@alicloudfe/components';
21
21
  import Pagination from './components/Pagination';
22
+ import TableContent from './components/TableContent';
22
23
  import genProColumnToColumn from './utils/genProColumnToColumn';
23
24
  import { getGlobalConfig, useRequest, request as utilResquest, getDeepValue, getMessage, pickProps, usePrefixCls, getTargetValue } from '@teamix/utils';
24
- import { ProSkeletonRaw as Skeleton } from '../skeleton';
25
25
  import './index.scss';
26
26
  import Layout from './components/Layout';
27
27
  import { actionRefUseStateOn, emit, initActionRef, processDefaultFilter, useActionType } from './utils';
28
28
  import getTableProps from './utils/getTableProps';
29
- import getTableSortIcons from './utils/getTableSortIcons';
30
29
  import useTableSelection from './utils/useTableSelection';
31
30
  import FullScreen from './components/ToolBar/Fullscreen';
32
- import { EmptyContent } from '@teamix/pro-field';
33
31
  import { ProActionGroup } from '../actions';
34
32
  import classNames from 'classnames';
35
33
  import ProPageContainer from '../page-container';
@@ -38,42 +36,9 @@ import debounce from 'lodash.debounce';
38
36
  import CardView from './components/CardView';
39
37
  import { useUrlState } from '@teamix/hooks';
40
38
  import { getUrlStateFilter } from './utils/util';
39
+ import processColumns from './utils/processColumns';
41
40
  export * from './typing';
42
41
  var cls = usePrefixCls('teamix-pro-table');
43
- /**
44
- * 处理原生传入的 columns 以便于 选择列 方便处理
45
- * @param columns 原生传入的 columns
46
- * @returns
47
- */
48
- var processColumns = function processColumns(columns, initialColumns) {
49
- var _getGlobalConfig;
50
- var globalFilterColumns = (_getGlobalConfig = getGlobalConfig('ProTable')) === null || _getGlobalConfig === void 0 ? void 0 : _getGlobalConfig.filterColumns;
51
- var filterColumns = columns.filter(function (item) {
52
- return item.columnFilters !== false && (item === null || item === void 0 ? void 0 : item.hidden) !== true && (!globalFilterColumns || globalFilterColumns(_objectSpread({}, item)));
53
- });
54
- // 处理只剩一列批量选择的情况下宽度错乱问题
55
- if (filterColumns === null || filterColumns === void 0 ? void 0 : filterColumns.length) {
56
- var _initialColumns$;
57
- if ((filterColumns === null || filterColumns === void 0 ? void 0 : filterColumns.length) === 1) {
58
- var _filterColumns$, _filterColumns$2;
59
- if ((_filterColumns$ = filterColumns[0]) === null || _filterColumns$ === void 0 ? void 0 : _filterColumns$.width) {
60
- delete filterColumns[0].width;
61
- }
62
- if ((_filterColumns$2 = filterColumns[0]) === null || _filterColumns$2 === void 0 ? void 0 : _filterColumns$2.lock) {
63
- filterColumns[0].lock = false;
64
- }
65
- } else if (((_initialColumns$ = initialColumns[0]) === null || _initialColumns$ === void 0 ? void 0 : _initialColumns$.columnFilters) !== false) {
66
- var _initialColumns$2, _initialColumns$3;
67
- if ((_initialColumns$2 = initialColumns[0]) === null || _initialColumns$2 === void 0 ? void 0 : _initialColumns$2.width) {
68
- filterColumns[0].width = initialColumns[0].width;
69
- }
70
- if ((_initialColumns$3 = initialColumns[0]) === null || _initialColumns$3 === void 0 ? void 0 : _initialColumns$3.lock) {
71
- filterColumns[0].lock = initialColumns[0].lock;
72
- }
73
- }
74
- }
75
- return filterColumns;
76
- };
77
42
  /** 默认请求翻页参数 */
78
43
  var globalPageKey = 'currentPage';
79
44
  var globalPageSizeKey = 'pageSize';
@@ -198,7 +163,9 @@ var ProTable = function ProTable(props) {
198
163
  _useState12 = _slicedToArray(_useState11, 2),
199
164
  showSkeleton = _useState12[0],
200
165
  setShowSkeleton = _useState12[1]; // 首次加载,渲染骨架屏
201
- var skeletonDataSource = new Array(skeletonSize).fill({});
166
+ var skeletonDataSource = useMemo(function () {
167
+ return new Array(skeletonSize).fill({});
168
+ }, [skeletonSize]);
202
169
  var requestDataKey = method.toLowerCase() === 'get' ? 'params' : 'data';
203
170
  // 如果使用 customRequest 的话,内置 loading
204
171
  var _useState13 = useState(requestWhenMount),
@@ -214,8 +181,8 @@ var ProTable = function ProTable(props) {
214
181
  setFilteredColumns = _useState16[1];
215
182
  // 全局状态 : 自适应表格
216
183
  var autoWidth = useMemo(function () {
217
- var _getGlobalConfig2;
218
- return ((_getGlobalConfig2 = getGlobalConfig('ProTable')) === null || _getGlobalConfig2 === void 0 ? void 0 : _getGlobalConfig2.autoWidth) || autoWidthProp;
184
+ var _getGlobalConfig;
185
+ return ((_getGlobalConfig = getGlobalConfig('ProTable')) === null || _getGlobalConfig === void 0 ? void 0 : _getGlobalConfig.autoWidth) || autoWidthProp;
219
186
  }, [autoWidthProp]);
220
187
  // 判断是否有操作列,有的话则渲染一个 shadow dom
221
188
  var hasActionColumn = false;
@@ -405,8 +372,8 @@ var ProTable = function ProTable(props) {
405
372
  });
406
373
  // 全局状态 : 大数据截断
407
374
  var globalUseMaxData = useMemo(function () {
408
- var _getGlobalConfig3;
409
- return (_getGlobalConfig3 = getGlobalConfig('ProTable')) === null || _getGlobalConfig3 === void 0 ? void 0 : _getGlobalConfig3.useMaxData;
375
+ var _getGlobalConfig2;
376
+ return (_getGlobalConfig2 = getGlobalConfig('ProTable')) === null || _getGlobalConfig2 === void 0 ? void 0 : _getGlobalConfig2.useMaxData;
410
377
  }, []);
411
378
  // 非全屏状态下的
412
379
  var normalDataFilterFormRef = useRef();
@@ -453,7 +420,9 @@ var ProTable = function ProTable(props) {
453
420
  if (showSkeleton && result) {
454
421
  result.disabled = true;
455
422
  }
456
- return result;
423
+ return _objectSpread({
424
+ _primaryKey: props.primaryKey
425
+ }, result);
457
426
  },
458
427
  titleProps: function titleProps() {
459
428
  var result = {};
@@ -523,11 +492,22 @@ var ProTable = function ProTable(props) {
523
492
  var columns = processColumns(propsColumns !== null && propsColumns !== void 0 ? propsColumns : [], propsColumns);
524
493
  setFilteredColumns(columns);
525
494
  (_actionRef$current = actionRef.current) === null || _actionRef$current === void 0 ? void 0 : (_actionRef$current$se = _actionRef$current.setState) === null || _actionRef$current$se === void 0 ? void 0 : _actionRef$current$se.call(_actionRef$current, 'filterColumns', columns);
495
+ if (autoWidth) {
496
+ reGenFilteredColumnsByAutoWidth(columns);
497
+ }
526
498
  }, [propsColumns]);
527
499
  // dataSource 受控
528
500
  useEffect(function () {
529
501
  if (propsDataSource) {
530
502
  _setData(propsDataSource);
503
+ if (autoWidth) {
504
+ shadowContainer({
505
+ columns: filteredColumns,
506
+ data: propsDataSource,
507
+ shadowContainerRef: shadowContainerRef
508
+ });
509
+ reGenFilteredColumnsByAutoWidth();
510
+ }
531
511
  }
532
512
  }, [propsDataSource]);
533
513
  // 初始化 ActionRef。
@@ -745,7 +725,9 @@ var ProTable = function ProTable(props) {
745
725
  if (Number.isInteger(time) && time >= 1000) {
746
726
  autoRefreshTimerRef.current = setTimeout(function () {
747
727
  // 自动刷新不显示 loading
748
- _request({}, true);
728
+ // 当表格自适应时,自动刷新要显示 loading ,否则表格自适应会出问题
729
+ // setShowLoading(true)
730
+ _request({}, !autoWidth);
749
731
  }, Number(time));
750
732
  emit('PRO_TABLE_REFRESH_TIMER_FLAG', Number(time));
751
733
  }
@@ -830,7 +812,7 @@ var ProTable = function ProTable(props) {
830
812
  }
831
813
  });
832
814
  // 请求函数
833
- function _request(params, noLoading, filterParams, isReset) {
815
+ var _request = useCallback(function (params, noLoading, filterParams, isReset) {
834
816
  var _dataFilterFormRef$cu2, _actionRef$current$ge, _actionRef$current6, _actionRef$current6$g, _objectSpread3;
835
817
  // 首次渲染表格,获取 urlState 上的 表头 filter 数据
836
818
  if (bindUrl && (bindUrlProps === null || bindUrlProps === void 0 ? void 0 : bindUrlProps.headerFilters) !== false && dataRef.current.flag) {
@@ -934,7 +916,7 @@ var ProTable = function ProTable(props) {
934
916
  if (Number.isInteger(time) && time >= 1000) {
935
917
  autoRefreshTimerRef.current = setTimeout(function () {
936
918
  // 自动刷新不显示 loading
937
- _request(params, true);
919
+ _request(params, !autoWidth);
938
920
  }, Number(time));
939
921
  emit('PRO_TABLE_REFRESH_TIMER_FLAG', Number(time));
940
922
  }
@@ -945,57 +927,68 @@ var ProTable = function ProTable(props) {
945
927
  getData.run(requestData);
946
928
  }
947
929
  }
948
- }
949
- function onSort(dataIndex, order) {
930
+ }, [bindUrl, bindUrlProps, dataRef, url, customRequest, currentPage, pageSize, propsParams]);
931
+ var onSort = useCallback(function (dataIndex, order) {
950
932
  var nextSort = _defineProperty({}, dataIndex, order);
951
933
  setSort(nextSort);
952
934
  _request(targetFormatSort(nextSort));
953
- }
935
+ }, [_request, targetFormatSort]);
954
936
  // 处理 dataFilter 中的 onFilter、onReset
955
- var dataFilter = _objectSpread(_objectSpread({
956
- mode: 'inline',
957
- forceClear: true
958
- }, propsDataFilter), {}, {
959
- onInit: (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onInit) || requestWhenMount ? function (values) {
960
- var _propsDataFilter$onIn;
961
- // 表单初始化请求处理
962
- propsDataFilter === null || propsDataFilter === void 0 ? void 0 : (_propsDataFilter$onIn = propsDataFilter.onInit) === null || _propsDataFilter$onIn === void 0 ? void 0 : _propsDataFilter$onIn.call(propsDataFilter, values);
963
- !fullscreenState && requestWhenMount && _request({}, false, values);
964
- return true;
965
- } : undefined,
966
- onFilter: function onFilter(values) {
967
- var _actionRef$current7, _actionRef$current7$c;
968
- // 全屏状态,判断全屏表单onFilter是否禁用
969
- if (fullscreenState && !filterEnableRef.current.fullscreen) {
970
- filterEnableRef.current.fullscreen = true;
971
- return;
972
- }
973
- // 非全屏状态,判断普通表单onFiler是否禁用
974
- if (!fullscreenState && !filterEnableRef.current.normal) {
975
- filterEnableRef.current.normal = true;
976
- return;
937
+ var dataFilter = useMemo(function () {
938
+ return _objectSpread(_objectSpread({
939
+ mode: 'inline',
940
+ forceClear: true
941
+ }, propsDataFilter), {}, {
942
+ onInit: (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onInit) || requestWhenMount ? function (values) {
943
+ var _propsDataFilter$onIn;
944
+ // 表单初始化请求处理
945
+ propsDataFilter === null || propsDataFilter === void 0 ? void 0 : (_propsDataFilter$onIn = propsDataFilter.onInit) === null || _propsDataFilter$onIn === void 0 ? void 0 : _propsDataFilter$onIn.call(propsDataFilter, values);
946
+ !fullscreenState && requestWhenMount && _request({}, false, values);
947
+ return true;
948
+ } : undefined,
949
+ onFilter: function onFilter(values) {
950
+ var _actionRef$current7, _actionRef$current7$c;
951
+ // 全屏状态,判断全屏表单onFilter是否禁用
952
+ if (fullscreenState && !filterEnableRef.current.fullscreen) {
953
+ filterEnableRef.current.fullscreen = true;
954
+ return;
955
+ }
956
+ // 非全屏状态,判断普通表单onFiler是否禁用
957
+ if (!fullscreenState && !filterEnableRef.current.normal) {
958
+ filterEnableRef.current.normal = true;
959
+ return;
960
+ }
961
+ (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onFilter) && (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onFilter(values));
962
+ // 搜索变化时,暂时先清空选择
963
+ (_actionRef$current7 = actionRef.current) === null || _actionRef$current7 === void 0 ? void 0 : (_actionRef$current7$c = _actionRef$current7.clearRowSelection) === null || _actionRef$current7$c === void 0 ? void 0 : _actionRef$current7$c.call(_actionRef$current7);
964
+ setCurrentPage(1);
965
+ _request(_defineProperty({}, targetPageKey, 1), false, values);
966
+ },
967
+ onReset: function onReset(values) {
968
+ var _dataFilterFormRef$cu3;
969
+ (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onReset) && (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onReset());
970
+ (_dataFilterFormRef$cu3 = dataFilterFormRef.current) === null || _dataFilterFormRef$cu3 === void 0 ? void 0 : _dataFilterFormRef$cu3.reset();
971
+ setCurrentPage(1);
972
+ _request(_defineProperty({}, targetPageKey, 1), false, values);
977
973
  }
978
- (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onFilter) && (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onFilter(values));
979
- // 搜索变化时,暂时先清空选择
980
- (_actionRef$current7 = actionRef.current) === null || _actionRef$current7 === void 0 ? void 0 : (_actionRef$current7$c = _actionRef$current7.clearRowSelection) === null || _actionRef$current7$c === void 0 ? void 0 : _actionRef$current7$c.call(_actionRef$current7);
981
- setCurrentPage(1);
982
- _request(_defineProperty({}, targetPageKey, 1), false, values);
983
- },
984
- onReset: function onReset(values) {
985
- var _dataFilterFormRef$cu3;
986
- (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onReset) && (propsDataFilter === null || propsDataFilter === void 0 ? void 0 : propsDataFilter.onReset());
987
- (_dataFilterFormRef$cu3 = dataFilterFormRef.current) === null || _dataFilterFormRef$cu3 === void 0 ? void 0 : _dataFilterFormRef$cu3.reset();
988
- setCurrentPage(1);
989
- _request(_defineProperty({}, targetPageKey, 1), false, values);
990
- }
991
- });
992
- var getTableLoading = function getTableLoading() {
974
+ });
975
+ }, [propsDataFilter, fullscreenState, filterEnableRef, actionRef]);
976
+ var isLoading = useMemo(function () {
993
977
  if (!customRequest) {
994
978
  return showLoading && !showSkeleton && (getData.loading || props.loading);
995
979
  } else {
996
980
  return showLoading && !showSkeleton && (customTableLoading || props.loading);
997
981
  }
998
- };
982
+ }, [customRequest, showLoading, showSkeleton, customTableLoading, props.loading, getData]);
983
+ useEffect(function () {
984
+ if (autoWidth) {
985
+ reGenFilteredColumnsByAutoWidth();
986
+ }
987
+ }, [shadowContainerRef === null || shadowContainerRef === void 0 ? void 0 : shadowContainerRef.current]);
988
+ var memorizedGenProColumnToColumn = useMemo(function () {
989
+ var result = genProColumnToColumn(filteredColumns, showSkeleton, actionRef, context, dataTeamixSpm, bindUrl, bindUrlProps);
990
+ return result;
991
+ }, [filteredColumns, showSkeleton, actionRef, context, dataTeamixSpm, bindUrl, bindUrlProps]);
999
992
  var renderTable = function renderTable(isFullScreen) {
1000
993
  if (propsColumns) {
1001
994
  return /*#__PURE__*/React.createElement("div", {
@@ -1022,11 +1015,15 @@ var ProTable = function ProTable(props) {
1022
1015
  autoRefreshProps: autoRefreshProps,
1023
1016
  bindUrlProps: bindUrlProps,
1024
1017
  bindUrl: bindUrl
1025
- }), switchViewState === 'table' && /*#__PURE__*/React.createElement(Table.StickyLock, _objectSpread({
1018
+ }), autoWidth && shadowContainer({
1019
+ columns: filteredColumns,
1020
+ data: data,
1021
+ shadowContainerRef: shadowContainerRef
1022
+ }), hasActionColumn && shadowActionColumnContainer(filteredColumns, shadowActionColumnContainerRef), switchViewState === 'table' && /*#__PURE__*/React.createElement(TableContent, _objectSpread({
1026
1023
  hasBorder: false,
1027
1024
  dataSource: showSkeleton ? skeletonDataSource : data || props.dataSource,
1028
- columns: genProColumnToColumn(filteredColumns, showSkeleton, actionRef, context, dataTeamixSpm, bindUrl, bindUrlProps),
1029
- loading: getTableLoading(),
1025
+ columns: memorizedGenProColumnToColumn,
1026
+ loading: isLoading,
1030
1027
  className: classNames('teamix-pro-table', tableClassName, {
1031
1028
  'with-row-select': rowSelection,
1032
1029
  'teamix-pro-tree-table': isTree
@@ -1037,14 +1034,12 @@ var ProTable = function ProTable(props) {
1037
1034
  sort: sort,
1038
1035
  primaryKey: primaryKey,
1039
1036
  rowSelection: rowSelection,
1040
- emptyContent: /*#__PURE__*/React.createElement(EmptyContent, _objectSpread({}, emptyProps)),
1041
- sortIcons: getTableSortIcons(),
1042
1037
  fixedHeader: fullscreenState || fixedTableBody,
1043
1038
  maxBodyHeight: "calc(100vh - ".concat(headerHeight, "px)")
1044
1039
  }, pickProps(getTableProps(), otherProps))), switchViewState === 'card' && /*#__PURE__*/React.createElement(CardView, {
1045
1040
  dataSource: showSkeleton ? skeletonDataSource : data || props.dataSource,
1046
1041
  showSkeleton: showSkeleton,
1047
- loading: getTableLoading(),
1042
+ loading: isLoading,
1048
1043
  originColumns: propsColumns,
1049
1044
  cardViewProps: cardViewProps,
1050
1045
  scrollHeight: fullscreenState || fixedTableBody ? "calc(100vh - ".concat(headerHeight, "px)") : undefined,
@@ -1086,34 +1081,33 @@ var ProTable = function ProTable(props) {
1086
1081
  })));
1087
1082
  } else return footerAction;
1088
1083
  };
1089
- var renderFooter = function renderFooter() {
1090
- function onChangePagination(currentPage) {
1091
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1092
- // 翻页默认清空选择
1093
- if (!reserveSelectedRecords) {
1094
- var _actionRef$current8, _actionRef$current8$c;
1095
- (_actionRef$current8 = actionRef.current) === null || _actionRef$current8 === void 0 ? void 0 : (_actionRef$current8$c = _actionRef$current8.clearRowSelection) === null || _actionRef$current8$c === void 0 ? void 0 : _actionRef$current8$c.call(_actionRef$current8);
1096
- }
1097
- setCurrentPage(currentPage);
1098
- _request(_objectSpread(_defineProperty({}, targetPageKey, currentPage), params));
1084
+ var onChangePagination = useCallback(function (currentPage) {
1085
+ var _objectSpread4;
1086
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1087
+ // 翻页默认清空选择
1088
+ if (!reserveSelectedRecords) {
1089
+ var _actionRef$current8, _actionRef$current8$c;
1090
+ (_actionRef$current8 = actionRef.current) === null || _actionRef$current8 === void 0 ? void 0 : (_actionRef$current8$c = _actionRef$current8.clearRowSelection) === null || _actionRef$current8$c === void 0 ? void 0 : _actionRef$current8$c.call(_actionRef$current8);
1099
1091
  }
1100
- function onChangePaginationSize(currentPageSize) {
1101
- var _request10;
1102
- // 翻页默认清空选择
1103
- if (!reserveSelectedRecords) {
1104
- var _actionRef$current9, _actionRef$current9$c;
1105
- (_actionRef$current9 = actionRef.current) === null || _actionRef$current9 === void 0 ? void 0 : (_actionRef$current9$c = _actionRef$current9.clearRowSelection) === null || _actionRef$current9$c === void 0 ? void 0 : _actionRef$current9$c.call(_actionRef$current9);
1106
- }
1107
- setPageSize(currentPageSize);
1108
- setCurrentPage(1);
1109
- _request((_request10 = {}, _defineProperty(_request10, targetPageSizeKey, currentPageSize), _defineProperty(_request10, targetPageKey, 1), _request10));
1092
+ setCurrentPage(currentPage);
1093
+ _request(_objectSpread((_objectSpread4 = {}, _defineProperty(_objectSpread4, targetPageKey, currentPage), _defineProperty(_objectSpread4, "pageSize", pageSize), _objectSpread4), params));
1094
+ }, [reserveSelectedRecords, targetPageKey, actionRef, pageSize]);
1095
+ var onChangePaginationSize = useCallback(function (currentPageSize) {
1096
+ var _request10;
1097
+ // 翻页默认清空选择
1098
+ if (!reserveSelectedRecords) {
1099
+ var _actionRef$current9, _actionRef$current9$c;
1100
+ (_actionRef$current9 = actionRef.current) === null || _actionRef$current9 === void 0 ? void 0 : (_actionRef$current9$c = _actionRef$current9.clearRowSelection) === null || _actionRef$current9$c === void 0 ? void 0 : _actionRef$current9$c.call(_actionRef$current9);
1110
1101
  }
1102
+ setPageSize(currentPageSize);
1103
+ setCurrentPage(1);
1104
+ _request((_request10 = {}, _defineProperty(_request10, targetPageSizeKey, currentPageSize), _defineProperty(_request10, targetPageKey, 1), _request10));
1105
+ }, [reserveSelectedRecords, actionRef, targetPageSizeKey, targetPageKey, currentPage]);
1106
+ var renderFooter = function renderFooter() {
1111
1107
  function renderRowSelection() {
1112
1108
  if (rowSelection) {
1113
1109
  if (showSkeleton) {
1114
- return /*#__PURE__*/React.createElement("div", {
1115
- className: cls('footer-left-wrapper')
1116
- }, /*#__PURE__*/React.createElement(Skeleton.Footer.Operation, null));
1110
+ return null;
1117
1111
  } else {
1118
1112
  return /*#__PURE__*/React.createElement("div", {
1119
1113
  className: cls('footer-left-wrapper')
@@ -1127,9 +1121,7 @@ var ProTable = function ProTable(props) {
1127
1121
  }
1128
1122
  } else if (footerAction) {
1129
1123
  if (showSkeleton) {
1130
- return /*#__PURE__*/React.createElement("div", {
1131
- className: cls('footer-left-wrapper')
1132
- }, /*#__PURE__*/React.createElement(Skeleton.Footer.Operation, null));
1124
+ return null;
1133
1125
  } else {
1134
1126
  return /*#__PURE__*/React.createElement("div", {
1135
1127
  className: cls('footer-left-wrapper')
@@ -1150,7 +1142,7 @@ var ProTable = function ProTable(props) {
1150
1142
  })
1151
1143
  }, renderRowSelection(), /*#__PURE__*/React.createElement("div", {
1152
1144
  className: cls('footer-right-wrapper')
1153
- }, showSkeleton ? /*#__PURE__*/React.createElement(Skeleton.Footer.Pagination, null) : /*#__PURE__*/React.createElement(React.Fragment, null, data.length > 0 && /*#__PURE__*/React.createElement(Pagination, _objectSpread({
1145
+ }, showSkeleton ? null : /*#__PURE__*/React.createElement(React.Fragment, null, data.length > 0 && /*#__PURE__*/React.createElement(Pagination, _objectSpread({
1154
1146
  className: cls('pagination'),
1155
1147
  onChange: function onChange(number, e) {
1156
1148
  onChangePagination(number);
@@ -1178,7 +1170,7 @@ var ProTable = function ProTable(props) {
1178
1170
  })
1179
1171
  }, renderRowSelection(), /*#__PURE__*/React.createElement("div", {
1180
1172
  className: cls('footer-right-wrapper')
1181
- }, showSkeleton ? /*#__PURE__*/React.createElement(Skeleton.Footer.Pagination, null) : footer));
1173
+ }, showSkeleton ? null : footer));
1182
1174
  }
1183
1175
  };
1184
1176
  // 判断是否需要吸底
@@ -1205,7 +1197,7 @@ var ProTable = function ProTable(props) {
1205
1197
  // 'footer-suction': footerSuctionState && footerSuction,
1206
1198
  }),
1207
1199
  ref: tableRef
1208
- }, showShadowContainer && shadowContainer({
1200
+ }, autoWidth && shadowContainer({
1209
1201
  columns: filteredColumns,
1210
1202
  data: data,
1211
1203
  shadowContainerRef: shadowContainerRef
@@ -103,7 +103,7 @@ $fullscreenPadding: 24px;
103
103
  pointer-events: none;
104
104
  display: flex;
105
105
  }
106
-
106
+
107
107
  // sort icon
108
108
  .next-table-sort.next-table-header-icon {
109
109
  line-height: 16px;
@@ -24,6 +24,8 @@ declare type TDataService = {
24
24
  };
25
25
  export declare type responsivePaginationType = 'mini' | 'small' | 'simple' | 'normal';
26
26
  export declare type ProTableColumnProps = {
27
+ /** 是否开启了自动计算宽度 */
28
+ isAutoWidth?: boolean;
27
29
  /** 自动计算宽度时的被挤占的情况 */
28
30
  shrink?: number;
29
31
  /** 是否自动适应该列宽度 */
@@ -182,7 +184,8 @@ export declare type ProTableProps = {
182
184
  autoRedirect?: boolean;
183
185
  /** 使用超大数据模式 **/
184
186
  useMaxData?: boolean;
185
- } & Omit<TableProps, 'columns'> & ProTableTopAreaProps;
187
+ rowSelection?: rowSelectionType;
188
+ } & Omit<TableProps, 'columns' | 'rowSelection'> & ProTableTopAreaProps;
186
189
  export declare type rowSelectionType = {
187
190
  getProps?: (record: any, index: number) => any;
188
191
  onChange?: (selectedRowKeys: Array<any>, records: Array<any>) => void;
@@ -194,7 +197,11 @@ export declare type rowSelectionType = {
194
197
  titleProps?: () => any;
195
198
  columnProps?: () => any;
196
199
  titleAddons?: () => any;
197
- };
200
+ /** 默认选中的 Key 值 **/
201
+ defaultSelectedRowKeys?: any[];
202
+ /** 默认选中的 record 值 **/
203
+ defaultSelectedRecords?: any[];
204
+ } & TableProps['rowSelection'];
198
205
  export declare type innerRowSelectionType = {
199
206
  rowSelection: rowSelectionType;
200
207
  selectedRowKeys: string[];
@@ -6,13 +6,13 @@ import { ProTableColumnProps, ITableCellRender } from '../typing';
6
6
  * @param data
7
7
  * @returns
8
8
  */
9
- export declare function genAutoWidthColumns(fileteredColumns: ProTableColumnProps[], ref: MutableRefObject<HTMLDivElement | null>, data: any[], size: 'small' | 'medium', useRowSelection?: boolean | undefined, actionColumnRef?: MutableRefObject<HTMLDivElement | null>): ProTableColumnProps[];
9
+ export declare function genAutoWidthColumns(columns: ProTableColumnProps[], ref: MutableRefObject<HTMLDivElement | null>, data: any[], size: 'small' | 'medium', useRowSelection?: boolean | undefined, actionColumnRef?: MutableRefObject<HTMLDivElement | null>): ProTableColumnProps[];
10
10
  interface IShadowContainerProps {
11
11
  columns: ProTableColumnProps[];
12
12
  data: any[];
13
13
  shadowContainerRef: MutableRefObject<null>;
14
14
  }
15
- export declare const shadowContainer: (props: IShadowContainerProps) => JSX.Element;
15
+ export declare const shadowContainer: (props: IShadowContainerProps) => JSX.Element | null;
16
16
  export declare const shadowActionColumnContainer: (columns: ProTableColumnProps[], shadowActionColumnContainerRef: MutableRefObject<null>) => JSX.Element | undefined;
17
17
  export declare const computeableWidthTypeList: {
18
18
  dateTime: (data: any[], render: ITableCellRender) => any;
@@ -8,7 +8,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
9
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
10
  import React, { createRef } from 'react';
11
- import { getTargetValue } from '@teamix/utils';
11
+ import { getTargetValue, _ } from '@teamix/utils';
12
12
  import { renderCell } from './pureColumnRender';
13
13
  import { renderColumnsTitle } from './columnRender';
14
14
  import { ProActionGroup } from '../../actions';
@@ -26,21 +26,25 @@ var columnShrinkMaxWidth = 100;
26
26
  * @param data
27
27
  * @returns
28
28
  */
29
- export function genAutoWidthColumns(fileteredColumns, ref, data, size, useRowSelection, actionColumnRef) {
30
- if (!ref.current) {
31
- return fileteredColumns;
29
+ export function genAutoWidthColumns(columns, ref, data, size, useRowSelection, actionColumnRef) {
30
+ if (!(ref === null || ref === void 0 ? void 0 : ref.current)) {
31
+ return columns;
32
32
  }
33
33
  var hasLockFlag = false;
34
34
  var dom = ref.current;
35
35
  var actionColumnDom = actionColumnRef === null || actionColumnRef === void 0 ? void 0 : actionColumnRef.current;
36
36
  var childNodes = dom.children;
37
+ if (dom.children.length === 0) {
38
+ return columns;
39
+ }
37
40
  var finalColumns = [];
38
- fileteredColumns.forEach(function (column, index) {
41
+ var filterdColumnsResult = _.cloneDeep(columns);
42
+ filterdColumnsResult.forEach(function (column, index) {
39
43
  var render = column.render,
40
44
  _column$valueType = column.valueType,
41
45
  valueType = _column$valueType === void 0 ? 'text' : _column$valueType,
42
- _column$autoWidth = column.autoWidth,
43
- autoWidth = _column$autoWidth === void 0 ? true : _column$autoWidth,
46
+ _column$isAutoWidth = column.isAutoWidth,
47
+ isAutoWidth = _column$isAutoWidth === void 0 ? true : _column$isAutoWidth,
44
48
  actionSchema = column.actionSchema,
45
49
  sortable = column.sortable,
46
50
  lock = column.lock;
@@ -52,6 +56,17 @@ export function genAutoWidthColumns(fileteredColumns, ref, data, size, useRowSel
52
56
  var finalType = type || valueType || '';
53
57
  var shrink = fieldTypeShrink[finalType];
54
58
  column.shrink = column.shrink || (shrink !== undefined ? shrink : 1);
59
+ if ((column === null || column === void 0 ? void 0 : column.isAutoWidth) === false) {
60
+ // console.log(column.title, 'isAutoWidth')
61
+ finalColumns.push(column);
62
+ return;
63
+ }
64
+ ;
65
+ if ((column === null || column === void 0 ? void 0 : column.columnFilters) === false) {
66
+ finalColumns.push(column);
67
+ return;
68
+ }
69
+ // column.isAutoWidth = true
55
70
  //@ts-ignore
56
71
  // if (!autoWidth) {
57
72
  // finalColumns.push(column);
@@ -72,13 +87,20 @@ export function genAutoWidthColumns(fileteredColumns, ref, data, size, useRowSel
72
87
  if (width >= 280) {
73
88
  width = 280;
74
89
  }
90
+ column.isAutoWidth = false;
75
91
  column.width = defaultPaddingFixer(width, size, false);
76
92
  }
77
93
  finalColumns.push(column);
78
94
  return;
79
95
  }
96
+ // 当列没出来的时候不比较
97
+ // @ts-ignore
98
+ if ((column === null || column === void 0 ? void 0 : column.columnFilters) === false) {
99
+ finalColumns.push(column);
100
+ return;
101
+ }
80
102
  // @ts-ignore
81
- var titleWidth = childNodes[index].children[0].scrollWidth;
103
+ var titleWidth = _.get(childNodes, '[index]?.children[0].scrollWidth', 0);
82
104
  // @ts-ignore
83
105
  if (fixedWidthTypeList[finalType]) {
84
106
  // console.log(
@@ -86,20 +108,37 @@ export function genAutoWidthColumns(fileteredColumns, ref, data, size, useRowSel
86
108
  // fixedWidthTypeList[finalType],
87
109
  // );
88
110
  // 固定宽度
111
+ // console.log(column.title, '固定宽度')
112
+ column.isAutoWidth = false;
89
113
  column.width = defaultPaddingFixer(
90
114
  // @ts-ignore
91
115
  Math.max(titleWidth, fixedWidthTypeList[finalType]), size, index === 0 && useRowSelection);
92
116
  // @ts-ignore
93
117
  } else if (computeableWidthTypeList[finalType]) {
94
118
  // 可计算宽度
119
+ // console.log(column.title, '可计算宽度')
120
+ column.isAutoWidth = false;
95
121
  column.width = defaultPaddingFixer(
96
122
  // @ts-ignore
97
123
  Math.max(titleWidth, computeableWidthTypeList[finalType](data, render)), size, index === 0 && useRowSelection);
98
124
  } else {
125
+ var _column$render;
99
126
  // 直接根据 dom 计算
127
+ // console.log(column.title, '可计算 dom')
128
+ column.isAutoWidth = false;
100
129
  column.width = defaultPaddingFixer(Math.max(titleWidth,
101
130
  // @ts-ignore
102
131
  calcWidthWithParentDOM(childNodes[index], column.shrink)), size, index === 0 && useRowSelection);
132
+ if ((column === null || column === void 0 ? void 0 : column.sortable) && ((column === null || column === void 0 ? void 0 : column.tooltip) || (column === null || column === void 0 ? void 0 : column.filters))) {
133
+ // 检测有 sortable 和 tooltip 的时候增加宽度
134
+ column.width = column.width + 40;
135
+ } else if (column === null || column === void 0 ? void 0 : column.sortable) {
136
+ column.width = column.width + 24;
137
+ }
138
+ // @ts-ignore
139
+ if (column === null || column === void 0 ? void 0 : (_column$render = column.render) === null || _column$render === void 0 ? void 0 : _column$render.copy) {
140
+ column.width = column.width + 16;
141
+ }
103
142
  }
104
143
  if (index === 0) {
105
144
  // 首列不会被挤占
@@ -120,6 +159,7 @@ export var shadowContainer = function shadowContainer(props) {
120
159
  var columns = props.columns,
121
160
  data = props.data,
122
161
  shadowContainerRef = props.shadowContainerRef;
162
+ if (data.length === 0) return null;
123
163
  return /*#__PURE__*/React.createElement("div", {
124
164
  ref: shadowContainerRef,
125
165
  className: "teamix-pro-table-shadow-container"
@@ -136,8 +176,12 @@ export var shadowContainer = function shadowContainer(props) {
136
176
  //@ts-ignore
137
177
  !fixedWidthTypeList[valueType] && data.map(function (item, index) {
138
178
  // @ts-ignore
139
- column.smartWidth = renderCellSmartWidth(getValueFromRecord(dataIndex, item), column, index, item);
140
- return renderCell(getValueFromRecord(dataIndex, item), column, index, item);
179
+ var newColumn = _.cloneDeep(column);
180
+ newColumn.smartWidth = renderCellSmartWidth(getValueFromRecord(dataIndex, item), column, index, item);
181
+ newColumn.render = _objectSpread(_objectSpread({}, column.render), {}, {
182
+ description: ''
183
+ });
184
+ return renderCell(getValueFromRecord(dataIndex, item), newColumn, index, item);
141
185
  }));
142
186
  }
143
187
  }));
@@ -219,11 +263,15 @@ export var fieldTypeShrink = {
219
263
  ip: 0
220
264
  };
221
265
  function calcWidthWithParentDOM(dom, shrink) {
222
- var childNodes = _toConsumableArray(dom.children);
223
- childNodes.shift();
224
- return calcSingleColumnLength(childNodes.map(function (node) {
225
- return node.scrollWidth;
226
- }), shrink);
266
+ if (dom) {
267
+ var childNodes = _toConsumableArray(dom.children);
268
+ childNodes.shift();
269
+ return calcSingleColumnLength(childNodes.map(function (node) {
270
+ return node.scrollWidth;
271
+ }), shrink);
272
+ } else {
273
+ return 0;
274
+ }
227
275
  }
228
276
  function calcSingleColumnLength() {
229
277
  var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -300,7 +348,8 @@ function defaultPaddingFixer(width) {
300
348
  }
301
349
  function sum() {
302
350
  var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
303
- return list.reduce(function (a, b) {
351
+ if (list.length === 0) return 0;
352
+ return list === null || list === void 0 ? void 0 : list.reduce(function (a, b) {
304
353
  return a + b;
305
354
  });
306
355
  }