zmdms-webui 3.4.3 → 3.4.5

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.
@@ -1,3 +1,4 @@
1
+ import { __spreadArray } from '../../_virtual/_tslib.js';
1
2
  import { useRef, useState, useEffect, useCallback } from 'react';
2
3
  import isEqual from 'lodash/isEqual';
3
4
 
@@ -161,80 +162,46 @@ function useSubMenuOpenKeys(userSubMenus, activeTab, options) {
161
162
  }
162
163
  return;
163
164
  }
164
- var _loop_1 = function (key, value) {
165
- if (!Array.isArray(value)) {
166
- return "continue";
167
- }
168
- // 存放当前二级菜单的值
169
- // 20240327 这里有一个问题,就是开发可能会再A系统配置B系统的菜单;
170
- // 这个时候这个菜单的path 就会带上B系统的前缀;这里再去做拼接的话,就会比对不上activeTab当前选中的tab。所以这里要做下判断 如果当前菜单的path有前缀的话,那么不再做前缀的拼接
171
- // let currentSubMenu: any = null;
172
- var result = value.find(function (subMenuVal) {
173
- var system = subMenuVal.system;
165
+ // 20250204 菜单逻辑修改
166
+ // 遍历二级菜单(支持无限层级递归)
167
+ // 递归查找 activeTab 对应的菜单,返回需要展开的祖先 id 链(不含命中节点本身)
168
+ var findMenuAndAncestors = function (menus, ancestors) {
169
+ if (ancestors === void 0) { ancestors = []; }
170
+ for (var _i = 0, menus_1 = menus; _i < menus_1.length; _i++) {
171
+ var menu = menus_1[_i];
172
+ var system = menu.system;
174
173
  var prefix = getPrefixByAppId(system);
175
- // 二级菜单如果没有配置路由的 不需要跳转
176
- // const newPath =
177
- // path === "/" ? "/" : prefix ? `/${prefix}${path}` : path;
178
- var newPath = getNewPath(subMenuVal, prefix);
179
- // 如果值相等的话,说明这个就是目标值
180
- // 即父级就是当前选中项
174
+ var newPath = getNewPath(menu, prefix);
181
175
  if (newPath === activeTab) {
182
- // currentSubMenu = { ...subMenuVal };
183
- // 这里可能有点问题 应该是当前的id
184
- // 默认展开所有菜单
185
- // setOpenKeys([subMenuVal.parentId]);
186
- if (Array.isArray(value)) {
187
- // 要先过滤掉没有子级的菜单,因为没有子级的菜单不需要展开
188
- setOpenKeys(value
189
- .filter(function (i) {
190
- return Array.isArray(i.children) && i.children.length > 0;
191
- })
192
- .map(function (i) { return i.id; }));
193
- }
194
- return true;
176
+ return ancestors;
195
177
  }
196
- // 如果没有子元素,或者子元素不是数组 直接下一轮遍历
197
- if (!subMenuVal.children || !Array.isArray(subMenuVal.children)) {
198
- return false;
199
- }
200
- return subMenuVal.children.find(function (item) {
201
- var system = item.system;
202
- var prefix = getPrefixByAppId(system);
203
- // 二级菜单如果没有配置路由的 不需要跳转
204
- // const newPath =
205
- // path === "/" ? "/" : prefix ? `/${prefix}${path}` : path;
206
- var newPath = getNewPath(item, prefix);
207
- if (newPath === activeTab) {
208
- // currentSubMenu = { ...item };
209
- // 只打开当前级
210
- // setOpenKeys([item.parentId]);
211
- // 默认展开所有菜单
212
- if (Array.isArray(value)) {
213
- setOpenKeys(value
214
- .filter(function (i) {
215
- return Array.isArray(i.children) && i.children.length > 0;
216
- })
217
- .map(function (i) { return i.id; }));
218
- }
219
- return true;
178
+ if (Array.isArray(menu.children) && menu.children.length > 0) {
179
+ var result = findMenuAndAncestors(menu.children, __spreadArray(__spreadArray([], ancestors, true), [
180
+ menu.id,
181
+ ], false));
182
+ if (result) {
183
+ return result;
220
184
  }
221
- return false;
222
- });
223
- });
224
- // 找到当前路由 对应的二级菜单 提前结束循环
225
- if (result) {
226
- // 设置一级菜单选中的key
227
- setMainMenuSelectedKeys && setMainMenuSelectedKeys([key]);
228
- return "break";
185
+ }
229
186
  }
187
+ return null;
230
188
  };
231
- // 20250204 菜单逻辑修改
232
- // 遍历二级菜单
233
189
  for (var _i = 0, _a = Object.entries(userSubMenus); _i < _a.length; _i++) {
234
190
  var _b = _a[_i], key = _b[0], value = _b[1];
235
- var state_1 = _loop_1(key, value);
236
- if (state_1 === "break")
191
+ if (!Array.isArray(value)) {
192
+ continue;
193
+ }
194
+ var ancestorIds = findMenuAndAncestors(value);
195
+ if (ancestorIds) {
196
+ // 顶层菜单全部展开(保持原有行为)+ 命中项的祖先链展开,保证深层菜单可见
197
+ var topLevelIds = value
198
+ .filter(function (i) { return Array.isArray(i.children) && i.children.length > 0; })
199
+ .map(function (i) { return i.id; });
200
+ setOpenKeys(Array.from(new Set(__spreadArray(__spreadArray([], topLevelIds, true), ancestorIds, true))));
201
+ // 设置一级菜单选中的key
202
+ setMainMenuSelectedKeys && setMainMenuSelectedKeys([key]);
237
203
  break;
204
+ }
238
205
  }
239
206
  }, [
240
207
  userSubMenus,
@@ -9,6 +9,22 @@ import dayjs from 'dayjs';
9
9
  // 内部常量,用于标记父数据
10
10
  var IS_PARENT = "__is_parent__";
11
11
  var PARENT_LEVEL = "__parent_level__";
12
+ /**
13
+ * 只保留父行数据(剥离子数据),并标记为父数据。
14
+ * 用于“按收起导出”:仅导出顶层汇总行,不导出子行明细。
15
+ * @param records 原始数据数组
16
+ * @param childrenColumnName 子节点字段名
17
+ */
18
+ function flattenParentOnly(records, childrenColumnName) {
19
+ if (!Array.isArray(records) || records.length === 0) {
20
+ return records;
21
+ }
22
+ return records.map(function (item) {
23
+ var _a;
24
+ var _b = item, _c = childrenColumnName; _b[_c]; var itemWithoutChildren = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
25
+ return __assign(__assign({}, itemWithoutChildren), (_a = {}, _a[IS_PARENT] = true, _a[PARENT_LEVEL] = 0, _a));
26
+ });
27
+ }
12
28
  /**
13
29
  * 扁平化树形数据
14
30
  * @param records 原始数据数组
@@ -48,18 +64,22 @@ function flattenTreeData(records, childrenColumnName) {
48
64
  /**
49
65
  * 使用 ExcelJS + 后处理添加批注
50
66
  * 导出Excel,支持维度合并和小计,以及批注功能
67
+ * @param flatChildren 是否展开子行:true(默认)父子全量平铺;false 只导出父行(收起态)
51
68
  */
52
- function exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName) {
69
+ function exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName, flatChildren) {
53
70
  var _a;
54
71
  var _this = this;
55
72
  if (fileName === void 0) { fileName = "export.xlsx"; }
56
73
  if (sheetName === void 0) { sheetName = "Sheet1"; }
57
74
  if (childrenColumnName === void 0) { childrenColumnName = "children"; }
75
+ if (flatChildren === void 0) { flatChildren = true; }
58
76
  if (!records || records.length === 0) {
59
77
  throw new Error("没有数据可导出");
60
78
  }
61
- // 扁平化树形数据
62
- var flattenedRecords = flattenTreeData(records, childrenColumnName);
79
+ // 扁平化树形数据:flatChildren=false 时只保留父行(收起态导出)
80
+ var flattenedRecords = flatChildren
81
+ ? flattenTreeData(records, childrenColumnName)
82
+ : flattenParentOnly(records, childrenColumnName);
63
83
  var processedData = applyPrecisionToRecords(flattenedRecords, columns);
64
84
  // 准备Excel数据
65
85
  var excelData = prepareExcelData(processedData, columns, columnHeaders, topDescription);
@@ -662,28 +682,30 @@ function applyExcelStyles(worksheet, data, numKeys, dateKeys, columns, headerRow
662
682
  /**
663
683
  * 主要的导出函数,使用改进的批注功能
664
684
  */
665
- function exportToExcelWithMerge(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName) {
685
+ function exportToExcelWithMerge(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName, flatChildren) {
666
686
  if (fileName === void 0) { fileName = "export.xlsx"; }
667
687
  if (sheetName === void 0) { sheetName = "Sheet1"; }
668
688
  if (childrenColumnName === void 0) { childrenColumnName = "children"; }
669
- return exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName);
689
+ if (flatChildren === void 0) { flatChildren = true; }
690
+ return exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys, dateKeys, fileName, sheetName, columnHeaders, summaryConfig, topDescription, topDescriptionRowHeight, childrenColumnName, flatChildren);
670
691
  }
671
692
  /**
672
693
  * 简化版本的导出函数
673
694
  */
674
695
  function exportToExcelSimple(records, config) {
675
- return exportToExcelWithMerge(records, config.columns || [], config.mergeKeys, config.numKeys || [], config.dateKeys, config.fileName || "export.xlsx", config.sheetName || "Sheet1", config.columnHeaders, config.summaryConfig, config.topDescription, config.topDescriptionRowHeight, config.childrenColumnName || "children");
696
+ return exportToExcelWithMerge(records, config.columns || [], config.mergeKeys, config.numKeys || [], config.dateKeys, config.fileName || "export.xlsx", config.sheetName || "Sheet1", config.columnHeaders, config.summaryConfig, config.topDescription, config.topDescriptionRowHeight, config.childrenColumnName || "children", config.flatChildren !== false);
676
697
  }
677
698
  /**
678
699
  * Hook 版本,支持选择导出方式
700
+ * flatChildren 可在 config 中配置默认值,也可在调用 exportExcel(fileName, options) 时通过 options 覆盖。
679
701
  */
680
702
  function useExcelExport(records, config) {
681
- var columns = config.columns, isAutoMerge = config.isAutoMerge, columnHeaders = config.columnHeaders, summaryConfig = config.summaryConfig, childrenColumnName = config.childrenColumnName;
703
+ var columns = config.columns, isAutoMerge = config.isAutoMerge, columnHeaders = config.columnHeaders, summaryConfig = config.summaryConfig, childrenColumnName = config.childrenColumnName, _a = config.flatChildren, defaultFlatChildren = _a === void 0 ? true : _a;
682
704
  var mergeKeys = useMergeKeys(columns, isAutoMerge);
683
705
  var numKeys = useNumKeys(columns);
684
706
  var dateKeys = useDateKeys(columns);
685
707
  var exportFunction = useMemoizedFn(function (fileName, options) {
686
- var _a = options || {}, topDescription = _a.topDescription, topDescriptionRowHeight = _a.topDescriptionRowHeight, time = _a.time;
708
+ var _a = options || {}, topDescription = _a.topDescription, topDescriptionRowHeight = _a.topDescriptionRowHeight, time = _a.time, _b = _a.flatChildren, flatChildren = _b === void 0 ? defaultFlatChildren : _b;
687
709
  if (!fileName.includes(".xlsx")) {
688
710
  fileName = fileName + ".xlsx";
689
711
  }
@@ -701,6 +723,7 @@ function useExcelExport(records, config) {
701
723
  topDescription: topDescription,
702
724
  topDescriptionRowHeight: topDescriptionRowHeight,
703
725
  childrenColumnName: childrenColumnName,
726
+ flatChildren: flatChildren,
704
727
  });
705
728
  });
706
729
  return exportFunction;
@@ -335,11 +335,14 @@ interface ITableRefHandel {
335
335
  onResetDynamicList?: () => void;
336
336
  /**
337
337
  * 导出excel
338
+ * config.flatChildren: 是否展开子行,默认 true(父子全量平铺);false 时只导出父行(收起态汇总)
338
339
  */
339
340
  exportExcel?: (fileName: string, config?: {
340
341
  topDescription?: string;
341
342
  time?: string;
342
343
  topDescriptionRowHeight?: number;
344
+ /** 是否展开子行,默认 true。false 时只导出父行(收起态) */
345
+ flatChildren?: boolean;
343
346
  }) => void;
344
347
  }
345
348
  interface ITableProps<RecordType> extends Omit<TableProps<RecordType>, "columns"> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "3.4.3",
3
+ "version": "3.4.5",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",