@lingxiteam/ebe-utils 0.2.22 → 0.2.24

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 (145) hide show
  1. package/lib/h5public/yarn.lock +7 -8
  2. package/lib/pcpublic/src/components/pcfactory/src/Button/index.tsx +11 -10
  3. package/lib/pcpublic/src/components/pcfactory/src/Card/CardTitle/index.tsx +31 -24
  4. package/lib/pcpublic/src/components/pcfactory/src/Card/index.tsx +32 -14
  5. package/lib/pcpublic/src/components/pcfactory/src/Card/useExtendBtn.tsx +85 -48
  6. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/ChartLine.tsx +24 -6
  7. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/PropsType.ts +31 -5
  8. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/index.tsx +3 -2
  9. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/loader.tsx +1 -1
  10. package/lib/pcpublic/src/components/pcfactory/src/Form/Form.tsx +153 -129
  11. package/lib/pcpublic/src/components/pcfactory/src/Form/index.tsx +2 -5
  12. package/lib/pcpublic/src/components/pcfactory/src/Form/useFormStatus.ts +8 -4
  13. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/LXPieChart.tsx +15 -3
  14. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/PropsType.ts +4 -3
  15. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/index.tsx +1 -1
  16. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/loader.tsx +1 -1
  17. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/LXRadarChat.tsx +18 -4
  18. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/PropsType.ts +2 -1
  19. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/index.tsx +1 -1
  20. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/loader.tsx +1 -1
  21. package/lib/pcpublic/src/components/pcfactory/src/Layout/index.tsx +2 -2
  22. package/lib/pcpublic/src/components/pcfactory/src/ModalSelect/BaseModalSelect.tsx +7 -2
  23. package/lib/pcpublic/src/components/pcfactory/src/ModalSelect/index.tsx +60 -26
  24. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/LcdpUeditorMain.tsx +62 -55
  25. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/RichTextEditor.tsx +2 -6
  26. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/RichTextEditorMain.tsx +5 -5
  27. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/index.tsx +9 -2
  28. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/loader.ts +1 -1
  29. package/lib/pcpublic/src/components/pcfactory/src/Select/index.tsx +145 -66
  30. package/lib/pcpublic/src/components/pcfactory/src/Select/selectUtils.ts +13 -9
  31. package/lib/pcpublic/src/components/pcfactory/src/Table/BodyCell/index.tsx +36 -26
  32. package/lib/pcpublic/src/components/pcfactory/src/Table/EditComponent/index.tsx +69 -94
  33. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/GhostTag/index.tsx +12 -5
  34. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/Hyperlink/index.tsx +9 -5
  35. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PointTag/index.tsx +11 -5
  36. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PureColourFill/index.tsx +11 -5
  37. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PureFadeColourTag/index.tsx +14 -7
  38. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/Thumbnail/index.tsx +30 -31
  39. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/index.tsx +89 -41
  40. package/lib/pcpublic/src/components/pcfactory/src/Table/HeaderCell/HeaderCellTitle/index.tsx +25 -12
  41. package/lib/pcpublic/src/components/pcfactory/src/Table/HeaderCell/index.tsx +12 -5
  42. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/PopoverWrapper.tsx +220 -0
  43. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/SingleBtn.tsx +39 -32
  44. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/index.tsx +178 -148
  45. package/lib/pcpublic/src/components/pcfactory/src/Table/Table.tsx +439 -0
  46. package/lib/pcpublic/src/components/pcfactory/src/Table/TableHead/index.tsx +159 -72
  47. package/lib/pcpublic/src/components/pcfactory/src/Table/TableSummaryRow/index.tsx +12 -20
  48. package/lib/pcpublic/src/components/pcfactory/src/Table/constant.ts +3 -0
  49. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/index.ts +4 -4
  50. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCMDActions.ts +32 -28
  51. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCheckStrict.ts +44 -57
  52. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useColumns.tsx +306 -276
  53. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCommon.ts +9 -6
  54. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useDataSource.ts +30 -21
  55. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useExpandable.tsx +33 -27
  56. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useFilter.tsx +84 -77
  57. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useFormatCell.tsx +33 -16
  58. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/usePagination.ts +15 -5
  59. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useRowEdit.ts +33 -33
  60. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useRowMerge.ts +13 -5
  61. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useScroll.ts +94 -28
  62. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSelection.ts +108 -99
  63. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSort.ts +8 -5
  64. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSummaryCol.ts +27 -43
  65. package/lib/pcpublic/src/components/pcfactory/src/Table/index.tsx +73 -394
  66. package/lib/pcpublic/src/components/pcfactory/src/Table/loader.tsx +15 -0
  67. package/lib/pcpublic/src/components/pcfactory/src/Table/types/OperationCell.d.ts +2 -2
  68. package/lib/pcpublic/src/components/pcfactory/src/Table/types/event.d.ts +12 -8
  69. package/lib/pcpublic/src/components/pcfactory/src/Table/types/headerCell.d.ts +2 -1
  70. package/lib/pcpublic/src/components/pcfactory/src/Table/types/prop.d.ts +24 -11
  71. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/SequenceId.ts +2 -1
  72. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/index.ts +90 -82
  73. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/indexedDBHelper.ts +9 -22
  74. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/translate.ts +59 -0
  75. package/lib/pcpublic/src/components/pcfactory/src/Transfer/Transfer.tsx +644 -0
  76. package/lib/pcpublic/src/components/pcfactory/src/Transfer/index.tsx +49 -637
  77. package/lib/pcpublic/src/components/pcfactory/src/Transfer/loader.tsx +11 -0
  78. package/lib/pcpublic/src/components/pcfactory/src/Tree/TreeEllipsisIcon.tsx +38 -0
  79. package/lib/pcpublic/src/components/pcfactory/src/Tree/TreeNodeMenu/index.tsx +34 -35
  80. package/lib/pcpublic/src/components/pcfactory/src/Tree/index.tsx +213 -149
  81. package/lib/pcpublic/src/components/pcfactory/src/TreeSelect/index.tsx +47 -43
  82. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/TreeTable.tsx +264 -0
  83. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/index.ts +4 -1
  84. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/useCMDAction.ts +9 -3
  85. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/useExpandable.tsx +9 -3
  86. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/index.tsx +52 -191
  87. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/loader.tsx +16 -0
  88. package/lib/pcpublic/src/components/pcfactory/src/assets/index.tsx +34 -0
  89. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/quadrate.tsx +20 -0
  90. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/roundness.tsx +14 -0
  91. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/semicircle.tsx +15 -0
  92. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/verticalLine.tsx +12 -0
  93. package/lib/pcpublic/src/components/pcfactory/src/styles/common.less +17 -0
  94. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Card.less +57 -11
  95. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Form.less +101 -12
  96. package/lib/pcpublic/src/components/pcfactory/src/styles/components/ModalSelect.less +6 -0
  97. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Select.less +70 -6
  98. package/lib/pcpublic/src/components/pcfactory/src/utils/ChannelContainer.tsx +20 -14
  99. package/lib/pcpublic/src/components/pcfactory/src/utils/ChildRender.ts +6 -8
  100. package/lib/pcpublic/src/components/pcfactory/src/utils/CustomModule.tsx +4 -6
  101. package/lib/pcpublic/src/components/pcfactory/src/utils/DummyFormContext.ts +9 -13
  102. package/lib/pcpublic/src/components/pcfactory/src/utils/Empty/empty.tsx +5 -17
  103. package/lib/pcpublic/src/components/pcfactory/src/utils/Empty/index.tsx +3 -3
  104. package/lib/pcpublic/src/components/pcfactory/src/utils/Holidays.ts +11 -39
  105. package/lib/pcpublic/src/components/pcfactory/src/utils/HolidaysFormat.ts +83 -0
  106. package/lib/pcpublic/src/components/pcfactory/src/utils/IdleContainer/index.tsx +47 -0
  107. package/lib/pcpublic/src/components/pcfactory/src/utils/IdleContainer/scheduler.ts +74 -0
  108. package/lib/pcpublic/src/components/pcfactory/src/utils/LoaderHelper.tsx +4 -1
  109. package/lib/pcpublic/src/components/pcfactory/src/utils/Spin/index.tsx +8 -7
  110. package/lib/pcpublic/src/components/pcfactory/src/utils/WithSyncValue.ts +25 -23
  111. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/index.ts +10 -7
  112. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useMap.ts +9 -6
  113. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useMemoizedFn.ts +4 -1
  114. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/usePersistFn.ts +17 -0
  115. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useSafeState.ts +2 -2
  116. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useSetState.ts +7 -5
  117. package/lib/pcpublic/src/components/pcfactory/src/utils/common.ts +23 -50
  118. package/lib/pcpublic/src/components/pcfactory/src/utils/constant.ts +53 -57
  119. package/lib/pcpublic/src/components/pcfactory/src/utils/dynamicUtils/DynamicContext.tsx +12 -17
  120. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/FormContext.tsx +22 -12
  121. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/FormFields.tsx +50 -19
  122. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/WrapperContainer.tsx +58 -37
  123. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/cmdHelper.ts +33 -30
  124. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/common.ts +2 -0
  125. package/lib/pcpublic/src/components/pcfactory/src/utils/generatorDisabledCallback.ts +121 -113
  126. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useCommonImperativeHandle.ts +16 -14
  127. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useCompState.tsx +1 -1
  128. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useDataMask.ts +7 -2
  129. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useDoubleClick.ts +3 -1
  130. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useFuncExpExecute.ts +16 -14
  131. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useGetStaticAttrData.ts +9 -3
  132. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useHiddenStyle.ts +4 -5
  133. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useInit.ts +11 -0
  134. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useInitReactQuill.ts +3 -1
  135. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useListenState.ts +1 -0
  136. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useLocale.ts +6 -4
  137. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/usePrintMode.tsx +2 -2
  138. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useRules.ts +1 -1
  139. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useTestHelper.ts +2 -0
  140. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useToggleBoolean.ts +8 -4
  141. package/lib/pcpublic/src/components/pcfactory/src/utils/index.ts +10 -10
  142. package/lib/pcpublic/src/components/pcfactory/src/utils/polyfill.js +29 -31
  143. package/lib/pcpublic/src/components/pcfactory/src/utils/renderReadOnly.tsx +29 -26
  144. package/lib/public/public/iconfont.js +1 -0
  145. package/package.json +2 -2
