@arim-aisdc/public-components 2.3.5 → 2.3.7

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.
@@ -17,7 +17,7 @@ export declare const foramtBaseInfoField: (data: any, dataField: BaseInfoFieldTy
17
17
  value: any;
18
18
  field: string;
19
19
  label?: string;
20
- text: string | JSX.Element | Element;
20
+ text: string | Element | JSX.Element;
21
21
  units?: string;
22
22
  width?: string;
23
23
  labelWidth?: string;
@@ -135,7 +135,8 @@ var Cell = function Cell(_ref) {
135
135
  }), !cannotDragColumn.includes(header.column.id) ? /*#__PURE__*/_jsxs("div", {
136
136
  className: "cell-right",
137
137
  children: [canSorting && header.column.getCanSort() ? /*#__PURE__*/_jsx(Sort, {
138
- sort: header.column.getIsSorted()
138
+ sort: header.column.getIsSorted(),
139
+ onClick: header.column.getToggleSortingHandler()
139
140
  }) : null, canFilter && columnDef.enableColumnFilter !== false ? /*#__PURE__*/_jsx(ColumnFilter, {
140
141
  column: header.column,
141
142
  manualFiltering: manualFiltering
@@ -102,6 +102,15 @@ table {
102
102
  height: 60%;
103
103
  top: 20%;
104
104
  }
105
+
106
+ &:hover {
107
+ .sort-flag {
108
+ display: inline-block;
109
+ }
110
+ .filter-icon {
111
+ display: inline-block;
112
+ }
113
+ }
105
114
  }
106
115
 
107
116
  .table-thead-tr:nth-last-child(2) {
@@ -54,7 +54,7 @@ var getCurrentRouterName = function getCurrentRouterName() {
54
54
  return window.location.pathname.slice(1);
55
55
  };
56
56
  var TableMax = function TableMax(_ref) {
57
- var _JSON$parse, _tableContentRef$curr;
57
+ var _JSON$parse, _tableContentRef$curr, _tableContentRef$curr2;
58
58
  var tableId = _ref.tableId,
59
59
  originColumns = _ref.columns,
60
60
  _ref$datas = _ref.datas,
@@ -187,6 +187,10 @@ var TableMax = function TableMax(_ref) {
187
187
  request = _ref.request,
188
188
  onEditValueChange = _ref.onEditValueChange;
189
189
  var tableMaxRef = useRef(null);
190
+ // 表格元素
191
+ var tableContentRef = useRef(null);
192
+ var tableHeaderRef = useRef(null);
193
+ var tableBodyRef = useRef(null);
190
194
  var _useTranslation = useTranslation(),
191
195
  _useTranslation2 = _slicedToArray(_useTranslation, 1),
192
196
  t = _useTranslation2[0];
@@ -283,7 +287,7 @@ var TableMax = function TableMax(_ref) {
283
287
  columnPinning = _useState20[0],
284
288
  setColumnPinning = _useState20[1];
285
289
  var _useColumnWidth = useColumnWidth({
286
- tableMaxRef: tableMaxRef,
290
+ tableContentRef: tableContentRef,
287
291
  tableId: tableId,
288
292
  tableKeyPrefixCls: tableKeyPrefixCls,
289
293
  columnVisibleConfig: columnVisibleConfig,
@@ -294,6 +298,7 @@ var TableMax = function TableMax(_ref) {
294
298
  onColumnSizingChange = _useColumnWidth.onColumnSizingChange,
295
299
  tableContainerWidth = _useColumnWidth.tableContainerWidth,
296
300
  handleVisibleConfigChange = _useColumnWidth.handleVisibleConfigChange;
301
+ console.log('columnSizing', columnSizing, tableContentRef === null || tableContentRef === void 0 || (_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.getBoundingClientRect().width, tableContainerWidth);
297
302
 
298
303
  /**列筛选 */
299
304
  var _useState21 = useState(defaultColumnFilters),
@@ -426,10 +431,6 @@ var TableMax = function TableMax(_ref) {
426
431
  onExpandedChange: setExpanded,
427
432
  sortDescFirst: true // 首次排序为递减排序,不加这个属性的话,有些列的排序会有问题
428
433
  });
429
- // 表格元素
430
- var tableContentRef = useRef(null);
431
- var tableHeaderRef = useRef(null);
432
- var tableBodyRef = useRef(null);
433
434
 
434
435
  // 暴露给外部的api
435
436
  useImperativeHandle(refInstance, function () {
@@ -952,7 +953,7 @@ var TableMax = function TableMax(_ref) {
952
953
  useEffect(function () {
953
954
  // 表格宽度变化时(比如调整页面宽度大小),重新计算是否展示阴影
954
955
  getPinShadowInfo();
955
- }, [tableContentRef === null || tableContentRef === void 0 || (_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.clientWidth, table.getState().columnSizing]);
956
+ }, [tableContentRef === null || tableContentRef === void 0 || (_tableContentRef$curr2 = tableContentRef.current) === null || _tableContentRef$curr2 === void 0 ? void 0 : _tableContentRef$curr2.clientWidth, table.getState().columnSizing]);
956
957
  var scrollHandler = useCallback(function (event) {
957
958
  if (!event.currentTarget) return;
958
959
  tableHeaderRef.current.scrollLeft = event.currentTarget.scrollLeft / event.currentTarget.scrollWidth * (tableHeaderRef === null || tableHeaderRef === void 0 ? void 0 : tableHeaderRef.current.scrollWidth);
@@ -4,11 +4,11 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useTranslation } from "../../../../../hooks/useTranslation";
7
8
  import { DatePicker } from 'antd';
8
9
  import dayjs from 'dayjs';
9
10
  import { defaultDateFormat } from "../index";
10
11
  import "./index.less";
11
- import { useTranslation } from "../../../../../hooks/useTranslation";
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  var defaultRangePresets = [{
14
14
  label: '最近7天',
@@ -129,6 +129,7 @@ export function ColumnFilter(_ref) {
129
129
  setFilterPanelVisible(false);
130
130
  }, []);
131
131
  return /*#__PURE__*/_jsxs("div", {
132
+ className: "filter-icon-wrapper",
132
133
  children: [/*#__PURE__*/_jsx("i", {
133
134
  className: "iconfont-table icon-table-filter filter-icon ".concat(!!column.getFilterValue() ? 'height-light-filter' : ''),
134
135
  onClick: onFilterIconClick
@@ -1,9 +1,11 @@
1
1
  .filter-icon {
2
2
  cursor: pointer;
3
+ display: none;
3
4
  }
4
5
 
5
6
  .height-light-filter {
6
7
  color: @global-primary-color;
8
+ display: inline-block !important;
7
9
  }
8
10
 
9
11
  .filter-panel-wrapper {
@@ -21,3 +23,8 @@
21
23
  padding: 8px 12px;
22
24
  border-radius: 2px;
23
25
  }
26
+
27
+ .filter-icon-wrapper {
28
+ line-height: 32px;
29
+ height: 32px;
30
+ }
@@ -1,5 +1,6 @@
1
1
  import './index.less';
2
- declare const Sort: ({ sort }: {
2
+ declare const Sort: ({ sort, onClick }: {
3
3
  sort: string | boolean;
4
+ onClick: (e: any) => void;
4
5
  }) => import("react/jsx-runtime").JSX.Element;
5
6
  export default Sort;
@@ -2,10 +2,12 @@ import "./index.less";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { jsxs as _jsxs } from "react/jsx-runtime";
4
4
  var Sort = function Sort(_ref) {
5
- var sort = _ref.sort;
5
+ var sort = _ref.sort,
6
+ onClick = _ref.onClick;
6
7
  if (sort === 'asc') {
7
8
  return /*#__PURE__*/_jsxs("span", {
8
- className: "sort-flag",
9
+ className: "sort-flag show-sort-flag",
10
+ onClick: onClick,
9
11
  children: [/*#__PURE__*/_jsx("i", {
10
12
  className: "triangle-up triangle-up-red"
11
13
  }), /*#__PURE__*/_jsx("i", {
@@ -14,7 +16,8 @@ var Sort = function Sort(_ref) {
14
16
  });
15
17
  } else if (sort === 'desc') {
16
18
  return /*#__PURE__*/_jsxs("span", {
17
- className: "sort-flag",
19
+ className: "sort-flag show-sort-flag",
20
+ onClick: onClick,
18
21
  children: [/*#__PURE__*/_jsx("i", {
19
22
  className: "triangle-up"
20
23
  }), /*#__PURE__*/_jsx("i", {
@@ -24,6 +27,7 @@ var Sort = function Sort(_ref) {
24
27
  }
25
28
  return /*#__PURE__*/_jsxs("span", {
26
29
  className: "sort-flag",
30
+ onClick: onClick,
27
31
  children: [/*#__PURE__*/_jsx("i", {
28
32
  className: "triangle-up"
29
33
  }), /*#__PURE__*/_jsx("i", {
@@ -5,6 +5,7 @@
5
5
  flex-direction: column;
6
6
  width: 16px;
7
7
  cursor: pointer;
8
+ display: none;
8
9
 
9
10
  .triangle-up {
10
11
  display: block;
@@ -33,3 +34,7 @@
33
34
  }
34
35
  }
35
36
  }
37
+
38
+ .show-sort-flag {
39
+ display: inline-block !important;
40
+ }
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { ColumnSizing } from '../TableMax';
3
3
  interface UseColumnWidthProps {
4
- tableMaxRef: React.RefObject<HTMLDivElement>;
4
+ tableContentRef: React.RefObject<HTMLDivElement>;
5
5
  tableId: string;
6
6
  tableKeyPrefixCls: string;
7
7
  columnVisibleConfig?: Record<string, boolean>;
8
8
  tableKey: string;
9
9
  }
10
- export declare const useColumnWidth: ({ tableMaxRef, tableId, tableKeyPrefixCls, columnVisibleConfig, tableKey, }: UseColumnWidthProps) => {
10
+ export declare const useColumnWidth: ({ tableContentRef, tableId, tableKeyPrefixCls, columnVisibleConfig, tableKey, }: UseColumnWidthProps) => {
11
11
  columnSizing: ColumnSizing;
12
12
  allColumnCount: number;
13
13
  onColumnSizingChange: (data: any) => void;
@@ -14,9 +14,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
14
14
  import { getSizeInfo } from "../utils";
15
15
  import { debounce } from 'lodash';
16
16
  var CACHE_MAX_AGE = 1 * 60 * 60 * 1000; // 1小时
17
-
17
+ var defaultMinSize = 120;
18
+ var defaultMaxSize = 240;
18
19
  export var useColumnWidth = function useColumnWidth(_ref) {
19
- var tableMaxRef = _ref.tableMaxRef,
20
+ var tableContentRef = _ref.tableContentRef,
20
21
  tableId = _ref.tableId,
21
22
  tableKeyPrefixCls = _ref.tableKeyPrefixCls,
22
23
  _ref$columnVisibleCon = _ref.columnVisibleConfig,
@@ -28,22 +29,33 @@ export var useColumnWidth = function useColumnWidth(_ref) {
28
29
  allColumnSizing: {},
29
30
  //所有列的列宽
30
31
  allColumnCount: 0,
31
- tableContainerWidth: undefined
32
+ tableContainerWidth: undefined,
33
+ initColumnsSizeMap: {}
32
34
  }),
33
35
  _useState2 = _slicedToArray(_useState, 2),
34
36
  state = _useState2[0],
35
37
  setState = _useState2[1];
38
+ var getTableWidth = useCallback(function () {
39
+ var _tableContentRef$curr;
40
+ var width = (_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.getBoundingClientRect().width;
41
+ var style = window.getComputedStyle(tableContentRef.current);
42
+ var horizontalBorderWidth = parseFloat(style.getPropertyValue('border-left-width')) + parseFloat(style.getPropertyValue('border-right-width'));
43
+ return Math.floor(width - horizontalBorderWidth);
44
+ }, [tableContentRef]);
36
45
 
37
46
  /**
38
47
  * 处理容器宽度变化的逻辑
39
- * 1.容器变小,不重新计算其他列
48
+ * 1.容器变小:
49
+ * 找到原始columns设置列宽度的第一列
50
+ * 如果当前列的宽度大于初始宽度,则按照容器变化的总宽度,除选择列和展开列外,其他列平分容器减小的宽度
51
+ * 如果当前列的宽度小于等于初始宽度,则列宽均不变
40
52
  * 2.容器变大:
41
53
  * 列宽之和大于容器宽度,不重新计算
42
54
  * 列宽之和小于容器宽度,除选择列和展开列外,其他列平分 列宽之和与容器宽度的差值
43
55
  */
44
56
  var handleResize = useCallback(function () {
45
- if (!tableMaxRef.current) return;
46
- var newWidth = Math.floor(tableMaxRef.current.clientWidth);
57
+ if (!tableContentRef.current) return;
58
+ var newWidth = getTableWidth();
47
59
  setState(function (prevState) {
48
60
  // 计算可见列,排除特定列
49
61
  var visibleColumns = Object.keys(prevState.columnSizing).filter(function (key) {
@@ -56,7 +68,7 @@ export var useColumnWidth = function useColumnWidth(_ref) {
56
68
  }, 0);
57
69
 
58
70
  // 容器变大时的逻辑
59
- if (newWidth > prevState.tableContainerWidth) {
71
+ if (prevState.tableContainerWidth > 0 && newWidth > prevState.tableContainerWidth) {
60
72
  if (totalVisibleWidth < newWidth) {
61
73
  // 计算剩余宽度
62
74
  var remainWidth = newWidth - totalVisibleWidth - 10;
@@ -77,27 +89,42 @@ export var useColumnWidth = function useColumnWidth(_ref) {
77
89
  });
78
90
  }
79
91
  }
92
+ } else if (prevState.tableContainerWidth > 0 && JSON.stringify(prevState.initColumnsSizeMap) !== '{}') {
93
+ // 容器变小时,重新计算
94
+ var reducedWidth = newWidth - totalVisibleWidth - 10;
95
+ var _unselectedCount = visibleColumns.length;
96
+ if (_unselectedCount > 0) {
97
+ var _averageWidth = reducedWidth / _unselectedCount;
98
+ var _newVisibleColumnsSizing = _objectSpread({}, prevState.columnSizing);
99
+ visibleColumns.forEach(function (key) {
100
+ _newVisibleColumnsSizing[key] = Math.max((_newVisibleColumnsSizing[key] || 0) + _averageWidth, Math.max(state.initColumnsSizeMap[visibleColumns[0]], defaultMinSize));
101
+ });
102
+ return _objectSpread(_objectSpread({}, prevState), {}, {
103
+ columnSizing: _newVisibleColumnsSizing,
104
+ allColumnSizing: _objectSpread(_objectSpread({}, prevState.allColumnSizing || {}), _newVisibleColumnsSizing),
105
+ tableContainerWidth: newWidth
106
+ });
107
+ }
80
108
  }
81
- // 容器变小时,列宽保持不变
82
109
  return _objectSpread(_objectSpread({}, prevState), {}, {
83
110
  tableContainerWidth: newWidth
84
111
  });
85
112
  });
86
- }, [tableMaxRef.current]);
113
+ }, [tableContentRef.current]);
87
114
 
88
115
  // 使用防抖处理容器宽度变化
89
116
  var debouncedHandleResize = useMemo(function () {
90
117
  return debounce(handleResize, 200);
91
118
  }, [handleResize]);
92
119
  useEffect(function () {
93
- if (!tableMaxRef.current) return;
120
+ if (!tableContentRef.current) return;
94
121
  var resizeObserver = new ResizeObserver(debouncedHandleResize);
95
- resizeObserver.observe(tableMaxRef.current);
122
+ resizeObserver.observe(tableContentRef.current);
96
123
  return function () {
97
124
  resizeObserver.disconnect();
98
125
  debouncedHandleResize.cancel(); // 清理防抖
99
126
  };
100
- }, [tableMaxRef.current, debouncedHandleResize]);
127
+ }, [tableContentRef.current, debouncedHandleResize]);
101
128
 
102
129
  /**
103
130
  * 列显示隐藏后调整列宽
@@ -122,11 +149,10 @@ export var useColumnWidth = function useColumnWidth(_ref) {
122
149
  })
123
150
  });
124
151
  } else {
125
- var _tableMaxRef$current;
126
152
  //列宽减少
127
153
  var newVisibleColumnsSizing = prevState.columnSizing;
128
154
  delete newVisibleColumnsSizing[key];
129
- var containerWidth = ((_tableMaxRef$current = tableMaxRef.current) === null || _tableMaxRef$current === void 0 ? void 0 : _tableMaxRef$current.clientWidth) - 10 || 0;
155
+ var containerWidth = getTableWidth() - 10 || 0;
130
156
  // 计算当前总宽度
131
157
  var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
132
158
  return Number(sum || 0) + Number(width || 0);
@@ -164,8 +190,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
164
190
  * */
165
191
  var calculateColumnSizing = useCallback(function (columnsSizeMap, allColumnCount, containerWidth) {
166
192
  var _Object$keys$filter;
167
- if (!tableMaxRef.current || !columnsSizeMap) return {};
168
- var currentWidth = containerWidth || state.tableContainerWidth || tableMaxRef.current.clientWidth;
193
+ if (!tableContentRef.current || !columnsSizeMap) return {};
194
+ var currentWidth = containerWidth || state.tableContainerWidth || getTableWidth();
169
195
  var hasColumnCount = ((_Object$keys$filter = Object.keys(columnsSizeMap).filter(function (item) {
170
196
  return !!columnsSizeMap[item];
171
197
  })) === null || _Object$keys$filter === void 0 ? void 0 : _Object$keys$filter.length) || 0;
@@ -179,8 +205,6 @@ export var useColumnWidth = function useColumnWidth(_ref) {
179
205
 
180
206
  // 处理未设置宽度的列
181
207
  if (remainColumnCount > 0) {
182
- var defaultMinSize = 120;
183
- var defaultMaxSize = 240;
184
208
  var averageSize = Math.max(Math.min(remainTableContainerWidth / remainColumnCount, defaultMaxSize), defaultMinSize);
185
209
  Object.keys(columnsSizeMap).forEach(function (key) {
186
210
  if (!newColumnSizeMap[key]) {
@@ -237,7 +261,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
237
261
  columnSizing: columnSizing,
238
262
  allColumnCount: _newAllColumnCount,
239
263
  allColumnSizing: _objectSpread(_objectSpread({}, _initColumnsSizeMap), columnSizing),
240
- tableContainerWidth: prevState.tableContainerWidth
264
+ tableContainerWidth: prevState.tableContainerWidth,
265
+ initColumnsSizeMap: columnSizeMap
241
266
  };
242
267
  });
243
268
  return;
@@ -263,7 +288,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
263
288
  columnSizing: columnSizing,
264
289
  allColumnSizing: _objectSpread(_objectSpread({}, initColumnsSizeMap), columnSizing),
265
290
  allColumnCount: newAllColumnCount,
266
- tableContainerWidth: prevState.tableContainerWidth
291
+ tableContainerWidth: prevState.tableContainerWidth,
292
+ initColumnsSizeMap: columnSizeMap
267
293
  };
268
294
  });
269
295
  }, [columnVisibleConfig, tableId, tableKey, tableKeyPrefixCls, calculateColumnSizing]);
@@ -280,7 +306,6 @@ export var useColumnWidth = function useColumnWidth(_ref) {
280
306
  var changedColumn = data();
281
307
  if (!changedColumn) return;
282
308
  setState(function (prevState) {
283
- var _tableMaxRef$current2;
284
309
  var changedColumnKey = Object.keys(changedColumn)[0];
285
310
  if (!changedColumnKey) return prevState;
286
311
  var oldWidth = prevState.columnSizing[changedColumnKey] || 0;
@@ -295,7 +320,7 @@ export var useColumnWidth = function useColumnWidth(_ref) {
295
320
  var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
296
321
  return Number(sum || 0) + Number(width || 0);
297
322
  }, 0);
298
- var containerWidth = ((_tableMaxRef$current2 = tableMaxRef.current) === null || _tableMaxRef$current2 === void 0 ? void 0 : _tableMaxRef$current2.clientWidth) - 10 || 0;
323
+ var containerWidth = getTableWidth() - 10 || 0;
299
324
  console.log(widthDiff, newWidth, oldWidth, changedColumnKey, prevState, 3344);
300
325
 
301
326
  // 处理列宽变大
@@ -5,6 +5,7 @@
5
5
  width: 100%;
6
6
  display: flex;
7
7
  flex-direction: column;
8
+ box-sizing: border-box;
8
9
  // justify-content: center;
9
10
  // align-items: center;
10
11
 
@@ -119,7 +120,6 @@
119
120
  overflow-y: hidden !important;
120
121
  display: flex;
121
122
  flex-direction: column;
122
-
123
123
  border: @global-table-max-border;
124
124
  border-bottom: @global-table-max-center-border-bottom;
125
125
  border-radius: @global-table-max-center-border-radius;
@@ -146,7 +146,7 @@
146
146
 
147
147
  .table-body {
148
148
  flex: 1;
149
- overflow: auto scroll;
149
+ overflow: scroll scroll;
150
150
  font-weight: @global-table-max-body-font-weight;
151
151
  // background: @tableColor2;
152
152
  .tbody-tr-td {
@@ -10,6 +10,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
10
10
  import * as React from 'react';
11
11
  import { FormItemType } from "../components/QueryFilter";
12
12
  import { useConfig } from "../components/ConfigProvider";
13
+ import dayjs from 'dayjs';
13
14
  function deepMerge(obj1, obj2) {
14
15
  // 创建一个新对象,避免直接修改原始对象
15
16
  var result = _objectSpread({}, obj1);
@@ -96,7 +97,7 @@ export var useTranslation = function useTranslation(locales) {
96
97
  groupPrefix = _options$groupPrefix === void 0 ? "" : _options$groupPrefix;
97
98
  var processArray = function processArray(array) {
98
99
  return array.map(function (item) {
99
- if (_typeof(item) === "object" && !Array.isArray(item)) {
100
+ if (_typeof(item) === "object" && !(item instanceof Date) && !(item instanceof dayjs) && !Array.isArray(item)) {
100
101
  var newItem = _objectSpread({}, item);
101
102
  if (fieldKey in newItem) {
102
103
  // 如果有分组前缀,动态拼接键
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arim-aisdc/public-components",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "前端组件库",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",