@nokecy/qc-ui 1.1.57 → 1.1.59

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.
@@ -441,11 +441,10 @@ function AgGridPlus(props) {
441
441
  // 辅助函数: 获取数据类型
442
442
  var getDataType = function getDataType(data, colName, valueEnum) {
443
443
  if (typeof data[colName] === 'number') {
444
- // 如果有枚举值,说明是分类数据,不进行计算;否则默认求和
445
- var shouldCalculate = !valueEnum || valueEnum.length === 0;
444
+ // 数值只用于列对齐;底部合计必须由 calculateType 显式声明。@author nokecy
446
445
  return {
447
446
  type: "number",
448
- calculateType: shouldCalculate ? "sum" : false
447
+ calculateType: valueEnum !== null && valueEnum !== void 0 && valueEnum.length ? false : undefined
449
448
  };
450
449
  }
451
450
  return undefined;
@@ -473,11 +472,11 @@ function AgGridPlus(props) {
473
472
  return (0, _columnProcessors.processEnumColumn)(col, dataType);
474
473
  }
475
474
  if (col.type || typeof col.cellRenderer == "string") {
476
- return _objectSpread({}, col);
475
+ return (0, _columnProcessors.mergeInferredColumnType)(col, dataType);
477
476
  }
478
477
  //@ts-ignore
479
478
  if (col !== null && col !== void 0 && col.ellipsis) {
480
- return _objectSpread(_objectSpread({}, col), {}, {
479
+ return _objectSpread(_objectSpread({}, (0, _columnProcessors.mergeInferredColumnType)(col, dataType)), {}, {
481
480
  cellRenderer: function cellRenderer(_ref) {
482
481
  var value = _ref.value;
483
482
  return /*#__PURE__*/_react.default.createElement(Text, {
@@ -494,12 +493,12 @@ function AgGridPlus(props) {
494
493
  });
495
494
  }
496
495
  if (col.cellRenderer) {
497
- return _objectSpread(_objectSpread({}, col), {}, {
496
+ return _objectSpread(_objectSpread({}, (0, _columnProcessors.mergeInferredColumnType)(col, dataType)), {}, {
498
497
  customCellRenderer: col.cellRenderer,
499
498
  cellRenderer: cellRenderer
500
499
  });
501
500
  }
502
- return _objectSpread(_objectSpread(_objectSpread({}, (0, _columnProcessors.toColumnType)(dataType)), col), {}, {
501
+ return _objectSpread(_objectSpread({}, (0, _columnProcessors.mergeInferredColumnType)(col, dataType)), {}, {
503
502
  customCellRenderer: col.cellRenderer,
504
503
  cellRenderer: cellRenderer
505
504
  });
@@ -886,6 +885,10 @@ function AgGridPlus(props) {
886
885
  onRetry: onRefresh
887
886
  };
888
887
  }, [loadError, accessible, filtered, overlayNoRowsTemplateText, emptyState, onRefresh]);
888
+ // 调用方自带空态浮层时让位,见 resolveNoRowsOverlay。@author nokecy
889
+ var noRowsOverlay = (0, _react.useMemo)(function () {
890
+ return (0, _emptyState.resolveNoRowsOverlay)(_NoRowsOverlay.default, noRowsOverlayParams, rest.noRowsOverlayComponent, rest.noRowsOverlayComponentParams);
891
+ }, [noRowsOverlayParams, rest.noRowsOverlayComponent, rest.noRowsOverlayComponentParams]);
889
892
  (0, _react.useEffect)(function () {
890
893
  gridRef.current = {
891
894
  onRefresh: onRefresh
@@ -949,6 +952,7 @@ function AgGridPlus(props) {
949
952
  }
950
953
  };
951
954
  var calculateSum = (0, _react.useCallback)(function () {
955
+ if (props.pinnedBottomRowData !== undefined) return;
952
956
  var displayedData = [];
953
957
  if (apiRef.current) {
954
958
  apiRef.current.forEachNodeAfterFilter(function (node) {
@@ -960,22 +964,16 @@ function AgGridPlus(props) {
960
964
  (_apiRef$current4 = apiRef.current) === null || _apiRef$current4 === void 0 || _apiRef$current4.setGridOption('pinnedBottomRowData', undefined);
961
965
  return;
962
966
  }
963
- var calcColFields = allColDefs.filter(function (col) {
964
- return col.calculateType;
965
- }).map(function (col) {
966
- return {
967
- field: col.field,
968
- calculateType: col.calculateType,
969
- transactionAmount: col.transactionAmount || 2,
970
- formatWithCommas: col.formatWithCommas
971
- };
972
- });
967
+ var calcColFields = (0, _aggregation.getCalculationColumns)(allColDefs);
973
968
  if (calcColFields.length > 0) {
974
969
  var _apiRef$current5;
975
970
  var calculatedValues = (0, _aggregation.computeAggregationRow)(calcColFields, displayedData);
976
971
  (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 || _apiRef$current5.setGridOption('pinnedBottomRowData', calculatedValues);
972
+ } else {
973
+ var _apiRef$current6;
974
+ (_apiRef$current6 = apiRef.current) === null || _apiRef$current6 === void 0 || _apiRef$current6.setGridOption('pinnedBottomRowData', undefined);
977
975
  }
978
- }, [allColDefs]);
976
+ }, [allColDefs, props.pinnedBottomRowData]);
979
977
  var onFilterChanged = function onFilterChanged(event) {
980
978
  calculateSum();
981
979
  };
@@ -1329,8 +1327,8 @@ function AgGridPlus(props) {
1329
1327
  ensureDomOrder: true,
1330
1328
  columnHoverHighlight: true
1331
1329
  },
1332
- noRowsOverlayComponent: _NoRowsOverlay.default,
1333
- noRowsOverlayComponentParams: noRowsOverlayParams
1330
+ noRowsOverlayComponent: noRowsOverlay.component,
1331
+ noRowsOverlayComponentParams: noRowsOverlay.params
1334
1332
  // 加载中不显示空态:外层 Spin 已经在转,再叠一句「暂无数据」会让用户
1335
1333
  // 以为真的没数据(冒烟截图里这两者确实同时出现过)。@author nokecy
1336
1334
  ,
@@ -1369,8 +1367,8 @@ function AgGridPlus(props) {
1369
1367
  },
1370
1368
  onDragStopped: function onDragStopped(e) {
1371
1369
  if (apiRef.current) {
1372
- var _apiRef$current6;
1373
- var _columnState = (_apiRef$current6 = apiRef.current) === null || _apiRef$current6 === void 0 ? void 0 : _apiRef$current6.getColumnState();
1370
+ var _apiRef$current7;
1371
+ var _columnState = (_apiRef$current7 = apiRef.current) === null || _apiRef$current7 === void 0 ? void 0 : _apiRef$current7.getColumnState();
1374
1372
  setColumnState(_columnState);
1375
1373
 
1376
1374
  // onColumnStateChanged && onColumnStateChanged(columnState)
@@ -48,3 +48,9 @@
48
48
  .custom-cell-right {
49
49
  text-align: right !important;
50
50
  }
51
+
52
+ // 空态浮层里的「重试」「新建」「清空筛选」要能点:AG-Grid 给 .ag-overlay 设了 pointer-events: none,
53
+ // 只给加载浮层放开,空态浮层里的按钮因此点不到。只放开可交互元素,空白处仍穿透到表格。@author nokecy
54
+ .ag-overlay-no-rows-wrapper :is(button, a, input, [role='button']) {
55
+ pointer-events: auto;
56
+ }
@@ -9,6 +9,15 @@ export interface CalculationColumnConfig {
9
9
  formatWithCommas?: boolean;
10
10
  cellRenderer?: any;
11
11
  }
12
+ export interface CalculationColumnDefinition {
13
+ field?: string;
14
+ calculateType?: CalculationColumnConfig['calculateType'] | false;
15
+ transactionAmount?: number;
16
+ formatWithCommas?: boolean;
17
+ children?: CalculationColumnDefinition[];
18
+ }
19
+ /** 分组表头只是展示结构;原生固定合计行要读取所有叶子数值列。@author nokecy */
20
+ export declare const getCalculationColumns: (columns: CalculationColumnDefinition[]) => CalculationColumnConfig[];
12
21
  export declare const isValidNumber: (value: any) => boolean;
13
22
  export declare const sumField: (field: string, data: any[]) => number;
14
23
  export declare const avgField: (field: string, data: any[]) => number;
@@ -4,7 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.sumField = exports.stdDevField = exports.isValidNumber = exports.formatWithCommas = exports.computeAggregationRow = exports.avgField = void 0;
7
+ exports.sumField = exports.stdDevField = exports.isValidNumber = exports.getCalculationColumns = exports.formatWithCommas = exports.computeAggregationRow = exports.avgField = void 0;
8
8
  var _lodash = _interopRequireWildcard(require("lodash"));
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -13,6 +13,20 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
13
13
  * @author nokecy
14
14
  */
15
15
 
16
+ /** 分组表头只是展示结构;原生固定合计行要读取所有叶子数值列。@author nokecy */
17
+ var getCalculationColumns = exports.getCalculationColumns = function getCalculationColumns(columns) {
18
+ return columns.flatMap(function (column) {
19
+ var _column$transactionAm;
20
+ if (column.children) return getCalculationColumns(column.children);
21
+ if (!column.field || !column.calculateType) return [];
22
+ return [{
23
+ field: column.field,
24
+ calculateType: column.calculateType,
25
+ transactionAmount: (_column$transactionAm = column.transactionAmount) !== null && _column$transactionAm !== void 0 ? _column$transactionAm : 2,
26
+ formatWithCommas: column.formatWithCommas
27
+ }];
28
+ });
29
+ };
16
30
  var isValidNumber = exports.isValidNumber = function isValidNumber(value) {
17
31
  return typeof value === 'number' && !isNaN(value);
18
32
  };
@@ -56,8 +56,8 @@ export declare function inferDataType(data: any, colName: string, valueEnum?: Va
56
56
  * 早先是把整个 dataType 摊进 colDef,等于给列设了 type:"number"——而注册的 columnTypes 里
57
57
  * 根本没有叫 number 的类型,这个字段一直没生效。
58
58
  *
59
- * 数量型数值列真正该有的是右对齐:位数对齐了才能一眼比大小。只有 calculateType 为真
60
- * (可求和的数量型)才右对齐;用 valueEnum 表示分类的数值列(状态码之类)不动。
59
+ * 普通数值列右对齐;合计另由 calculateType 显式控制。
60
+ * 用 valueEnum 表示分类的数值列(状态码之类)不动。
61
61
  *
62
62
  * @author nokecy
63
63
  */
@@ -65,6 +65,8 @@ export declare function toColumnType(dataType?: DataTypeInference): {
65
65
  calculateType?: any;
66
66
  type?: string;
67
67
  };
68
+ /** 显式列类型只控制显示方式,不遮蔽数值对齐或显式合计配置。@author nokecy */
69
+ export declare function mergeInferredColumnType<T extends object>(column: T, dataType?: DataTypeInference): T & ReturnType<typeof toColumnType>;
68
70
  /**
69
71
  * 处理枚举列定义 —— **枚举列渲染的唯一实现**。
70
72
  *
@@ -9,6 +9,7 @@ exports.createCellRenderer = createCellRenderer;
9
9
  exports.filterHiddenColumns = filterHiddenColumns;
10
10
  exports.handleGridPlusColumnState = handleGridPlusColumnState;
11
11
  exports.inferDataType = inferDataType;
12
+ exports.mergeInferredColumnType = mergeInferredColumnType;
12
13
  exports.processEllipsisColumn = processEllipsisColumn;
13
14
  exports.processEnumColumn = processEnumColumn;
14
15
  exports.toColumnType = toColumnType;
@@ -75,11 +76,10 @@ function handleGridPlusColumnState(columnState) {
75
76
  function inferDataType(data, colName, valueEnum) {
76
77
  var value = data[colName];
77
78
  if (typeof value === 'number') {
78
- // 如果有枚举值,说明是分类数据,不进行计算
79
- var shouldCalculate = !valueEnum || valueEnum.length === 0;
79
+ // 数值只决定对齐;合计必须由列定义显式声明。@author nokecy
80
80
  return {
81
81
  type: 'number',
82
- calculateType: shouldCalculate ? 'sum' : false
82
+ calculateType: valueEnum !== null && valueEnum !== void 0 && valueEnum.length ? false : undefined
83
83
  };
84
84
  }
85
85
  if (typeof value === 'boolean') {
@@ -104,17 +104,19 @@ function inferDataType(data, colName, valueEnum) {
104
104
  * 早先是把整个 dataType 摊进 colDef,等于给列设了 type:"number"——而注册的 columnTypes 里
105
105
  * 根本没有叫 number 的类型,这个字段一直没生效。
106
106
  *
107
- * 数量型数值列真正该有的是右对齐:位数对齐了才能一眼比大小。只有 calculateType 为真
108
- * (可求和的数量型)才右对齐;用 valueEnum 表示分类的数值列(状态码之类)不动。
107
+ * 普通数值列右对齐;合计另由 calculateType 显式控制。
108
+ * 用 valueEnum 表示分类的数值列(状态码之类)不动。
109
109
  *
110
110
  * @author nokecy
111
111
  */
112
112
  function toColumnType(dataType) {
113
113
  if (!dataType) return {};
114
- if (dataType.type === 'number' && dataType.calculateType) {
115
- return {
114
+ if (dataType.type === 'number' && dataType.calculateType !== false) {
115
+ return dataType.calculateType ? {
116
116
  calculateType: dataType.calculateType,
117
117
  type: 'rightAligned'
118
+ } : {
119
+ type: 'rightAligned'
118
120
  };
119
121
  }
120
122
  return {
@@ -122,6 +124,11 @@ function toColumnType(dataType) {
122
124
  };
123
125
  }
124
126
 
127
+ /** 显式列类型只控制显示方式,不遮蔽数值对齐或显式合计配置。@author nokecy */
128
+ function mergeInferredColumnType(column, dataType) {
129
+ return _objectSpread(_objectSpread({}, toColumnType(dataType)), column);
130
+ }
131
+
125
132
  /**
126
133
  * 处理枚举列定义 —— **枚举列渲染的唯一实现**。
127
134
  *
@@ -40,3 +40,15 @@ export declare function resolveEmptyText(state: {
40
40
  override?: string;
41
41
  texts?: EmptyStateTexts;
42
42
  }): string;
43
+ /**
44
+ * 选出空态浮层组件及其入参。
45
+ * 调用方传了 `noRowsOverlayComponent` 就用调用方的:宿主往往有自己的空态(例如无数据时带「新建」按钮、
46
+ * 外部筛选栏的「清空筛选」),此前内置浮层写死在 `...rest` 之后,把它们全部覆盖掉了。
47
+ * 入参合并:内置的 branch / text / onRetry 照样传给自定义组件,调用方同名入参优先。
48
+ *
49
+ * @author nokecy
50
+ */
51
+ export declare function resolveNoRowsOverlay<C, P extends object>(builtIn: C, builtInParams: P, custom?: C | null, customParams?: Record<string, any> | null): {
52
+ component: C;
53
+ params: P & Record<string, any>;
54
+ };
@@ -7,6 +7,12 @@ exports.DEFAULT_EMPTY_TEXTS = void 0;
7
7
  exports.hasEffectiveFilter = hasEffectiveFilter;
8
8
  exports.resolveEmptyBranch = resolveEmptyBranch;
9
9
  exports.resolveEmptyText = resolveEmptyText;
10
+ exports.resolveNoRowsOverlay = resolveNoRowsOverlay;
11
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
16
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
17
  /**
12
18
  * 表格空态四分。
@@ -74,4 +80,19 @@ function resolveEmptyText(state) {
74
80
  if (state.override) return state.override;
75
81
  var branch = resolveEmptyBranch(state);
76
82
  return (_state$texts$branch = (_state$texts = state.texts) === null || _state$texts === void 0 ? void 0 : _state$texts[branch]) !== null && _state$texts$branch !== void 0 ? _state$texts$branch : DEFAULT_EMPTY_TEXTS[branch];
83
+ }
84
+
85
+ /**
86
+ * 选出空态浮层组件及其入参。
87
+ * 调用方传了 `noRowsOverlayComponent` 就用调用方的:宿主往往有自己的空态(例如无数据时带「新建」按钮、
88
+ * 外部筛选栏的「清空筛选」),此前内置浮层写死在 `...rest` 之后,把它们全部覆盖掉了。
89
+ * 入参合并:内置的 branch / text / onRetry 照样传给自定义组件,调用方同名入参优先。
90
+ *
91
+ * @author nokecy
92
+ */
93
+ function resolveNoRowsOverlay(builtIn, builtInParams, custom, customParams) {
94
+ return {
95
+ component: custom !== null && custom !== void 0 ? custom : builtIn,
96
+ params: customParams ? _objectSpread(_objectSpread({}, builtInParams), customParams) : builtInParams
97
+ };
77
98
  }
@@ -36,7 +36,7 @@ import ToolBar from "./toolBar";
36
36
  import SettingItem from "./settingItem";
37
37
  import { RedoOutlined, FilterOutlined } from '@ant-design/icons';
38
38
  import { convertFilterModel, dateTimeValueFormatter, dateValueFormatter, flatten, toTree } from "./utils";
39
- import { processEnumColumn, toColumnType } from "./utils/columnProcessors";
39
+ import { mergeInferredColumnType, processEnumColumn } from "./utils/columnProcessors";
40
40
  import AdvancedQueryBuilder from "./queryForm/AdvancedQueryBuilder";
41
41
  import { v4 as uuidv4 } from 'uuid';
42
42
  import Setting from "./setting";
@@ -46,7 +46,7 @@ import _, { isArray } from 'lodash';
46
46
  import CustomGroupCellRenderer from "./_utils/customGroupCellRenderer";
47
47
  import NoRowsOverlay from "./shared/NoRowsOverlay";
48
48
  import { DEFAULT_PAGE_SIZE_OPTIONS } from "./utils/constants";
49
- import { hasEffectiveFilter, resolveEmptyBranch, resolveEmptyText } from "./utils/emptyState";
49
+ import { hasEffectiveFilter, resolveEmptyBranch, resolveEmptyText, resolveNoRowsOverlay } from "./utils/emptyState";
50
50
  import processColumnGroups from "./_utils/processColumnGroups";
51
51
  import flattenColumnState from "./_utils/processFormColumnState";
52
52
  import { localeText } from "./locale";
@@ -55,7 +55,7 @@ import { QueryFormContext } from "./context/queryFormContext";
55
55
  import { useGridSchemes } from "./context/useSchemeManager";
56
56
  import { useSchemeDataFlow } from "./context/useSchemeDataFlow";
57
57
  import { extractItemsOrder, extractHiddenFields } from "./shared/utils/schemeDataMigration";
58
- import { computeAggregationRow } from "./utils/aggregation";
58
+ import { computeAggregationRow, getCalculationColumns } from "./utils/aggregation";
59
59
  import { sortFormItemsByOrder, filterHiddenFormItems } from "./utils/queryFormDerivation";
60
60
  import { filterVisibleSelectedRows } from "./utils/rowSelection";
61
61
  import { buildFilterString, pageToSkipCount } from "./utils/requestParams";
@@ -433,11 +433,10 @@ function AgGridPlus(props) {
433
433
  // 辅助函数: 获取数据类型
434
434
  var getDataType = function getDataType(data, colName, valueEnum) {
435
435
  if (typeof data[colName] === 'number') {
436
- // 如果有枚举值,说明是分类数据,不进行计算;否则默认求和
437
- var shouldCalculate = !valueEnum || valueEnum.length === 0;
436
+ // 数值只用于列对齐;底部合计必须由 calculateType 显式声明。@author nokecy
438
437
  return {
439
438
  type: "number",
440
- calculateType: shouldCalculate ? "sum" : false
439
+ calculateType: valueEnum !== null && valueEnum !== void 0 && valueEnum.length ? false : undefined
441
440
  };
442
441
  }
443
442
  return undefined;
@@ -465,11 +464,11 @@ function AgGridPlus(props) {
465
464
  return processEnumColumn(col, dataType);
466
465
  }
467
466
  if (col.type || typeof col.cellRenderer == "string") {
468
- return _objectSpread({}, col);
467
+ return mergeInferredColumnType(col, dataType);
469
468
  }
470
469
  //@ts-ignore
471
470
  if (col !== null && col !== void 0 && col.ellipsis) {
472
- return _objectSpread(_objectSpread({}, col), {}, {
471
+ return _objectSpread(_objectSpread({}, mergeInferredColumnType(col, dataType)), {}, {
473
472
  cellRenderer: function cellRenderer(_ref) {
474
473
  var value = _ref.value;
475
474
  return /*#__PURE__*/React.createElement(Text, {
@@ -486,12 +485,12 @@ function AgGridPlus(props) {
486
485
  });
487
486
  }
488
487
  if (col.cellRenderer) {
489
- return _objectSpread(_objectSpread({}, col), {}, {
488
+ return _objectSpread(_objectSpread({}, mergeInferredColumnType(col, dataType)), {}, {
490
489
  customCellRenderer: col.cellRenderer,
491
490
  cellRenderer: cellRenderer
492
491
  });
493
492
  }
494
- return _objectSpread(_objectSpread(_objectSpread({}, toColumnType(dataType)), col), {}, {
493
+ return _objectSpread(_objectSpread({}, mergeInferredColumnType(col, dataType)), {}, {
495
494
  customCellRenderer: col.cellRenderer,
496
495
  cellRenderer: cellRenderer
497
496
  });
@@ -878,6 +877,10 @@ function AgGridPlus(props) {
878
877
  onRetry: onRefresh
879
878
  };
880
879
  }, [loadError, accessible, filtered, overlayNoRowsTemplateText, emptyState, onRefresh]);
880
+ // 调用方自带空态浮层时让位,见 resolveNoRowsOverlay。@author nokecy
881
+ var noRowsOverlay = useMemo(function () {
882
+ return resolveNoRowsOverlay(NoRowsOverlay, noRowsOverlayParams, rest.noRowsOverlayComponent, rest.noRowsOverlayComponentParams);
883
+ }, [noRowsOverlayParams, rest.noRowsOverlayComponent, rest.noRowsOverlayComponentParams]);
881
884
  useEffect(function () {
882
885
  gridRef.current = {
883
886
  onRefresh: onRefresh
@@ -941,6 +944,7 @@ function AgGridPlus(props) {
941
944
  }
942
945
  };
943
946
  var calculateSum = useCallback(function () {
947
+ if (props.pinnedBottomRowData !== undefined) return;
944
948
  var displayedData = [];
945
949
  if (apiRef.current) {
946
950
  apiRef.current.forEachNodeAfterFilter(function (node) {
@@ -952,22 +956,16 @@ function AgGridPlus(props) {
952
956
  (_apiRef$current4 = apiRef.current) === null || _apiRef$current4 === void 0 || _apiRef$current4.setGridOption('pinnedBottomRowData', undefined);
953
957
  return;
954
958
  }
955
- var calcColFields = allColDefs.filter(function (col) {
956
- return col.calculateType;
957
- }).map(function (col) {
958
- return {
959
- field: col.field,
960
- calculateType: col.calculateType,
961
- transactionAmount: col.transactionAmount || 2,
962
- formatWithCommas: col.formatWithCommas
963
- };
964
- });
959
+ var calcColFields = getCalculationColumns(allColDefs);
965
960
  if (calcColFields.length > 0) {
966
961
  var _apiRef$current5;
967
962
  var calculatedValues = computeAggregationRow(calcColFields, displayedData);
968
963
  (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 || _apiRef$current5.setGridOption('pinnedBottomRowData', calculatedValues);
964
+ } else {
965
+ var _apiRef$current6;
966
+ (_apiRef$current6 = apiRef.current) === null || _apiRef$current6 === void 0 || _apiRef$current6.setGridOption('pinnedBottomRowData', undefined);
969
967
  }
970
- }, [allColDefs]);
968
+ }, [allColDefs, props.pinnedBottomRowData]);
971
969
  var onFilterChanged = function onFilterChanged(event) {
972
970
  calculateSum();
973
971
  };
@@ -1321,8 +1319,8 @@ function AgGridPlus(props) {
1321
1319
  ensureDomOrder: true,
1322
1320
  columnHoverHighlight: true
1323
1321
  },
1324
- noRowsOverlayComponent: NoRowsOverlay,
1325
- noRowsOverlayComponentParams: noRowsOverlayParams
1322
+ noRowsOverlayComponent: noRowsOverlay.component,
1323
+ noRowsOverlayComponentParams: noRowsOverlay.params
1326
1324
  // 加载中不显示空态:外层 Spin 已经在转,再叠一句「暂无数据」会让用户
1327
1325
  // 以为真的没数据(冒烟截图里这两者确实同时出现过)。@author nokecy
1328
1326
  ,
@@ -1361,8 +1359,8 @@ function AgGridPlus(props) {
1361
1359
  },
1362
1360
  onDragStopped: function onDragStopped(e) {
1363
1361
  if (apiRef.current) {
1364
- var _apiRef$current6;
1365
- var _columnState = (_apiRef$current6 = apiRef.current) === null || _apiRef$current6 === void 0 ? void 0 : _apiRef$current6.getColumnState();
1362
+ var _apiRef$current7;
1363
+ var _columnState = (_apiRef$current7 = apiRef.current) === null || _apiRef$current7 === void 0 ? void 0 : _apiRef$current7.getColumnState();
1366
1364
  setColumnState(_columnState);
1367
1365
 
1368
1366
  // onColumnStateChanged && onColumnStateChanged(columnState)
@@ -48,3 +48,9 @@
48
48
  .custom-cell-right {
49
49
  text-align: right !important;
50
50
  }
51
+
52
+ // 空态浮层里的「重试」「新建」「清空筛选」要能点:AG-Grid 给 .ag-overlay 设了 pointer-events: none,
53
+ // 只给加载浮层放开,空态浮层里的按钮因此点不到。只放开可交互元素,空白处仍穿透到表格。@author nokecy
54
+ .ag-overlay-no-rows-wrapper :is(button, a, input, [role='button']) {
55
+ pointer-events: auto;
56
+ }
@@ -9,6 +9,15 @@ export interface CalculationColumnConfig {
9
9
  formatWithCommas?: boolean;
10
10
  cellRenderer?: any;
11
11
  }
12
+ export interface CalculationColumnDefinition {
13
+ field?: string;
14
+ calculateType?: CalculationColumnConfig['calculateType'] | false;
15
+ transactionAmount?: number;
16
+ formatWithCommas?: boolean;
17
+ children?: CalculationColumnDefinition[];
18
+ }
19
+ /** 分组表头只是展示结构;原生固定合计行要读取所有叶子数值列。@author nokecy */
20
+ export declare const getCalculationColumns: (columns: CalculationColumnDefinition[]) => CalculationColumnConfig[];
12
21
  export declare const isValidNumber: (value: any) => boolean;
13
22
  export declare const sumField: (field: string, data: any[]) => number;
14
23
  export declare const avgField: (field: string, data: any[]) => number;
@@ -5,6 +5,20 @@ import _, { uniqueId } from 'lodash';
5
5
  * @author nokecy
6
6
  */
7
7
 
8
+ /** 分组表头只是展示结构;原生固定合计行要读取所有叶子数值列。@author nokecy */
9
+ export var getCalculationColumns = function getCalculationColumns(columns) {
10
+ return columns.flatMap(function (column) {
11
+ var _column$transactionAm;
12
+ if (column.children) return getCalculationColumns(column.children);
13
+ if (!column.field || !column.calculateType) return [];
14
+ return [{
15
+ field: column.field,
16
+ calculateType: column.calculateType,
17
+ transactionAmount: (_column$transactionAm = column.transactionAmount) !== null && _column$transactionAm !== void 0 ? _column$transactionAm : 2,
18
+ formatWithCommas: column.formatWithCommas
19
+ }];
20
+ });
21
+ };
8
22
  export var isValidNumber = function isValidNumber(value) {
9
23
  return typeof value === 'number' && !isNaN(value);
10
24
  };
@@ -56,8 +56,8 @@ export declare function inferDataType(data: any, colName: string, valueEnum?: Va
56
56
  * 早先是把整个 dataType 摊进 colDef,等于给列设了 type:"number"——而注册的 columnTypes 里
57
57
  * 根本没有叫 number 的类型,这个字段一直没生效。
58
58
  *
59
- * 数量型数值列真正该有的是右对齐:位数对齐了才能一眼比大小。只有 calculateType 为真
60
- * (可求和的数量型)才右对齐;用 valueEnum 表示分类的数值列(状态码之类)不动。
59
+ * 普通数值列右对齐;合计另由 calculateType 显式控制。
60
+ * 用 valueEnum 表示分类的数值列(状态码之类)不动。
61
61
  *
62
62
  * @author nokecy
63
63
  */
@@ -65,6 +65,8 @@ export declare function toColumnType(dataType?: DataTypeInference): {
65
65
  calculateType?: any;
66
66
  type?: string;
67
67
  };
68
+ /** 显式列类型只控制显示方式,不遮蔽数值对齐或显式合计配置。@author nokecy */
69
+ export declare function mergeInferredColumnType<T extends object>(column: T, dataType?: DataTypeInference): T & ReturnType<typeof toColumnType>;
68
70
  /**
69
71
  * 处理枚举列定义 —— **枚举列渲染的唯一实现**。
70
72
  *
@@ -60,11 +60,10 @@ export function handleGridPlusColumnState(columnState) {
60
60
  export function inferDataType(data, colName, valueEnum) {
61
61
  var value = data[colName];
62
62
  if (typeof value === 'number') {
63
- // 如果有枚举值,说明是分类数据,不进行计算
64
- var shouldCalculate = !valueEnum || valueEnum.length === 0;
63
+ // 数值只决定对齐;合计必须由列定义显式声明。@author nokecy
65
64
  return {
66
65
  type: 'number',
67
- calculateType: shouldCalculate ? 'sum' : false
66
+ calculateType: valueEnum !== null && valueEnum !== void 0 && valueEnum.length ? false : undefined
68
67
  };
69
68
  }
70
69
  if (typeof value === 'boolean') {
@@ -89,17 +88,19 @@ export function inferDataType(data, colName, valueEnum) {
89
88
  * 早先是把整个 dataType 摊进 colDef,等于给列设了 type:"number"——而注册的 columnTypes 里
90
89
  * 根本没有叫 number 的类型,这个字段一直没生效。
91
90
  *
92
- * 数量型数值列真正该有的是右对齐:位数对齐了才能一眼比大小。只有 calculateType 为真
93
- * (可求和的数量型)才右对齐;用 valueEnum 表示分类的数值列(状态码之类)不动。
91
+ * 普通数值列右对齐;合计另由 calculateType 显式控制。
92
+ * 用 valueEnum 表示分类的数值列(状态码之类)不动。
94
93
  *
95
94
  * @author nokecy
96
95
  */
97
96
  export function toColumnType(dataType) {
98
97
  if (!dataType) return {};
99
- if (dataType.type === 'number' && dataType.calculateType) {
100
- return {
98
+ if (dataType.type === 'number' && dataType.calculateType !== false) {
99
+ return dataType.calculateType ? {
101
100
  calculateType: dataType.calculateType,
102
101
  type: 'rightAligned'
102
+ } : {
103
+ type: 'rightAligned'
103
104
  };
104
105
  }
105
106
  return {
@@ -107,6 +108,11 @@ export function toColumnType(dataType) {
107
108
  };
108
109
  }
109
110
 
111
+ /** 显式列类型只控制显示方式,不遮蔽数值对齐或显式合计配置。@author nokecy */
112
+ export function mergeInferredColumnType(column, dataType) {
113
+ return _objectSpread(_objectSpread({}, toColumnType(dataType)), column);
114
+ }
115
+
110
116
  /**
111
117
  * 处理枚举列定义 —— **枚举列渲染的唯一实现**。
112
118
  *
@@ -40,3 +40,15 @@ export declare function resolveEmptyText(state: {
40
40
  override?: string;
41
41
  texts?: EmptyStateTexts;
42
42
  }): string;
43
+ /**
44
+ * 选出空态浮层组件及其入参。
45
+ * 调用方传了 `noRowsOverlayComponent` 就用调用方的:宿主往往有自己的空态(例如无数据时带「新建」按钮、
46
+ * 外部筛选栏的「清空筛选」),此前内置浮层写死在 `...rest` 之后,把它们全部覆盖掉了。
47
+ * 入参合并:内置的 branch / text / onRetry 照样传给自定义组件,调用方同名入参优先。
48
+ *
49
+ * @author nokecy
50
+ */
51
+ export declare function resolveNoRowsOverlay<C, P extends object>(builtIn: C, builtInParams: P, custom?: C | null, customParams?: Record<string, any> | null): {
52
+ component: C;
53
+ params: P & Record<string, any>;
54
+ };
@@ -1,3 +1,8 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
6
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
7
  /**
3
8
  * 表格空态四分。
@@ -65,4 +70,19 @@ export function resolveEmptyText(state) {
65
70
  if (state.override) return state.override;
66
71
  var branch = resolveEmptyBranch(state);
67
72
  return (_state$texts$branch = (_state$texts = state.texts) === null || _state$texts === void 0 ? void 0 : _state$texts[branch]) !== null && _state$texts$branch !== void 0 ? _state$texts$branch : DEFAULT_EMPTY_TEXTS[branch];
73
+ }
74
+
75
+ /**
76
+ * 选出空态浮层组件及其入参。
77
+ * 调用方传了 `noRowsOverlayComponent` 就用调用方的:宿主往往有自己的空态(例如无数据时带「新建」按钮、
78
+ * 外部筛选栏的「清空筛选」),此前内置浮层写死在 `...rest` 之后,把它们全部覆盖掉了。
79
+ * 入参合并:内置的 branch / text / onRetry 照样传给自定义组件,调用方同名入参优先。
80
+ *
81
+ * @author nokecy
82
+ */
83
+ export function resolveNoRowsOverlay(builtIn, builtInParams, custom, customParams) {
84
+ return {
85
+ component: custom !== null && custom !== void 0 ? custom : builtIn,
86
+ params: customParams ? _objectSpread(_objectSpread({}, builtInParams), customParams) : builtInParams
87
+ };
68
88
  }