@@ -1,18 +1,19 @@
1
- import { TableRowSelection } from 'antd/lib/table/interface';
2
1
  import { useEffect, useMemo, useRef, useState } from 'react';
3
2
  import { MyTableProps } from '../types/prop';
4
- import { recursionDataSource } from '../utils';
5
3
  import useCheckStrict from './useCheckStrict';
4
+ import { TableRowSelection } from 'antd/lib/table/interface';
5
+ import { recursionDataSource } from '../utils';
6
+
6
7
 
7
8
  type selectionProps<T> = {
8
- innerDataSource: T[];
9
- currentRowKey: string;
10
- currentPageDataSource: T[];
11
- checkIfHiddenRow?: Function;
12
- hasPageChangeEvent?: boolean;
13
- funcExpExecute: Function;
14
- };
15
- const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps & selectionProps<T>) => {
9
+ innerDataSource: T[],
10
+ currentRowKey: string,
11
+ currentPageDataSource: T[],
12
+ checkIfHiddenRow?: Function,
13
+ hasPageChangeEvent?: boolean,
14
+ funcExpExecute: Function,
15
+ }
16
+ const useSelection = <T extends {[key: string]: unknown}, >(props: MyTableProps & selectionProps<T>) => {
16
17
  const {
17
18
  innerDataSource,
18
19
  currentRowKey,
@@ -30,6 +31,7 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
30
31
 
31
32
  const { childrenColumnName = 'children' } = expandable || {};
32
33
 
34
+
33
35
  const [selectedRows, setSelectedRows] = useState<any[]>([]);
34
36
  const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>([]);
35
37
  const [currentPageSelectedRows, setCurrentPageSelectedRows] = useState<any[]>([]);
@@ -42,6 +44,7 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
42
44
  childrenKey: childrenColumnName,
43
45
  });
