zmdms-webui 2.4.8 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,7 @@ var useTableInteraction = function (params) {
35
35
  displayHeight: containerHeight,
36
36
  needHorizontalScrollbar: needHorizontalScrollbar,
37
37
  scrollbarSize: scrollbarSize,
38
+ mergeCellMap: mergeCellMap,
38
39
  });
39
40
  });
40
41
  // 处理选择框列的全选点击
@@ -621,7 +621,7 @@ var useTableRender = function (params) {
621
621
  // 合计行选择框列显示文本(比如"合计")
622
622
  var dataIndex = column.dataIndex || column.key;
623
623
  var cellValue = record[dataIndex];
624
- var cellText = formatCellValue(cellValue, column);
624
+ var cellText = formatCellValue(cellValue, column, true);
625
625
  if (cellText) {
626
626
  ctx.fillStyle = COLORS.text;
627
627
  ctx.font = "bold ".concat(FONT_SIZE, "px ").concat(FONT_FAMILY);
@@ -656,7 +656,7 @@ var useTableRender = function (params) {
656
656
  // 应用格式化(日期、精度、千分符)
657
657
  var cellText = void 0;
658
658
  // 对于合计行,直接使用格式化函数,不应用render
659
- if (isSummaryRow) {
659
+ if (isSummaryRow && column.key !== "__index__") {
660
660
  cellText = formatCellValue(cellValue, column);
661
661
  }
662
662
  else {
@@ -800,8 +800,24 @@ var useTableRender = function (params) {
800
800
  ctx.stroke();
801
801
  ctx.lineWidth = 1; // 恢复为1px
802
802
  }
803
- // 计算实际数据区域的底部位置
804
- var dataBottomY = Math.min(headerHeight + dataRowCount * rowHeight - scrollState.scrollTop, displayHeight);
803
+ // 计算固定行占用的高度
804
+ var fixedTopRowsCount = fixedRowsCount || (fixedRowsConfig === null || fixedRowsConfig === void 0 ? void 0 : fixedRowsConfig.topCount) || 0;
805
+ var fixedBottomRowsCount = (fixedRowsConfig === null || fixedRowsConfig === void 0 ? void 0 : fixedRowsConfig.bottomCount) || 0;
806
+ var fixedSummaryHeight = summaryFixed && hasSummaryRow ? rowHeight : 0;
807
+ var fixedBottomHeight = fixedBottomRowsCount * rowHeight;
808
+ // 计算可滚动数据行的数量(排除固定行和合计行)
809
+ var scrollableDataRowCount = dataRowCount -
810
+ fixedTopRowsCount -
811
+ fixedBottomRowsCount -
812
+ (summaryFixed && hasSummaryRow ? 1 : 0);
813
+ // 计算实际数据区域的底部位置(考虑固定底部行和固定合计行)
814
+ var dataBottomY = Math.min(headerHeight +
815
+ fixedTopRowsCount * rowHeight +
816
+ scrollableDataRowCount * rowHeight -
817
+ scrollState.scrollTop, displayHeight -
818
+ (needHorizontalScrollbar ? SCROLLBAR_SIZE : 0) -
819
+ fixedBottomHeight -
820
+ fixedSummaryHeight);
805
821
  // 绘制垂直边框(只绘制body部分,从headerHeight开始,表头边框在drawHeaderCell中绘制)
806
822
  columnRenderInfos.forEach(function (info, colIndex) {
807
823
  var x = info.x, width = info.width, fixed = info.fixed, fixedLeft = info.fixedLeft;
@@ -823,9 +839,17 @@ var useTableRender = function (params) {
823
839
  ctx.stroke();
824
840
  }
825
841
  });
842
+ // 绘制水平边框(只绘制实际数据行的边框)
843
+ var maxRow = Math.min(endRow, dataRowCount, fixedTopRowsCount + scrollableDataRowCount);
826
844
  var _loop_1 = function (i) {
827
- var y = headerHeight + i * rowHeight - scrollState.scrollTop;
828
- if (y >= headerHeight && y <= displayHeight) {
845
+ // 计算Y坐标时需要考虑固定顶部行
846
+ var y = headerHeight +
847
+ fixedTopRowsCount * rowHeight +
848
+ (i - fixedTopRowsCount) * rowHeight -
849
+ scrollState.scrollTop;
850
+ // 只绘制在可滚动数据区域内的边框
851
+ if (y >= headerHeight + fixedTopRowsCount * rowHeight &&
852
+ y <= dataBottomY) {
829
853
  // 分段绘制,只绘制当前范围(fixed或非fixed)的边框
830
854
  columnRenderInfos.forEach(function (info, colIndex) {
831
855
  // 根据 onlyFixed 参数过滤
@@ -856,8 +880,7 @@ var useTableRender = function (params) {
856
880
  });
857
881
  }
858
882
  };
859
- // 绘制水平边框(只绘制实际数据行的边框)
860
- for (var i = startRow; i <= endRow && i <= dataRowCount; i++) {
883
+ for (var i = startRow; i <= maxRow; i++) {
861
884
  _loop_1(i);
862
885
  }
863
886
  // 为合并单元格绘制底部边框
@@ -865,8 +888,8 @@ var useTableRender = function (params) {
865
888
  mergeCellMap.forEach(function (mergeInfo, key) {
866
889
  if (!mergeInfo.skip && mergeInfo.rowSpan > 1) {
867
890
  var rowIndex = mergeInfo.rowIndex, colIndex = mergeInfo.colIndex, rowSpan = mergeInfo.rowSpan;
868
- // 只绘制在可视范围内的
869
- if (rowIndex >= startRow && rowIndex <= endRow) {
891
+ // 只绘制在可视范围内的且在数据区域内的
892
+ if (rowIndex >= startRow && rowIndex <= maxRow) {
870
893
  var columnInfo = columnRenderInfos[colIndex];
871
894
  if (!columnInfo)
872
895
  return;
@@ -880,11 +903,14 @@ var useTableRender = function (params) {
880
903
  ? getColumnWidth(colIndex)
881
904
  : width;
882
905
  var drawX = fixed ? fixedLeft : x - scrollState.scrollLeft;
883
- // 绘制合并单元格的底边框
906
+ // 绘制合并单元格的底边框,考虑固定顶部行
884
907
  var bottomY = headerHeight +
885
- (rowIndex + rowSpan) * rowHeight -
908
+ fixedTopRowsCount * rowHeight +
909
+ (rowIndex + rowSpan - fixedTopRowsCount) * rowHeight -
886
910
  scrollState.scrollTop;
887
- if (bottomY >= headerHeight && bottomY <= displayHeight) {
911
+ // 只在数据区域内绘制
912
+ if (bottomY >= headerHeight + fixedTopRowsCount * rowHeight &&
913
+ bottomY <= dataBottomY) {
888
914
  ctx.beginPath();
889
915
  ctx.moveTo(drawX, bottomY);
890
916
  ctx.lineTo(drawX + actualWidth, bottomY);
@@ -5,7 +5,7 @@
5
5
  * 获取鼠标位置对应的单元格
6
6
  */
7
7
  var getCellFromMousePosition = function (params) {
8
- var x = params.x, y = params.y, headerHeight = params.headerHeight, rowHeight = params.rowHeight, scrollTop = params.scrollTop, scrollLeft = params.scrollLeft, columnRenderInfos = params.columnRenderInfos, dataLength = params.dataLength, _a = params.fixedTopRowsCount, fixedTopRowsCount = _a === void 0 ? 0 : _a, _b = params.fixedBottomRowsCount, fixedBottomRowsCount = _b === void 0 ? 0 : _b, _c = params.hasSummaryRow, hasSummaryRow = _c === void 0 ? false : _c, _d = params.summaryFixed, summaryFixed = _d === void 0 ? false : _d, _e = params.displayHeight, displayHeight = _e === void 0 ? 0 : _e, _f = params.needHorizontalScrollbar, needHorizontalScrollbar = _f === void 0 ? false : _f, _g = params.scrollbarSize, scrollbarSize = _g === void 0 ? 12 : _g;
8
+ var x = params.x, y = params.y, headerHeight = params.headerHeight, rowHeight = params.rowHeight, scrollTop = params.scrollTop, scrollLeft = params.scrollLeft, columnRenderInfos = params.columnRenderInfos, dataLength = params.dataLength, _a = params.fixedTopRowsCount, fixedTopRowsCount = _a === void 0 ? 0 : _a, _b = params.fixedBottomRowsCount, fixedBottomRowsCount = _b === void 0 ? 0 : _b, _c = params.hasSummaryRow, hasSummaryRow = _c === void 0 ? false : _c, _d = params.summaryFixed, summaryFixed = _d === void 0 ? false : _d, _e = params.displayHeight, displayHeight = _e === void 0 ? 0 : _e, _f = params.needHorizontalScrollbar, needHorizontalScrollbar = _f === void 0 ? false : _f, _g = params.scrollbarSize, scrollbarSize = _g === void 0 ? 12 : _g, mergeCellMap = params.mergeCellMap;
9
9
  // 判断是否在表头区域(row=-1表示表头)
10
10
  var rowIndex;
11
11
  if (y < headerHeight) {
@@ -20,7 +20,7 @@ var getCellFromMousePosition = function (params) {
20
20
  rowIndex = Math.floor(relativeY / rowHeight);
21
21
  if (rowIndex < 0 || rowIndex >= fixedTopRowsCount)
22
22
  return null;
23
- return findColumn(x, scrollLeft, columnRenderInfos, rowIndex);
23
+ return findColumn(x, scrollLeft, columnRenderInfos, rowIndex, mergeCellMap);
24
24
  }
25
25
  // 检查是否在固定合计行区域
26
26
  if (summaryFixed && hasSummaryRow && displayHeight > 0) {
@@ -30,7 +30,7 @@ var getCellFromMousePosition = function (params) {
30
30
  if (y >= summaryRowY) {
31
31
  // 在固定合计行区域
32
32
  rowIndex = dataLength - 1; // 合计行是最后一行
33
- return findColumn(x, scrollLeft, columnRenderInfos, rowIndex);
33
+ return findColumn(x, scrollLeft, columnRenderInfos, rowIndex, mergeCellMap);
34
34
  }
35
35
  }
36
36
  // 检查是否在固定底部行区域
@@ -54,7 +54,7 @@ var getCellFromMousePosition = function (params) {
54
54
  rowIndex = bottomRowsStartIndex + relativeIndex;
55
55
  if (rowIndex < 0 || rowIndex >= dataLength)
56
56
  return null;
57
- return findColumn(x, scrollLeft, columnRenderInfos, rowIndex);
57
+ return findColumn(x, scrollLeft, columnRenderInfos, rowIndex, mergeCellMap);
58
58
  }
59
59
  }
60
60
  // 在可滚动区域
@@ -71,12 +71,13 @@ var getCellFromMousePosition = function (params) {
71
71
  return null;
72
72
  }
73
73
  }
74
- return findColumn(x, scrollLeft, columnRenderInfos, rowIndex);
74
+ return findColumn(x, scrollLeft, columnRenderInfos, rowIndex, mergeCellMap);
75
75
  };
76
76
  /**
77
77
  * 根据x坐标查找列索引
78
78
  */
79
- function findColumn(x, scrollLeft, columnRenderInfos, rowIndex) {
79
+ function findColumn(x, scrollLeft, columnRenderInfos, rowIndex, mergeCellMap) {
80
+ var foundCell = null;
80
81
  // 优先查找fixed列(因为fixed列在上层,会遮挡下层的非fixed列)
81
82
  for (var i = 0; i < columnRenderInfos.length; i++) {
82
83
  var info = columnRenderInfos[i];
@@ -84,22 +85,58 @@ function findColumn(x, scrollLeft, columnRenderInfos, rowIndex) {
84
85
  var fixedLeft = info.fixedLeft, width = info.width;
85
86
  var drawX = fixedLeft;
86
87
  if (x >= drawX && x < drawX + width) {
87
- return { row: rowIndex, col: i };
88
+ foundCell = { row: rowIndex, col: i };
89
+ break;
88
90
  }
89
91
  }
90
92
  }
91
93
  // 如果不在fixed列上,再查找非fixed列
92
- for (var i = 0; i < columnRenderInfos.length; i++) {
93
- var info = columnRenderInfos[i];
94
- if (!info.fixed) {
95
- var width = info.width;
96
- var drawX = info.x - scrollLeft;
97
- if (x >= drawX && x < drawX + width) {
98
- return { row: rowIndex, col: i };
94
+ if (!foundCell) {
95
+ for (var i = 0; i < columnRenderInfos.length; i++) {
96
+ var info = columnRenderInfos[i];
97
+ if (!info.fixed) {
98
+ var width = info.width;
99
+ var drawX = info.x - scrollLeft;
100
+ if (x >= drawX && x < drawX + width) {
101
+ foundCell = { row: rowIndex, col: i };
102
+ break;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ // 如果找到了单元格,检查它是否是被合并的单元格
108
+ if (foundCell && mergeCellMap) {
109
+ var mergeCellKey = "".concat(foundCell.row, "-").concat(foundCell.col);
110
+ var mergeInfo = mergeCellMap.get(mergeCellKey);
111
+ // 如果是被合并的单元格(skip=true),需要找到主单元格
112
+ if (mergeInfo && mergeInfo.skip) {
113
+ // 遍历所有可能的主单元格位置(从左上角开始,到当前位置)
114
+ // 找到覆盖当前位置的主单元格
115
+ for (var checkRow = 0; checkRow <= foundCell.row; checkRow++) {
116
+ for (var checkCol = 0; checkCol <= foundCell.col; checkCol++) {
117
+ var mainCellKey = "".concat(checkRow, "-").concat(checkCol);
118
+ var mainMergeInfo = mergeCellMap.get(mainCellKey);
119
+ // 找到主单元格(skip=false且有合并)
120
+ if (mainMergeInfo &&
121
+ !mainMergeInfo.skip &&
122
+ (mainMergeInfo.rowSpan > 1 || mainMergeInfo.colSpan > 1)) {
123
+ // 计算主单元格覆盖的范围
124
+ var mainCellEndRow = checkRow + mainMergeInfo.rowSpan - 1;
125
+ var mainCellEndCol = checkCol + mainMergeInfo.colSpan - 1;
126
+ // 检查当前位置是否在主单元格的覆盖范围内
127
+ if (foundCell.row >= checkRow &&
128
+ foundCell.row <= mainCellEndRow &&
129
+ foundCell.col >= checkCol &&
130
+ foundCell.col <= mainCellEndCol) {
131
+ // 返回主单元格的坐标
132
+ return { row: checkRow, col: checkCol };
133
+ }
134
+ }
135
+ }
99
136
  }
100
137
  }
101
138
  }
102
- return null;
139
+ return foundCell;
103
140
  }
104
141
  /**
105
142
  * 提取单元格文本(处理 render 函数)
@@ -17,9 +17,11 @@ var formatDate = function (value, format) {
17
17
  /**
18
18
  * 格式化单元格值
19
19
  */
20
- var formatCellValue = function (value, column) {
20
+ var formatCellValue = function (value, column, noEmptyText) {
21
21
  // 空值处理:null、undefined、空字符串
22
22
  if (value === null || value === undefined || value === "") {
23
+ if (noEmptyText)
24
+ return "";
23
25
  return column.emptyText !== undefined ? column.emptyText : "— —";
24
26
  }
25
27
  var formattedValue = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "2.4.8",
3
+ "version": "2.4.9",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",