44
46
 
47
+
45
48
  // 记录动作+操作选中的keys,包括跨页和非法的key
46
49
  const combineSelectedRowKeysRef = useRef<any[]>([]);
47
50
  const hiddenKeysRef = useRef<any[]>([]);
@@ -54,11 +57,8 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
54
57
  } else {
55
58
  // 当更新当前selectedKeys时,从hiddenKeys中过滤掉页面上已展示过的
56
59
  // 配置时兼容key为数字or字符串的情况
57
- const currentMap: Record<string | number, boolean> = keys.reduce((p, n) => {
58
- p[n] = true;
59
- return p;
60
- }, {} as any);
61
- hiddenKeysRef.current = hiddenKeysRef.current.filter(k => !currentMap[k]);
60
+ const currentMap: Record<string | number, boolean> = keys.reduce((p, n) => { p[n] = true; return p; }, {} as any);
61
+ hiddenKeysRef.current = hiddenKeysRef.current.filter((k) => !currentMap[k]);
62
62
  }
63
63
  // 更新表格所有的选中key
64
64
  combineSelectedRowKeysRef.current = [...new Set([...curKeys, ...hiddenKeysRef.current])];
@@ -86,8 +86,7 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
86
86
  value: index,
87
87
  },
88
88
  ]);
89
- }
90
- if (rowSelectionDisabled) {
89
+ } if (rowSelectionDisabled) {
91
90
  /**
92
91
  * 新版:配置态生成的DSL就是一个$$包含函数的表达式
93
92
  * 但会经过预处理移除 $$
@@ -108,10 +107,10 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
108
107
  };
109
108
 
110
109
  /**
111
- * 获取所有页选中行数据
112
- * @param _selectedRows 当前选中的行数据
113
- * @returns
114
- */
110
+ * 获取所有页选中行数据
111
+ * @param _selectedRows 当前选中的行数据
112
+ * @returns
113
+ */
115
114
  const handleAllPageSelectedRows = (_selectedRows: any[] = []) => {
116
115
  // 当 未配置页面回调事件 时,认为是前端分页,此时,_selectedRows 就代表所有页选中行数据
117
116
  if (!hasPageChangeEvent) {
@@ -120,9 +119,14 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
120
119
 
121
120
  // 当 配置页面回调事件 时,认为是后端分页,此时,_selectedRows 代表当前页选中数据,需要特殊处理
122
121
  if (currentRowKey) {
122
+ const currentPageKey = new Set<string>();
123
+ // 记录当前页数据(包括层级数据)的主键集合
124
+ recursionDataSource(innerDataSource, (n) => {
125
+ currentPageKey.add(n[currentRowKey] as string);
126
+ }, childrenColumnName);
123
127
  // 移除当前所有页行选中中,当前页对应的选中
124
- const otherPageSelectedRows = selectedRows.filter(selectedRow => {
125
- return !innerDataSource.some((row: any) => row[currentRowKey] === selectedRow[currentRowKey]);
128
+ const otherPageSelectedRows = selectedRows.filter((selectedRow) => {
129
+ return !currentPageKey.has(selectedRow[currentRowKey]);
126
130
  });
127
131
 
128
132
  // 重新补回最新的当前页的选中数据,返回所有页选中行数据
@@ -143,15 +147,11 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
143
147
  if (currentRowKey) {
144
148
  const currentPageKey = new Set<string>();
145
149
  // 记录当前页数据(包括层级数据)的主键集合
146
- recursionDataSource(
147
- currentPageDataSource,
148
- n => {
149
- currentPageKey.add(n[currentRowKey] as string);
150
- },
151
- childrenColumnName
152
- );
150
+ recursionDataSource(currentPageDataSource, (n) => {
151
+ currentPageKey.add(n[currentRowKey] as string);
152
+ }, childrenColumnName);
153
153
  // 在当前最新的选中的行数据中,找到属于当前页的、且可选中数据
154
- currentPageSeletedRows = selectedRows.filter(selectedRow => {
154
+ currentPageSeletedRows = selectedRows.filter((selectedRow) => {
155
155
  return currentPageKey.has(selectedRow[currentRowKey]);
156
156
  });
157
157
  }
@@ -167,7 +167,11 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
167
167
  const handleSelect = (_selectedRows: any[]) => {
168
168
  // 单选
169
169
  if (rowSelection?.type === 'radio') {
170
- onRowSelected(_selectedRows, true, _selectedRows);
170
+ onRowSelected(
171
+ _selectedRows,
172
+ true,
173
+ _selectedRows,
174
+ );
171
175
  } else {
172
176
  // 多选
173
177
  const allPageSelectedRows = handleAllPageSelectedRows(_selectedRows);
@@ -182,11 +186,19 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
182
186
  currentPageSelectedRows = _selectedRows;
183
187
  }
184
188
 
185
- onRowSelected(allPageSelectedRows, true, currentPageSelectedRows);
189
+ onRowSelected(
190
+ allPageSelectedRows,
191
+ true,
192
+ currentPageSelectedRows,
193
+ );
186
194
  }
187
195
  };
188
196
 
189
- const onRowSelected = (_sltrows: any[], doOnSelectChange: boolean, _currentPageSelectedRows?: any[]) => {
197
+ const onRowSelected = (
198
+ _sltrows: any[],
199
+ doOnSelectChange: boolean,
200
+ _currentPageSelectedRows?: any[],
201
+ ) => {
190
202
  const sltrows: any = currentRowKey ? _sltrows : [];
191
203
 
192
204
  const sltkeys: any = sltrows.map((row: any) => row[currentRowKey]);
@@ -242,7 +254,12 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
242
254
  // );
243
255
  // }
244
256
 
245
- rowSelection.type === 'radio' ? onRowSelected([record], true) : onRowSelected(triggerSingleSelection(selectedRows, record), true);
257
+ rowSelection.type === 'radio'
258
+ ? onRowSelected([record], true)
259
+ : onRowSelected(
260
+ triggerSingleSelection(selectedRows, record),
261
+ true,
262
+ );
246
263
  }
247
264
  };
248
265
 
@@ -253,7 +270,7 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
253
270
  const rowsObject = new Map();
254
271
  if (selectedRowsRule) {
255
272
  if (!['string', 'object'].includes(typeof selectedRowsRule)) {
256
- // TODO: (2022.7.27 与国永沟通),废弃旧版本在表格内部对 $$ 表达式的解析
273
+ // TODO: (2022.7.27 与国永沟通),废弃旧版本在表格内部对 $$ 表达式的解析
257
274
  console.warn('请检查配置数据,现有版本只支持(行id字符串或数组、行对象)');
258
275
  updateSelectRowsObject(rowsObject);
259
276
  return;
@@ -261,28 +278,26 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
261
278
 
262
279
  // '1' / '1,2,3' / 1,2,3 代表选中行的行id
263
280
  if (typeof selectedRowsRule === 'string') {
264
- actionSetSelectedKeys = selectedRowsRule?.split(',').map(k => k.trim()) || [];
281
+ actionSetSelectedKeys = selectedRowsRule?.split(',').map((k) => k.trim()) || [];
265
282
  }
266
283
 
267
284
  // 处理 [{ [rowId]: '1'} ...] 或 ['1', '2'] 或 [1, 2]
268
285
  if (Array.isArray(selectedRowsRule)) {
269
- actionSetSelectedKeys = selectedRowsRule
270
- .map(one => {
271
- if (['string', 'number'].includes(typeof one)) {
272
- return one;
273
- }
286
+ actionSetSelectedKeys = selectedRowsRule.map((one) => {
287
+ if (['string', 'number'].includes(typeof one)) {
288
+ return one;
289
+ }
274
290
 
275
- if (typeof one === 'object' && !Array.isArray(one) && one) {
276
- const rowKey = one[currentRowKey];
277
- if (rowKey) {
278
- rowsObject.set(rowKey, one);
279
- }
280
- return rowKey;
291
+ if (typeof one === 'object' && !Array.isArray(one) && one) {
292
+ const rowKey = one[currentRowKey];
293
+ if (rowKey) {
294
+ rowsObject.set(rowKey, one);
281
295
  }
296
+ return rowKey;
297
+ }
282
298
 
283
- return undefined;
284
- })
285
- .filter(one => !!one);
299
+ return undefined;
300
+ }).filter(one => !!one);
286
301
  }
287
302
 
288
303
  // 代表行数据对象
@@ -306,19 +321,15 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
306
321
 
307
322
  useEffect(() => {
308
323
  if (currentRowKey) {
309
- const keySet: Record<string | number, unknown> = {};
324
+ const keySet: Record<string|number, unknown> = {};
310
325
  const map: any = {};
311
326
  // 数据源变更需要更新当前选中行的数据,保证获取时能获取到当前最新的数据详情
312
- recursionDataSource<{ [k: string]: any; children?: any[] }>(
313
- innerDataSource as [],
314
- n => {
315
- map[n[currentRowKey]] = n;
316
- },
317
- childrenColumnName
318
- );
319
-
327
+ recursionDataSource<{[k: string]: any, children?: any[]}>(innerDataSource as [], (n) => {
328
+ map[n[currentRowKey]] = n;
329
+ }, childrenColumnName);
330
+
320
331
  const rows = [];
321
- selectedRows.forEach(selectedRow => {
332
+ selectedRows.forEach((selectedRow) => {
322
333
  const key = selectedRow[currentRowKey];
323
334
  if (!map[key]) {
324
335
  map[key] = selectedRow;
@@ -328,7 +339,7 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
328
339
  const actionRows: any[] = [];
329
340
  const collectSelectedRow = (key: string | number, childFlag = false) => {
330
341
  if (!keySet[key]) {
331
- const row = map[key] || actionSetSelectRowsObject.get(key);
342
+ const row = map[key] || actionSetSelectRowsObject?.get?.(key);
332
343
  const canSelected = childFlag ? !relatedDisabledMap[row[currentRowKey]] : true;
333
344
  // 通过动作设置选中的禁用节点,允许选中
334
345
  // 通过动作设置选中父节点时,非禁用的子级数据也需要选中
@@ -336,15 +347,11 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
336
347
  keySet[key] = row;
337
348
  actionRows.push(row);
338
349
  if (row?.[childrenColumnName]?.length && !checkStrictly) {
339
- recursionDataSource<{ [k: string]: any }>(
340
- row[childrenColumnName],
341
- n => {
342
- if (n[currentRowKey]) {
343
- collectSelectedRow(n[currentRowKey], true);
344
- }
345
- },
346
- childrenColumnName
347
- );
350
+ recursionDataSource<{[k: string]: any}>(row[childrenColumnName], (n) => {
351
+ if (n[currentRowKey]) {
352
+ collectSelectedRow(n[currentRowKey], true);
353
+ }
354
+ }, childrenColumnName);
348
355
  }
349
356
  }
350
357
  }
@@ -365,38 +372,40 @@ const useSelection = <T extends { [key: string]: unknown }>(props: MyTableProps
365
372
  const newCurrentPageSelectedRowKeys = newCurrentPageSelectedRows.map((r: any) => r[currentRowKey]);
366
373
  setCurrentPageSelectedRows(newCurrentPageSelectedRows);
367
374
  setCurrentPageSelectedRowKeys(newCurrentPageSelectedRowKeys);
368
- }, [selectedRows, currentRowKey, currentPageDataSource]);
375
+ }, [
376
+ selectedRows,
377
+ currentRowKey,
378
+ currentPageDataSource,
379
+ ]);
369
380
 
370
381
  return {
371
- rowSelection: rowSelection
372
- ? {
373
- type: rowSelection.type,
374
- selectedRowKeys,
375
- checkStrictly,
376
- onChange: (_: any, sltrows: any[]) => handleSelect(sltrows),
377
- getCheckboxProps: (record: T) => {
378
- const props: ReturnType<Required<TableRowSelection<unknown>>['getCheckboxProps']> = {
379
- disabled: relatedDisabledMap[record[currentRowKey] as string],
380
- };
381
-
382
- /**
383
- * 决定可选表格某行是否可选
384
- * 由于此接口不支持索引 index 操作,所以 index 定位行逻辑放在 currentPageDisabledRows,以此兼容
385
- */
386
- const isRowSelectDisabled =
387
- handleIsRowSelectDisabled(record) || !!currentPageDisabledRows.find(row => row[currentRowKey] === record[currentRowKey]);
388
-
389
- if (isRowSelectDisabled || checkIfHiddenRow?.(record[currentRowKey])) {
390
- props.disabled = true;
391
- }
382
+ rowSelection: rowSelection ? {
383
+ type: rowSelection.type,
384
+ selectedRowKeys,
385
+ checkStrictly,
386
+ onChange: (_: any, sltrows: any[]) => handleSelect(sltrows),
387
+ getCheckboxProps: (record: T) => {
388
+ const props: ReturnType<Required<TableRowSelection<unknown>>['getCheckboxProps']> = {
389
+ disabled: relatedDisabledMap[record[currentRowKey] as string],
390
+ };
391
+
392
+ /**
393
+ * 决定可选表格某行是否可选
394
+ * 由于此接口不支持索引 index 操作,所以 index 定位行逻辑放在 currentPageDisabledRows,以此兼容
395
+ */
396
+ const isRowSelectDisabled = handleIsRowSelectDisabled(record) ||
397
+ !!currentPageDisabledRows.find(row => row[currentRowKey] === record[currentRowKey]);
398
+
399
+ if (isRowSelectDisabled || checkIfHiddenRow?.(record[currentRowKey])) {
400
+ props.disabled = true;
401
+ }
392
402
 
393
- // 开启checkLoosed模式时,父禁用子也禁用
394
- markDisable(record, props.disabled || false);
403
+ // 开启checkLoosed模式时,父禁用子也禁用
404
+ markDisable(record, props.disabled || false);
395
405
 
396
- return props;
397
- },
398
- }
399
- : undefined,
406
+ return props;
407
+ },
408
+ } : undefined,
400
409
  selectedRows,
401
410
  selectedRowKeys,
402
411
  currentPageSelectedRows,
@@ -1,18 +1,21 @@
1
- import _ from 'lodash';
2
1
  import { useMemo, useState } from 'react';
3
2
  import { compareFn } from '../utils';
3
+ import _ from 'lodash';
4
4
 
5
5
  const useSort = (props: any) => {
6
- const { innerDataSource, onSortChange } = props;
6
+ const {
7
+ innerDataSource,
8
+ onSortChange,
9
+ } = props;
7
10
 
8
11
  const hasSortEvent = typeof onSortChange === 'function'; // 是否配置表格排序事件
9
12
 
10
13
  // 开启了行合并后由前端进行排序
11
14
  const [sortOrder, setSortOrder] = useState<
12
15
  | {
13
- field: string;
14
- order?: string;
15
- }
16
+ field: string;
17
+ order?: string;
18
+ }
16
19
  | undefined
17
20
  >();
18
21
 
@@ -1,44 +1,36 @@
1
- import { TableColumnProps } from 'antd';
2
1
  import { useMemo } from 'react';
3
2
  import { SummaryConfig } from '../types/prop';
3
+ import { TableColumnProps } from 'antd';
4
4
 
5
5
  export type ColItem = {
6
6
 
7
7
  /**
8
8
  * 总结行类型 sub 合计
9
9
  */
10
- operateType: 'sub';
10
+ 'operateType': 'sub',
11
11
 
12
12
  /**
13
13
  * 总结行涉及列key集合
14
14
  */
15
- group: string[];
16
- };
15
+ 'group': string[]
16
+ }
17
17
 
18
- export type Column = {
19
- key?: string;
20
- dataIndex: string | string[];
21
- type?: 'orderCol' | 'dynamicCol';
18
+ export type Column = {key?: string; dataIndex: string | string[]; type?: 'orderCol' | 'dynamicCol';
22
19
 
23
20
  /**
24
21
  * 动态列原始key
25
22
  */
26
23
  dynamicOriginKey?: string;
27
24
  fixed?: TableColumnProps<any>['fixed'];
28
- align?: TableColumnProps<any>['align'];
29
- children?: Array<Column>;
30
- };
25
+ align?: TableColumnProps<any>['align'], children?: Array<Column>}
31
26
  export interface SummaryProps<T> {
32
- summaryConfig?: SummaryConfig;
27
+ summaryConfig?: SummaryConfig,
33
28
  readonly dataSource?: Array<T>;
34
29
  columns?: Array<Column>;
35
30
  }
36
- const useSummaryCol = <T>(props: SummaryProps<T>) => {
31
+ const useSummaryCol = <T, >(props: SummaryProps<T>) => {
37
32
  const { summaryConfig, dataSource, columns } = props;
38
- const { summaryType, summaryGroup } = useMemo<{
39
- summaryType: SummaryConfig['type'];
40
- summaryGroup: SummaryConfig['group'];
41
- }>(() => {
33
+ const { summaryType, summaryGroup } = useMemo<{summaryType: SummaryConfig['type'], summaryGroup:SummaryConfig['group']}>(() => {
42
34
  if (!summaryConfig) {
43
35
  return {
44
36
  summaryType: 'none',
@@ -57,7 +49,7 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
57
49
  const colList: typeof columns = [];
58
50
  const recursive = (arr: typeof columns) => {
59
51
  if (Array.isArray(arr)) {
60
- arr.forEach(c => {
52
+ arr.forEach((c) => {
61
53
  if (c?.children?.length) {
62
54
  recursive(c.children);
63
55
  } else {
@@ -71,13 +63,10 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
71
63
  }, [columns]);
72
64
 
73
65
  const summaryColIndexMap = useMemo(() => {
74
- const map = new Map<
75
- string,
76
- {
77
- index: number;
78
- operateType: ColItem['operateType'];
79
- }
80
- >();
66
+ const map = new Map<string, {
67
+ index: number,
68
+ operateType: ColItem['operateType']
69
+ }>();
81
70
  if (summaryType === 'none') {
82
71
  return map;
83
72
  }
@@ -102,18 +91,18 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
102
91
  const summaryColList = useMemo(() => {
103
92
  if (summaryColIndexMap.size === 0) return [];
104
93
  const col: Array<{
105
- title: string | number;
106
- colSpan?: number;
107
- dataIndexList?: string[];
108
- operateType?: ColItem['operateType'];
109
- type?: Column['type'];
94
+ title: string | number,
95
+ colSpan?: number,
96
+ dataIndexList?: string[],
97
+ operateType?: ColItem['operateType'],
98
+ type?: Column['type']
110
99
  prev?: {
111
100
  index: number;
112
101
  fixed?: TableColumnProps<T>['fixed'];
113
102
  };
114
- align?: TableColumnProps<T>['align'];
103
+ align?: TableColumnProps<T>['align']
115
104
  }> = [];
116
- // 标记当前已经记录的总结列
105
+ // 标记当前已经记录的总结列
117
106
  const currentSummaryColMap: Record<number, (typeof col)[number]> = {};
118
107
  fieldColumns?.forEach((c, i) => {
119
108
  const { key, dataIndex, dynamicOriginKey, type } = c;
@@ -139,11 +128,8 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
139
128
  const { index, operateType } = summaryCol;
140
129
  if (currentSummaryColMap[index]) {
141
130
  const prevItem = currentSummaryColMap[index];
142
- if (
143
- prevItem?.prev &&
144
- i === prevItem?.prev?.index + 1 &&
145
- prevItem?.prev?.fixed === c?.fixed &&
146
- !(summaryType === 'single' && type === 'dynamicCol' && type === prevItem?.type)
131
+ if (prevItem?.prev && i === prevItem?.prev?.index + 1 && prevItem?.prev?.fixed === c?.fixed
132
+ && !(summaryType === 'single' && type === 'dynamicCol' && type === prevItem?.type)
147
133
  ) {
148
134
  // 勾选列是相邻的,则允许合并
149
135
  // 单列合计时,需排除动态列情况
@@ -173,7 +159,7 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
173
159
  col.push(item);
174
160
  }
175
161
  });
176
- const dataMap: Record<string, any[]> = {};
162
+ const dataMap:Record<string, any[]> = {};
177
163
  const recursiveCollectValueByDataIndex = (row: Record<string, any>, keyPath: string[] = []) => {
178
164
  Object.keys(row || {}).forEach((key: string) => {
179
165
  const dataIndex = [...keyPath, key];
@@ -189,10 +175,10 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
189
175
  });
190
176
  };
191
177
  // 收集每个dataIndex
192
- dataSource?.forEach(v => {
178
+ dataSource?.forEach((v) => {
193
179
  recursiveCollectValueByDataIndex(v as Record<string, any>);
194
180
  });
195
- return col.map(c => {
181
+ return col.map((c) => {
196
182
  const { operateType, dataIndexList = [] } = c;
197
183
  const item = {
198
184
  ...c,
@@ -207,9 +193,7 @@ const useSummaryCol = <T>(props: SummaryProps<T>) => {
207
193
  // 转换失败不合计
208
194
  return NaN;
209
195
  }
210
- data.forEach(v => {
211
- val += Number(v);
212
- });
196
+ data.forEach((v) => { val += Number(v); });
213
197
  return val;
214
198
  }, 0);
215
199
  item.title = isNaN(sub) ? '' : sub.toFixed(summaryConfig?.decimal || 0);