@bit-sun/business-component 2.2.2 → 2.2.3

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 (176) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/index.esm.js +4 -4
  9. package/dist/index.js +4 -4
  10. package/docs/index.md +21 -21
  11. package/lib/assets/drag.svg +17 -17
  12. package/lib/assets/exportFail.svg +37 -37
  13. package/lib/assets/exportProcessing.svg +28 -28
  14. package/lib/assets/exportSuccess.svg +34 -34
  15. package/lib/assets/label_icon_bottom.svg +25 -25
  16. package/lib/assets/upExport.svg +22 -22
  17. package/package.json +77 -77
  18. package/src/assets/32.svg +27 -27
  19. package/src/assets/addIcon.svg +17 -17
  20. package/src/assets/allfunc.svg +27 -27
  21. package/src/assets/arrowRight.svg +24 -24
  22. package/src/assets/btn-delete.svg +29 -29
  23. package/src/assets/btn-edit.svg +19 -19
  24. package/src/assets/btn-more.svg +17 -17
  25. package/src/assets/btn-submit.svg +19 -19
  26. package/src/assets/caidan.svg +11 -11
  27. package/src/assets/close.svg +26 -26
  28. package/src/assets/drag.svg +17 -17
  29. package/src/assets/exportFail.svg +37 -37
  30. package/src/assets/exportProcessing.svg +28 -28
  31. package/src/assets/exportSuccess.svg +34 -34
  32. package/src/assets/fixed-left-active.svg +11 -11
  33. package/src/assets/fixed-left.svg +15 -15
  34. package/src/assets/fixed-right-active.svg +11 -11
  35. package/src/assets/fixed-right.svg +15 -15
  36. package/src/assets/guanbi.svg +15 -15
  37. package/src/assets/icon-quanping.svg +15 -15
  38. package/src/assets/icon-shezhi.svg +17 -17
  39. package/src/assets/label_icon_bottom.svg +25 -25
  40. package/src/assets/list-no-img.svg +21 -21
  41. package/src/assets/morentouxiang-32.svg +23 -23
  42. package/src/assets/scanning.svg +24 -24
  43. package/src/assets/upExport.svg +22 -22
  44. package/src/components/Business/AddSelectBusiness/index.md +63 -63
  45. package/src/components/Business/AddSelectBusiness/index.tsx +344 -344
  46. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  47. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  48. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  49. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  50. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  51. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  52. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  53. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  54. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  55. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  58. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  59. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  60. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  61. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  62. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +156 -156
  63. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  64. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  65. package/src/components/Business/BsLayouts/index.less +79 -79
  66. package/src/components/Business/BsLayouts/index.tsx +1479 -1479
  67. package/src/components/Business/BsLayouts/service.ts +10 -10
  68. package/src/components/Business/BsLayouts/utils.tsx +230 -230
  69. package/src/components/Business/BsSulaQueryTable/index.less +219 -219
  70. package/src/components/Business/BsSulaQueryTable/index.tsx +480 -480
  71. package/src/components/Business/BsSulaQueryTable/setting.tsx +802 -802
  72. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  73. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  74. package/src/components/Business/CommodityEntry/index.md +70 -70
  75. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  76. package/src/components/Business/CommonAlert/index.tsx +23 -23
  77. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  78. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  79. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  80. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  81. package/src/components/Business/DetailPageWrapper/index.tsx +335 -335
  82. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  83. package/src/components/Business/HomePageWrapper/index.less +33 -33
  84. package/src/components/Business/HomePageWrapper/index.md +45 -45
  85. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  86. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  87. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +201 -201
  88. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  89. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  90. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  91. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  92. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  93. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  94. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  95. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  96. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  97. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  98. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  99. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  100. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  101. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  102. package/src/components/Business/JsonQueryTable/index.less +16 -16
  103. package/src/components/Business/JsonQueryTable/index.md +328 -328
  104. package/src/components/Business/JsonQueryTable/index.tsx +320 -320
  105. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  106. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  107. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  108. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  109. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  110. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  111. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  112. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  113. package/src/components/Business/JsonQueryTable/static.ts +356 -356
  114. package/src/components/Business/SearchSelect/BusinessUtils.ts +1586 -1586
  115. package/src/components/Business/SearchSelect/common.ts +53 -53
  116. package/src/components/Business/SearchSelect/index.md +1254 -1254
  117. package/src/components/Business/SearchSelect/index.tsx +51 -51
  118. package/src/components/Business/SearchSelect/utils.ts +100 -100
  119. package/src/components/Business/StateFlow/index.less +130 -130
  120. package/src/components/Business/StateFlow/index.md +60 -60
  121. package/src/components/Business/StateFlow/index.tsx +29 -29
  122. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  123. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  124. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  125. package/src/components/Business/columnSettingTable/columnSetting.tsx +764 -764
  126. package/src/components/Business/columnSettingTable/index.less +247 -247
  127. package/src/components/Business/columnSettingTable/index.md +357 -357
  128. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  129. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  130. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  131. package/src/components/Business/moreTreeTable/index.less +99 -99
  132. package/src/components/Business/moreTreeTable/index.md +508 -508
  133. package/src/components/Business/moreTreeTable/index.tsx +315 -315
  134. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  135. package/src/components/Functional/AddSelect/index.less +367 -367
  136. package/src/components/Functional/AddSelect/index.md +155 -155
  137. package/src/components/Functional/AddSelect/index.tsx +1072 -1072
  138. package/src/components/Functional/BillEntry/index.less +371 -371
  139. package/src/components/Functional/BillEntry/index.md +39 -39
  140. package/src/components/Functional/BillEntry/index.tsx +766 -766
  141. package/src/components/Functional/DataImport/index.less +63 -63
  142. package/src/components/Functional/DataImport/index.md +44 -44
  143. package/src/components/Functional/DataImport/index.tsx +695 -695
  144. package/src/components/Functional/DataValidation/index.less +63 -63
  145. package/src/components/Functional/DataValidation/index.md +39 -39
  146. package/src/components/Functional/DataValidation/index.tsx +687 -687
  147. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  148. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  149. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  150. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  151. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  152. package/src/components/Functional/SearchSelect/index.less +115 -115
  153. package/src/components/Functional/SearchSelect/index.md +141 -141
  154. package/src/components/Functional/SearchSelect/index.tsx +813 -813
  155. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  156. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  157. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  158. package/src/index.ts +34 -34
  159. package/src/plugin/TableColumnSetting/index.less +247 -247
  160. package/src/plugin/TableColumnSetting/index.md +50 -50
  161. package/src/plugin/TableColumnSetting/index.tsx +724 -724
  162. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  163. package/src/styles/bsDefault.less +1906 -1906
  164. package/src/utils/CheckOneUser/index.md +39 -39
  165. package/src/utils/CheckOneUser/index.ts +51 -51
  166. package/src/utils/LocalstorageUtils.ts +33 -33
  167. package/src/utils/TableUtils.tsx +18 -18
  168. package/src/utils/checkUtils.ts +39 -39
  169. package/src/utils/enumConfig.ts +10 -10
  170. package/src/utils/getFormMode.js +12 -12
  171. package/src/utils/index.ts +2 -2
  172. package/src/utils/requestUtils.ts +33 -33
  173. package/src/utils/serialize.js +7 -7
  174. package/src/utils/utils.ts +183 -183
  175. package/tsconfig.json +29 -29
  176. package/typings.d.ts +4 -4
@@ -1,1479 +1,1479 @@
1
- // @ts-nocheck
2
- import type {
3
- MenuDataItem,
4
- BasicLayoutProps as ProLayoutProps,
5
- Settings,
6
- } from '@ant-design/pro-layout';
7
- import ProLayout from '@ant-design/pro-layout';
8
- import React, { useState, createRef, useRef } from 'react';
9
- import {
10
- Tabs,
11
- Dropdown,
12
- Menu,
13
- } from 'antd';
14
- import {
15
- Link,
16
- useIntl,
17
- history,
18
- useModel,
19
- } from 'umi';
20
- import {
21
- DashOutlined,
22
- MenuUnfoldOutlined,
23
- CaretLeftOutlined,
24
- HomeOutlined,
25
- DoubleLeftOutlined,
26
- DoubleRightOutlined,
27
- } from '@ant-design/icons';
28
- import SearchFunc from './Components/SearchFunc';
29
- import { debounce } from 'lodash';
30
-
31
- import AllFunc from './Components/AllFunc';
32
- import {
33
- getBreadcrumbNameMap,
34
- ergodicMenuRoutes,
35
- matchPath,
36
- encodeUrlQuery,
37
- } from './utils';
38
- import moment from 'moment';
39
- import GlobalHeaderCom from './Components/GlobalHeader';
40
- import CustomerMenu from './Components/CustomerMenu';
41
- import CustomerMenuHeader from './Components/CustomerMenu/globalMenu/customMenuHeader';
42
- import './index.less';
43
- import { DndProvider, useDrag, useDrop } from 'react-dnd';
44
- import { HTML5Backend } from 'react-dnd-html5-backend';
45
- import ENUM from '@/utils/enumConfig';
46
- import { memoizeOneFormatter } from '@/utils/utils';
47
-
48
- const { TabPane } = Tabs;
49
-
50
- export const RouterContext = React.createContext({});
51
-
52
- export type BasicLayoutProps = {
53
- breadcrumbNameMap: Record<string, MenuDataItem>;
54
- route: ProLayoutProps['route'] & {
55
- authority: string[];
56
- };
57
- settings: Settings;
58
- } & ProLayoutProps;
59
-
60
- export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
61
- breadcrumbNameMap: Record<string, MenuDataItem>;
62
- };
63
-
64
- const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
65
- menuList.map((item) => {
66
- return {
67
- ...item,
68
- children: item.children ? menuDataRender(item.children) : undefined,
69
- };
70
- });
71
-
72
- let UN_LISTTEN_DRP;
73
- let routerArray = [];
74
- let lastTwoRouterArray = [1, 2];
75
-
76
- let draggerTabKeys = [];
77
-
78
- const type = 'DraggableTabNode';
79
- const DraggableTabNode = ({ index, children, moveNode }) => {
80
- const ref = useRef(null);
81
- const [{ isOver, dropClassName }, drop] = useDrop({
82
- accept: type,
83
- collect: (monitor) => {
84
- const { index: dragIndex } = monitor.getItem() || {};
85
-
86
- if (dragIndex === index) {
87
- return {};
88
- }
89
-
90
- return {
91
- isOver: monitor.isOver(),
92
- dropClassName: 'dropping',
93
- };
94
- },
95
- drop: (item) => {
96
- moveNode(item.index, index);
97
- },
98
- });
99
- const [, drag] = useDrag({
100
- type,
101
- item: {
102
- index,
103
- },
104
- collect: (monitor) => ({
105
- isDragging: monitor.isDragging(),
106
- }),
107
- });
108
- drop(drag(ref));
109
- return (
110
- <div
111
- ref={ref}
112
- style={{
113
- marginRight: 24,
114
- }}
115
- className={isOver ? dropClassName : ''}
116
- >
117
- {children}
118
- </div>
119
- );
120
- };
121
-
122
- const DraggableTabs = (props) => {
123
- const { children, changeListenRouterState } = props;
124
- const [order, setOrder] = useState([]);
125
-
126
- const moveTabNode = (dragKey, hoverKey) => {
127
- const newOrder = order.slice();
128
- React.Children.forEach(children, (c) => {
129
- if (c.key && newOrder.indexOf(c.key) === -1) {
130
- newOrder.push(c.key);
131
- }
132
- });
133
- const dragIndex = newOrder.indexOf(dragKey);
134
- const hoverIndex = newOrder.indexOf(hoverKey);
135
- newOrder.splice(dragIndex, 1);
136
- newOrder.splice(hoverIndex, 0, dragKey);
137
- changeListenRouterState(dragIndex, hoverIndex);
138
- setOrder(newOrder);
139
- };
140
-
141
- const renderTabBar = (tabBarProps, DefaultTabBar) => (
142
- <DefaultTabBar {...tabBarProps}>
143
- {(node) => (
144
- <DraggableTabNode
145
- key={node.key}
146
- index={node.key}
147
- moveNode={moveTabNode}
148
- >
149
- {node}
150
- </DraggableTabNode>
151
- )}
152
- </DefaultTabBar>
153
- );
154
-
155
- const tabs = [];
156
- React.Children.forEach(children, (c) => {
157
- tabs.push(c);
158
- });
159
- const orderTabs = tabs.slice().sort((a, b) => {
160
- const orderA = order.indexOf(a.key);
161
- const orderB = order.indexOf(b.key);
162
-
163
- if (orderA !== -1 && orderB !== -1) {
164
- return orderA - orderB;
165
- }
166
-
167
- if (orderA !== -1) {
168
- return -1;
169
- }
170
-
171
- if (orderB !== -1) {
172
- return 1;
173
- }
174
-
175
- const ia = tabs.indexOf(a);
176
- const ib = tabs.indexOf(b);
177
- return ia - ib;
178
- });
179
- return (
180
- <DndProvider backend={HTML5Backend}>
181
- <Tabs renderTabBar={renderTabBar} {...props}>
182
- {orderTabs}
183
- </Tabs>
184
- </DndProvider>
185
- );
186
- };
187
-
188
- const ItemMenu = (props) => {
189
- const {
190
- info: { key },
191
- operateFun,
192
- listenRouterState,
193
- } = props;
194
- let index = listenRouterState.findIndex((item) => item.key === key);
195
-
196
- const menu = (
197
- <Menu>
198
- <Menu.Item key="0" style={{ fontSize: '12px', textAlign: 'center' }}>
199
- <a
200
- onClick={(e) => {
201
- e.stopPropagation();
202
- operateFun(key, 'self');
203
- }}
204
- >
205
- 关闭当前标签
206
- </a>
207
- </Menu.Item>
208
- <Menu.Item
209
- disabled={index === 0}
210
- key="1"
211
- style={{ fontSize: '12px', textAlign: 'center' }}
212
- >
213
- <a
214
- onClick={(e) => {
215
- e.stopPropagation();
216
- operateFun(key, 'left');
217
- }}
218
- >
219
- 关闭其左侧标签
220
- </a>
221
- </Menu.Item>
222
- <Menu.Item
223
- disabled={index === listenRouterState.length - 1}
224
- key="2"
225
- style={{ fontSize: '12px', textAlign: 'center' }}
226
- >
227
- <a
228
- onClick={(e) => {
229
- e.stopPropagation();
230
- operateFun(key, 'right');
231
- }}
232
- >
233
- 关闭其右侧标签
234
- </a>
235
- </Menu.Item>
236
- <Menu.Item
237
- disabled={index === listenRouterState.length - 1}
238
- key="3"
239
- style={{ fontSize: '12px', textAlign: 'center' }}
240
- >
241
- <a
242
- onClick={(e) => {
243
- e.stopPropagation();
244
- operateFun(key, 'other');
245
- }}
246
- >
247
- 关闭其他标签
248
- </a>
249
- </Menu.Item>
250
- <Menu.Item
251
- disabled={index === listenRouterState.length - 1}
252
- key="4"
253
- style={{ fontSize: '12px', textAlign: 'center' }}
254
- >
255
- <a
256
- onClick={(e) => {
257
- e.stopPropagation();
258
- operateFun(key, 'all');
259
- }}
260
- >
261
- 关闭全部标签
262
- </a>
263
- </Menu.Item>
264
- </Menu>
265
- );
266
- return (
267
- <Dropdown overlay={menu} trigger={['hover']}>
268
- <a
269
- className="ant-dropdown-link"
270
- onClick={(e) => {
271
- e.preventDefault();
272
- e.stopPropagation();
273
- }}
274
- >
275
- <img style={{ marginRight: '-12px' }} src="./biaoqian-icon.svg" />
276
- </a>
277
- </Dropdown>
278
- );
279
- };
280
-
281
- class BasicLayout extends React.PureComponent {
282
- allFunc: any = createRef('');
283
- customerMenuRef: any = createRef('');
284
- actionRef: any = createRef<{
285
- reload: () => void;
286
- }>();
287
- constructor(props) {
288
- super(props);
289
- routerArray = this.updateTree(props.route.routes);
290
- const homeRouter = routerArray.filter(
291
- (itemroute) => itemroute.key === '/',
292
- )[0];
293
- const breadcrumbNameMap = getBreadcrumbNameMap(
294
- memoizeOneFormatter(props.route.routes, ''),
295
- );
296
- const hideMenuArray = ergodicMenuRoutes(props.route.routes);
297
-
298
- this.state = {
299
- listenRouterState: [
300
- { ...homeRouter, key: '/', tab: '欢迎', closable: false },
301
- ],
302
- listenRouterKey: ['/'],
303
- activeKey: '/',
304
- homeRouter,
305
- customerMatchs: [],
306
- breadcrumbNameMap,
307
- hideMenuArray,
308
- keyWord: '',
309
- collapse: false,
310
- drawerLeftParams: {
311
- visible: false,
312
- width: 690,
313
- title: '搜索',
314
- onClose: () => {
315
- this.setState({
316
- drawerLeftParams: {
317
- ...this.state.drawerLeftParams,
318
- visible: false,
319
- },
320
- });
321
- },
322
- },
323
- currentSubMenuData: [],
324
- showSubMenu: false,
325
- isSlider: false,
326
- };
327
- }
328
-
329
- componentDidMount() {
330
- const {
331
- history,
332
- location,
333
- itemPath,
334
- pathToRegexp,
335
- } = this.props;
336
-
337
- let istParent = 0;
338
-
339
- var self = this;
340
-
341
- window.top != window &&
342
- window.addEventListener('message', function (e) {
343
- istParent = 1;
344
- if (localStorage.getItem(ENUM.BROWSER_CACHE.CHILD_APP_BACK)) {
345
- localStorage.removeItem(ENUM.BROWSER_CACHE.CHILD_APP_BACK);
346
- } else {
347
- localStorage.setItem('isTabChange', true);
348
- }
349
-
350
- if (typeof e.data === 'string') {
351
- let newKey = encodeUrlQuery(e.data.replace(/^\/\w+\//, '/'));
352
- history.push(newKey);
353
- } else {
354
- const info = e.data;
355
- if (info.type === 'remove') {
356
- self.tabActions['remove'](info.key.replace(/^\/\w+\//, '/'));
357
- }
358
- }
359
- });
360
-
361
- UN_LISTTEN_DRP = history.listen((route) => {
362
- if ((window as any).__POWERED_BY_QIANKUN__) {
363
- if (window.location.href.indexOf(`/${itemPath}`) === -1) return;
364
- }
365
- const {
366
- listenRouterState,
367
- listenRouterKey,
368
- customerMatchs,
369
- hideMenuArray,
370
- } = this.state;
371
- let newListenRouterState = [...listenRouterState];
372
- let newListenRouterKey = [...listenRouterKey];
373
-
374
- let replaceRouter = routerArray.filter((itemRoute) =>
375
- pathToRegexp(itemRoute.key || '').test(route.pathname),
376
- )[0];
377
-
378
- if (!istParent) {
379
- if (route.pathname === '/') return;
380
- window.parent.postMessage(`/parent/${itemPath}${route.pathname}`, '*');
381
- }
382
-
383
- let currentKey = '';
384
-
385
- if (replaceRouter && replaceRouter.isOnlyOnePage) {
386
- // 处理中英文和特殊字符
387
- currentKey = decodeURIComponent(route.pathname);
388
- } else {
389
- currentKey = decodeURIComponent(
390
- route.pathname + this.parseQueryString(route.search),
391
- );
392
- }
393
-
394
- // 防止出错
395
- if (listenRouterKey.length !== listenRouterState.length) {
396
- listenRouterState.forEach((item, index) => {
397
- listenRouterKey[index] = item.key;
398
- });
399
- }
400
-
401
- if (!listenRouterKey.includes(currentKey)) {
402
- if (!replaceRouter) {
403
- replaceRouter = routerArray.filter(
404
- (itemroute) => itemroute.key === '/404',
405
- )?.[0];
406
-
407
- this.setState(
408
- {
409
- listenRouterState: [
410
- ...listenRouterState,
411
- { ...replaceRouter, key: currentKey, tab: '404' },
412
- ],
413
- activeKey: currentKey,
414
- listenRouterKey: [...listenRouterKey, currentKey],
415
- },
416
- () => {
417
- this.checkisNavSlide();
418
- },
419
- );
420
- } else {
421
- const match = matchPath(route.pathname, { path: replaceRouter.key }, pathToRegexp);
422
- newListenRouterState = [
423
- ...newListenRouterState,
424
- {
425
- ...replaceRouter,
426
- query: route.query,
427
- match: match,
428
- key: currentKey,
429
- tab: this.getPageTitle(route.pathname) + '',
430
- },
431
- ];
432
- newListenRouterKey = [...listenRouterKey, currentKey];
433
- }
434
- }
435
-
436
- // 处理hideMenu页面自动关闭
437
- lastTwoRouterArray.push(route.pathname);
438
- lastTwoRouterArray.shift();
439
- if (
440
- !localStorage.getItem('isTabChange') &&
441
- !localStorage.getItem('isMenuClick')
442
- ) {
443
- if (
444
- lastTwoRouterArray[0] &&
445
- typeof lastTwoRouterArray[0] === 'string'
446
- ) {
447
- let needRemoveKeyArray = hideMenuArray.filter((itemRoute) =>
448
- pathToRegexp(itemRoute.path || '').test(lastTwoRouterArray[0]),
449
- );
450
- // lastTwoRouterArray[0] != lastTwoRouterArray[1] 该判断条件用于判断是否是tab删除操作,如果是tab页删除操作,删除的是不是最后一个打开的tab页,执行history.push会导致错误的将最后打开的那个tab页也删除掉
451
- if (
452
- needRemoveKeyArray.length &&
453
- lastTwoRouterArray[0] != lastTwoRouterArray[1]
454
- ) {
455
- if (
456
- (!(
457
- lastTwoRouterArray[0].indexOf('/order/mainOrder/supplement') >=
458
- 0
459
- ) ||
460
- !pathToRegexp(
461
- '/order/mainOrder/:parmode/separateOrder/:id',
462
- ).test(lastTwoRouterArray[1])) &&
463
- (!pathToRegexp(
464
- '/order/mainOrder/:parmode/separateOrder/:id',
465
- ).test(lastTwoRouterArray[0]) ||
466
- !(
467
- lastTwoRouterArray[1].indexOf(
468
- 'order/mainOrder/separateOrder/',
469
- ) >= 0
470
- ))
471
- ) {
472
- if (!route.state?.thisHideInMenuDoNotClose) {
473
- newListenRouterState = newListenRouterState.filter((item) => {
474
- const [pathname] = item.key ? item.key.split('?') : [];
475
- return pathname && pathname !== lastTwoRouterArray[0];
476
- });
477
- newListenRouterKey = newListenRouterKey.filter((item) => {
478
- const [pathname] = item ? item.split('?') : [];
479
- return pathname && pathname !== lastTwoRouterArray[0];
480
- });
481
- }
482
- }
483
- }
484
- }
485
- // refs?.tableRef?.current?.refreshTable();
486
- } else {
487
- setTimeout(() => {
488
- // 处理页面刷新两面
489
- localStorage.removeItem('isTabChange');
490
- localStorage.removeItem('isMenuClick');
491
- }, 0);
492
- }
493
- this.setState(
494
- {
495
- //路由监听函数最后执行setState,避免处理hideMenu类型页面自动关闭的逻辑块内获取不到最新state的listenRouterState和listenRouterKey
496
- activeKey: currentKey,
497
- listenRouterState: newListenRouterState,
498
- listenRouterKey: newListenRouterKey,
499
- },
500
- () => {
501
- this.checkisNavSlide();
502
- },
503
- );
504
-
505
- istParent = 0;
506
- });
507
-
508
- if (
509
- localStorage.getItem('firstPage') &&
510
- localStorage.getItem('firstPage')?.startsWith(`#/${itemPath}/`)
511
- ) {
512
- istParent = 1;
513
- history.push(
514
- localStorage
515
- .getItem('firstPage')
516
- ?.slice(1)
517
- .replace(/^\/\w+\//, '/'),
518
- );
519
- } else {
520
- history.push(location);
521
- }
522
- }
523
-
524
- componentWillUnmount() {
525
- // eslint-disable-next-line no-unused-expressions
526
- UN_LISTTEN_DRP && UN_LISTTEN_DRP();
527
- }
528
-
529
- parseQueryString = (queryString) => {
530
- if (!queryString) {
531
- return '';
532
- }
533
-
534
- if (queryString.indexOf('?') < 0) {
535
- return `?${queryString}`;
536
- }
537
-
538
- return queryString;
539
- };
540
-
541
- updateTree = (Tree) => {
542
- const treeData = Tree;
543
- const treeList = [];
544
- // 递归获取树列表
545
- const getTreeList = (data) => {
546
- data.forEach((node) => {
547
- if (node.routes && node.routes.length > 0) {
548
- getTreeList(node.routes);
549
- } else {
550
- treeList.push({
551
- tab: node.locale,
552
- key: node.path,
553
- locale: node.locale,
554
- closable: true,
555
- content: node.component,
556
- name: node.name,
557
- hideInMenu: node.hideInMenu,
558
- isOnlyOnePage: node.isOnlyOnePage,
559
- });
560
- }
561
- });
562
- };
563
- getTreeList(treeData);
564
- return treeList;
565
- };
566
-
567
- getDictionarySource = (dicCode: string, needConvertInterger = false) => {
568
- const { dictionaryData } = this.props;
569
-
570
- let dicData = {};
571
-
572
- if (!dictionaryData) {
573
- let storageDic = localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES)
574
- ? JSON.parse(localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES))
575
- : {};
576
- dicData = storageDic[dicCode];
577
- } else {
578
- dicData = dictionaryData[dicCode];
579
- }
580
- // if (!dicData || !dicData.length) {
581
- // throw new Error(`当前没有${dicCode}字典值`);
582
- // }
583
-
584
- try {
585
- if (needConvertInterger) {
586
- dicData = dicData.map((item: { text: string; value: string }) => ({
587
- ...item,
588
- value: parseFloat(item.value),
589
- }));
590
- }
591
- } catch (e) { }
592
-
593
- return dicData;
594
- };
595
-
596
- getDictionaryTextByValue = (dicCode: string, value: string) => {
597
- let dicData = [];
598
- let dictionaryData: any;
599
- if (!dictionaryData) {
600
- let storageDic = localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES)
601
- ? JSON.parse(localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES))
602
- : {};
603
- dicData = storageDic[dicCode];
604
- } else {
605
- dicData = dictionaryData[dicCode];
606
- }
607
-
608
- if (!dicData || !dicData.length) {
609
- // throw new Error(`当前没有${dicCode}字典值`);
610
- }
611
-
612
- if (value === undefined) return '- -';
613
-
614
- const dicItemArray = dicData?.filter(
615
- (item: { value: string }) => item.value === value.toString(),
616
- );
617
-
618
- if (!dicItemArray?.length) {
619
- // throw new Error(`当前${dicCode}字典值合没有${value}的数据`)
620
- return value;
621
- }
622
-
623
- return dicItemArray[0].text;
624
- };
625
-
626
- timeFormat = (timeStr, format, notNeedConvertTimeZone) => {
627
- if (!timeStr) return '- -';
628
-
629
- if (notNeedConvertTimeZone) {
630
- return moment(timeStr).format(format);
631
- }
632
-
633
- return moment(timeStr).add(8, 'hours').format(format) || '- -';
634
- };
635
-
636
- onChange = (key) => {
637
- // console.log('onChange');
638
- if (key !== this.state.activeKey) {
639
- this.setState({
640
- activeKey: key,
641
- });
642
- localStorage.setItem('isTabChange', '1');
643
- let newKey = encodeUrlQuery(key);
644
- history.push(newKey);
645
- }
646
- };
647
-
648
- getPageTitle = (pathname) => {
649
- const { formatMessage } = this.props;
650
- const { breadcrumbNameMap } = this.state;
651
- const currRouterData = this.matchParamsPath(pathname, breadcrumbNameMap);
652
-
653
- if (!currRouterData) {
654
- return '';
655
- }
656
- const pageName = formatMessage({
657
- id: currRouterData.locale || currRouterData.name,
658
- defaultMessage: currRouterData.name,
659
- });
660
-
661
- return `${pageName}`;
662
- };
663
-
664
- matchParamsPath = (pathname, breadcrumbNameMap) => {
665
- const { pathToRegexp } = this.props;
666
- const pathKey = Object.keys(breadcrumbNameMap).find((key) =>
667
- pathToRegexp(key).test(pathname),
668
- );
669
- return breadcrumbNameMap[pathKey];
670
- };
671
-
672
- onEdit = (
673
- targetKey: React.MouseEvent | React.KeyboardEvent | string,
674
- action: string,
675
- ) => {
676
- this.tabActions[action](targetKey);
677
- };
678
-
679
- tabActions: any = {
680
- remove: (targetKey: string) => {
681
- const { listenRouterState, activeKey, customerMatchs, listenRouterKey } =
682
- this.state;
683
-
684
- let lastIndex: number = 0;
685
- let newActiveKey: string | undefined = activeKey;
686
- let newListenRouterState = [];
687
- let newListenRouterKey = [];
688
-
689
- if (targetKey === activeKey) {
690
- listenRouterState.forEach((pane, i) => {
691
- if (pane.key === targetKey) {
692
- lastIndex = i - 1;
693
- }
694
- });
695
-
696
- newListenRouterState = listenRouterState.filter(
697
- (item) => item.key !== targetKey,
698
- );
699
- newListenRouterKey = listenRouterKey.filter(
700
- (item) => item !== targetKey,
701
- );
702
-
703
- if (lastIndex < 0) {
704
- lastIndex = 0;
705
- }
706
-
707
- newActiveKey = newListenRouterState[lastIndex].key;
708
- } else {
709
- newListenRouterState = listenRouterState.filter(
710
- (item) => item.key !== targetKey,
711
- );
712
- newListenRouterKey = listenRouterKey.filter(
713
- (item) => item !== targetKey,
714
- );
715
- }
716
-
717
- this.setState(
718
- {
719
- activeKey: newActiveKey,
720
- listenRouterState: newListenRouterState,
721
- listenRouterKey: newListenRouterKey,
722
- },
723
- () => {
724
- let newKey = encodeUrlQuery(newActiveKey);
725
- history.push({
726
- pathname: newKey,
727
- });
728
- this.checkisNavSlide();
729
- },
730
- );
731
- },
732
- };
733
-
734
- updateState = (newListenRouterState, newListenRouterKey, cb) => {
735
- this.setState(
736
- {
737
- listenRouterState: newListenRouterState,
738
- listenRouterKey: newListenRouterKey,
739
- },
740
- () => {
741
- this.checkisNavSlide();
742
- if (cb) cb();
743
- },
744
- );
745
- };
746
-
747
- handleClose = () => {
748
- this.setState({
749
- drawerLeftParams: {
750
- ...this.state.drawerLeftParams,
751
- visible: false,
752
- },
753
- isCollapse: true,
754
- });
755
- this.allFunc.current?.close?.();
756
- this.customerMenuRef.current?.close?.();
757
- };
758
-
759
- handleMenuClick = (item: any) => {
760
- if (item.children || !item.component) return;
761
- let newKey = encodeUrlQuery(item.path);
762
- history.push({
763
- pathname: newKey,
764
- });
765
- this.setShowMenu(false);
766
- };
767
-
768
- getMenuDom = (menuData) => {
769
- return menuData.map((item) => (
770
- <div>
771
- <div
772
- onClick={() => {
773
- this.handleMenuClick(item);
774
- }}
775
- className={`${'menu_item'} ${item.children || !item.component ? '' : 'link_style'
776
- }`}
777
- style={{
778
- fontWeight: item.children || !item.component ? 'bolder' : '400',
779
- paddingLeft: '10px',
780
- marginTop: item.children || !item.component ? '5px' : '0px',
781
- fontSize: item.children || !item.component ? '14px' : '12px',
782
- }}
783
- >
784
- {item.name}
785
- </div>
786
- {!!item.children &&
787
- !!item.children.length &&
788
- this.getMenuDom(item.children)}
789
- </div>
790
- ));
791
- };
792
-
793
- setShowMenu = debounce((isShow) => {
794
- this.setState({
795
- showSubMenu: isShow,
796
- });
797
- }, 500);
798
-
799
- //设置tabs标签左右滚动
800
- setTabNavTransLate = (num) => {
801
- let globalTabsNav = document
802
- .getElementById('globalTabs')
803
- ?.getElementsByClassName('ant-tabs-nav-list')?.[0];
804
- let globalTabsNavWrap = document
805
- .getElementById('globalTabs')
806
- ?.getElementsByClassName('ant-tabs-nav-wrap')?.[0];
807
- let wrapWidth = globalTabsNavWrap.offsetWidth; //tabsNav父节点宽度
808
- let navListWidth = globalTabsNav.offsetWidth; //tabsNav总宽度
809
- if (navListWidth - wrapWidth <= 0) return;
810
- let maxTransX = navListWidth - wrapWidth; // 允许移动最大宽度
811
- let transXStr = document.defaultView?.getComputedStyle(
812
- globalTabsNav,
813
- null,
814
- ).transform;
815
- let transx = transXStr?.split(',')[4]; //当前translateX的值
816
-
817
- let targetTransX = Math.abs(Number(transx)) + num;
818
- if (targetTransX <= 0) targetTransX = 0;
819
- if (targetTransX >= Number(maxTransX)) targetTransX = Number(maxTransX);
820
- globalTabsNav.style.transform = 'translateX(-' + targetTransX + 'px)';
821
- };
822
-
823
- checkisNavSlide = () => {
824
- if (window.top != window) return;
825
- //监听tabs页签总长度判断是否可点击滑动
826
- let globalTabsNav = document
827
- .getElementById('globalTabs')
828
- ?.getElementsByClassName('ant-tabs-nav-list')?.[0];
829
- let globalTabsNavWrap = document
830
- .getElementById('globalTabs')
831
- ?.getElementsByClassName('ant-tabs-nav-wrap')?.[0];
832
- let wrapWidth = globalTabsNavWrap?.offsetWidth; //tabsNav父节点宽度
833
- let navListWidth = globalTabsNav?.offsetWidth; //tabsNav总宽度
834
- if (navListWidth - wrapWidth <= 0) {
835
- this.setState({
836
- isSlider: false,
837
- });
838
- return;
839
- }
840
- this.setState({
841
- isSlider: true,
842
- });
843
- };
844
-
845
- changeListenRouterState = (dragIndex: number, hoverIndex: number) => {
846
- const { listenRouterState, listenRouterKey } = this.state;
847
- let dragItem = listenRouterState[dragIndex];
848
- let dragKeyItem = listenRouterKey[dragIndex];
849
-
850
- listenRouterState.splice(dragIndex, 1);
851
- listenRouterState.splice(hoverIndex, 0, dragItem);
852
-
853
- listenRouterKey.splice(dragIndex, 1);
854
- listenRouterKey.splice(hoverIndex, 0, dragKeyItem);
855
- };
856
-
857
- operateFun = (key, type) => {
858
- const { listenRouterState, activeKey, listenRouterKey } = this.state;
859
- let deleteKey = '';
860
- let newlistenRouterState = [];
861
- let newlistenRouterKey = [];
862
- let newActiveKey = '';
863
- let deleteIndex = 0;
864
- if (type === 'self') {
865
- deleteIndex = listenRouterState.findIndex((item) => item.key === key);
866
- deleteKey = key;
867
- if (deleteIndex > 0) {
868
- newActiveKey = listenRouterState[deleteIndex - 1].key;
869
- } else {
870
- newActiveKey = listenRouterState[1].key;
871
- }
872
- newlistenRouterState = listenRouterState.filter((d) => d.key !== key);
873
- newlistenRouterKey = listenRouterKey.filter((d) => d !== key);
874
- this.updateState(newlistenRouterState, newlistenRouterKey, () => {
875
- if (deleteKey === activeKey) {
876
- let newKey = encodeUrlQuery(newActiveKey);
877
- history.push({
878
- pathname: newKey,
879
- });
880
- }
881
- });
882
- }
883
- if (type === 'left') {
884
- const index = listenRouterState.findIndex((item) => item.key === key);
885
- newlistenRouterState = listenRouterState.filter(
886
- (d: any, i: number) => i >= index || d.key === '/',
887
- );
888
- newlistenRouterKey = listenRouterKey.filter(
889
- (d: any, i: number) => i >= index || d === '/',
890
- );
891
- this.updateState(newlistenRouterState, newlistenRouterKey, () => {
892
- if (newlistenRouterKey.find((item) => item === activeKey)) {
893
- return;
894
- } else {
895
- let newKey = encodeUrlQuery(key);
896
- history.push({
897
- pathname: newKey,
898
- });
899
- }
900
- });
901
- }
902
- if (type === 'right') {
903
- const index = listenRouterState.findIndex((item) => item.key === key);
904
- newlistenRouterState = listenRouterState.filter(
905
- (d: any, i: number) => i <= index || d.key === '/',
906
- );
907
- newlistenRouterKey = listenRouterKey.filter(
908
- (d: any, i: number) => i <= index || d === '/',
909
- );
910
- this.updateState(
911
- listenRouterState.filter(
912
- (d: any, i: number) => i <= index || d.key === '/',
913
- ),
914
- listenRouterKey.filter((d: any, i: number) => i <= index || d === '/'),
915
- () => {
916
- if (newlistenRouterKey.find((item) => item === activeKey)) {
917
- return;
918
- } else {
919
- let newKey = encodeUrlQuery(key);
920
- history.push({
921
- pathname: newKey,
922
- });
923
- }
924
- },
925
- );
926
- }
927
- if (type === 'all') {
928
- this.updateState(
929
- listenRouterState.filter((item) => item.key === '/'),
930
- listenRouterKey.filter((item) => item === '/'),
931
- () => {
932
- history.push({
933
- pathname: '/',
934
- });
935
- },
936
- );
937
- }
938
- if (type === 'other') {
939
- this.updateState(
940
- listenRouterState.filter(
941
- (item) => item.key === key || item.key === '/',
942
- ),
943
- listenRouterKey.filter((item) => item === key || item === '/'),
944
- () => {
945
- if (key !== activeKey) {
946
- let newKey = encodeUrlQuery(key);
947
- history.push({
948
- pathname: newKey,
949
- });
950
- }
951
- },
952
- );
953
- }
954
- };
955
-
956
- render() {
957
- const {
958
- listenRouterState,
959
- activeKey,
960
- listenRouterKey,
961
- drawerLeftParams,
962
- collapse,
963
- currentSubMenuData,
964
- showSubMenu,
965
- currentSubPath,
966
- } = this.state;
967
- const { originRoutes, itemPath, defaultSettings, transparentProps={} } = this.props;
968
- const TabTitle: React.FC<{}> = ({ item, index, updateState }) => {
969
- return (
970
- <div className="tab_title_content">
971
- {item.tab}
972
- {item.key !== '/' && (
973
- <ItemMenu
974
- info={item}
975
- operateFun={this.operateFun}
976
- listenRouterState={listenRouterState}
977
- />
978
- )}
979
- </div>
980
- );
981
- };
982
-
983
- // 左侧菜单 route
984
- const dataShowRoute = this.props.routes.find(
985
- (route) => route.path === '/homePage/data-show',
986
- ); // 添加数据大屏
987
- const { route, ...restPrpos } = this.props;
988
- const exist = route.routes.find(
989
- (route) => route.path === '/homePage/data-show',
990
- );
991
- if (dataShowRoute && !exist) {
992
- route.routes.splice(1, 0, dataShowRoute);
993
- }
994
-
995
- const menu = (
996
- <Menu>
997
- <Menu.Item
998
- key="0"
999
- style={{
1000
- background: '#FFFFFF',
1001
- color: '#848484',
1002
- fontSize: '12px',
1003
- textAlign: 'center',
1004
- }}
1005
- >
1006
- <div>已打开的页签数: {listenRouterState.length}</div>
1007
- </Menu.Item>
1008
- <Menu.Item key="1" style={{ fontSize: '12px', textAlign: 'center' }}>
1009
- <a
1010
- onClick={() => {
1011
- // 关闭全部
1012
- this.updateState(
1013
- [
1014
- {
1015
- ...this.state.homeRouter,
1016
- key: '/',
1017
- tab: '欢迎',
1018
- closable: false,
1019
- },
1020
- ],
1021
- ['/'],
1022
- () => {
1023
- history.push('/');
1024
- },
1025
- );
1026
- }}
1027
- >
1028
- 关闭全部标签
1029
- </a>
1030
- </Menu.Item>
1031
- <Menu.Item key="2" style={{ fontSize: '12px', textAlign: 'center' }}>
1032
- <a
1033
- onClick={() => {
1034
- if (activeKey === '/') return;
1035
- const index = listenRouterState.findIndex(
1036
- (item) => item.key === activeKey,
1037
- );
1038
- let newActiveKey = '';
1039
- if (index > 0) {
1040
- newActiveKey = listenRouterState[index - 1].key;
1041
- } else {
1042
- newActiveKey = listenRouterState[1].key;
1043
- }
1044
- this.updateState(
1045
- listenRouterState.filter((d) => d.key !== activeKey),
1046
- listenRouterKey.filter((d) => d !== activeKey),
1047
- () => {
1048
- let newKey = encodeUrlQuery(newActiveKey);
1049
- history.push({
1050
- pathname: newKey,
1051
- });
1052
- },
1053
- );
1054
- }}
1055
- >
1056
- 关闭当前标签
1057
- </a>
1058
- </Menu.Item>
1059
- <Menu.Item key="3" style={{ fontSize: '12px', textAlign: 'center' }}>
1060
- <a
1061
- onClick={() => {
1062
- const index = listenRouterState.findIndex(
1063
- (item) => item.key === activeKey,
1064
- );
1065
- // let deleteKey = listenRouterState[index - 1]?.key;
1066
- // if (deleteKey === '/') {
1067
- // message.warning('首页不可关闭。');
1068
- // return;
1069
- // }
1070
-
1071
- this.updateState(
1072
- listenRouterState.filter(
1073
- (d: any, i: number) => i >= index || d.key === '/',
1074
- ),
1075
- listenRouterKey.filter(
1076
- (d: any, i: number) => i >= index || d === '/',
1077
- ),
1078
- );
1079
- }}
1080
- >
1081
- 关闭其左侧标签
1082
- </a>
1083
- </Menu.Item>
1084
- <Menu.Item key="4" style={{ fontSize: '12px', textAlign: 'center' }}>
1085
- <a
1086
- onClick={() => {
1087
- let index = listenRouterState.findIndex(
1088
- (item) => item.key === activeKey,
1089
- );
1090
- this.updateState(
1091
- listenRouterState.filter(
1092
- (d: any, i: number) => i <= index || d.key === '/',
1093
- ),
1094
- listenRouterKey.filter(
1095
- (d: any, i: number) => i <= index || d === '/',
1096
- ),
1097
- );
1098
- }}
1099
- >
1100
- 关闭其右侧标签
1101
- </a>
1102
- </Menu.Item>
1103
- </Menu>
1104
- );
1105
-
1106
- const filterByMenuDate = (
1107
- data: MenuDataItem[],
1108
- keyWord: string,
1109
- ): MenuDataItem[] =>
1110
- data
1111
- .map((item) => {
1112
- if (item.name && item.name.includes(keyWord)) {
1113
- return {
1114
- ...item,
1115
- };
1116
- }
1117
- return undefined;
1118
- })
1119
- .filter((item) => item) as MenuDataItem[];
1120
-
1121
- let weiqianduanProps = {};
1122
- let isWeiqianduan = false;
1123
-
1124
- if (window.top != window) {
1125
- isWeiqianduan = true;
1126
- weiqianduanProps = {
1127
- headerRender: false,
1128
- footerRender: false,
1129
- menuRender: false,
1130
- menuHeaderRender: false,
1131
- menuExtraRender: false,
1132
- };
1133
- }
1134
-
1135
- const OperationsSlot: Record<PositionType, React.ReactNode> = {
1136
- left: (
1137
- <div className={'tab_left_operate'}>
1138
- <div
1139
- onClick={() => {
1140
- history.push({
1141
- pathname: '/',
1142
- });
1143
- }}
1144
- >
1145
- <HomeOutlined />
1146
- </div>
1147
- <div
1148
- style={{ opacity: this.state.isSlider ? 1 : 0.5 }}
1149
- onClick={() => {
1150
- this.setTabNavTransLate(-100);
1151
- }}
1152
- >
1153
- <DoubleLeftOutlined />
1154
- </div>
1155
- </div>
1156
- ),
1157
- right: (
1158
- <div
1159
- style={{ opacity: this.state.isSlider ? 1 : 0.5 }}
1160
- className={'tab_right_operate'}
1161
- onClick={() => {
1162
- this.setTabNavTransLate(100);
1163
- }}
1164
- >
1165
- <DoubleRightOutlined />
1166
- </div>
1167
- ),
1168
- };
1169
-
1170
- return (
1171
- <ProLayout
1172
- actionRef={this.actionRef}
1173
- onMenuHeaderClick={() => history.push('/')}
1174
- menuHeaderRender={({ }) => (
1175
- <CustomerMenuHeader
1176
- originRoutes={originRoutes}
1177
- itemPath={itemPath}
1178
- handleClose={this.handleClose}
1179
- collapsed={collapse}
1180
- />
1181
- )}
1182
- menuExtraRender={() => {
1183
- if (!collapse) {
1184
- return (
1185
- <div>
1186
- <CustomerMenu
1187
- originRoutes={originRoutes}
1188
- itemPath={itemPath}
1189
- ref={this.customerMenuRef}
1190
- actionRef={this.actionRef}
1191
- handleClose={this.handleClose}
1192
- isCollapse={this.state.collapse}
1193
- />
1194
- </div>
1195
- );
1196
- }
1197
- return (
1198
- <div className="collapse_icon_close">
1199
- <span
1200
- className="collapse_icon"
1201
- onClick={() => {
1202
- this.setState({
1203
- collapse: !collapse,
1204
- });
1205
- }}
1206
- >
1207
- <MenuUnfoldOutlined />
1208
- </span>
1209
- </div>
1210
- );
1211
- }}
1212
- menuProps={{
1213
- onClick: () => {
1214
- localStorage.setItem('isMenuClick', 'true');
1215
- },
1216
- }}
1217
- collapsed={collapse}
1218
- onCollapse={(boo: boolean) => {
1219
- this.setState({
1220
- collapse: boo,
1221
- });
1222
- }}
1223
- menuItemRender={(menuItemProps, defaultDom) => {
1224
- if (menuItemProps?.path === '/') {
1225
- return (
1226
- <>
1227
- <div className="one_menu_wrap">
1228
- <Link
1229
- onClick={() => {
1230
- localStorage.setItem('isMenuClick', 'true');
1231
- }}
1232
- to={menuItemProps.path}
1233
- >
1234
- {defaultDom}
1235
- </Link>
1236
- </div>
1237
- </>
1238
- );
1239
- }
1240
- return (
1241
- <Link
1242
- onClick={() => {
1243
- localStorage.setItem('isMenuClick', 'true');
1244
- }}
1245
- to={menuItemProps.path}
1246
- >
1247
- {defaultDom}
1248
- </Link>
1249
- );
1250
- }}
1251
- subMenuItemRender={(menuItemProps, defaultDom) => {
1252
- return (
1253
- <div
1254
- style={{
1255
- height: '40px',
1256
- lineHeight: '40px',
1257
- position: 'relative',
1258
- overflow: 'hidden',
1259
- textOverflow: 'ellipsis',
1260
- whiteSpace: 'nowrap',
1261
- boxSizing: 'border-box',
1262
- paddingRight: '10px',
1263
- }}
1264
- onMouseEnter={() => {
1265
- if (
1266
- menuItemProps.pro_layout_parentKeys &&
1267
- menuItemProps.pro_layout_parentKeys.length
1268
- )
1269
- return;
1270
- this.setState({
1271
- currentSubMenuData: menuItemProps.children,
1272
- currentSubPath: menuItemProps.path,
1273
- });
1274
- this.setShowMenu(true);
1275
- }}
1276
- onMouseLeave={() => {
1277
- this.setShowMenu(false);
1278
- }}
1279
- >
1280
- {defaultDom}
1281
- {showSubMenu &&
1282
- currentSubPath === menuItemProps.path &&
1283
- !collapse && (
1284
- <CaretLeftOutlined
1285
- style={{ position: 'absolute', top: '14px', right: '-4px' }}
1286
- />
1287
- )}
1288
- </div>
1289
- );
1290
- }}
1291
- collapsedButtonRender={() => {
1292
- return (
1293
- <div
1294
- onClick={(e) => {
1295
- e.stopPropagation();
1296
- }}
1297
- className="banquan"
1298
- >
1299
- {''}
1300
- </div>
1301
- );
1302
- }}
1303
- postMenuData={(menus) => {
1304
- return [...filterByMenuDate(menus || [], this.state.keyWord)];
1305
- }}
1306
- links={[
1307
- !this.state.collapse ? (
1308
- <AllFunc
1309
- ref={this.allFunc}
1310
- itemPath={itemPath}
1311
- handleClose={this.handleClose}
1312
- isCollapse={this.state.collapse}
1313
- />
1314
- ) : (
1315
- ''
1316
- ),
1317
- ]}
1318
- onPageChange={() => {
1319
- const { location } = history;
1320
- // 如果没有登录,重定向到 login
1321
- if (
1322
- !localStorage.getItem(ENUM.BROWSER_CACHE.USER_INFO) &&
1323
- location.pathname !== '/user/login'
1324
- ) {
1325
- history.push('/user/login');
1326
- }
1327
- }}
1328
- headerRender={(props) => <GlobalHeaderCom {...props} />}
1329
- menu={{
1330
- request: async () => {
1331
- return JSON.parse(
1332
- localStorage.getItem(`customerMenu_${itemPath}_front`) || '[]',
1333
- );
1334
- },
1335
- type: 'group',
1336
- }}
1337
- route={route}
1338
- {...restPrpos}
1339
- {...defaultSettings}
1340
- {...weiqianduanProps}
1341
- >
1342
- <div id="globalTabsContent" className="globalTabs">
1343
- <DraggableTabs
1344
- activeKey={activeKey}
1345
- id="globalTabs"
1346
- onChange={this.onChange}
1347
- // tabBarExtraContent={operations}
1348
- type="editable-card"
1349
- tabBarStyle={{
1350
- background: '#f3f3f3',
1351
- height: '28px',
1352
- marginRight: 0,
1353
- fontSize: '12px',
1354
- color: '#2C2F2E70',
1355
- marginBottom: '-2px',
1356
- position: 'fixed',
1357
- top: 50,
1358
- zIndex: 10,
1359
- width: collapse ? 'calc(100% - 75px)' : 'calc(100% - 167px)',
1360
- display: isWeiqianduan ? 'none' : 'flex',
1361
- }}
1362
- tabPosition="top"
1363
- tabBarGutter={8}
1364
- onEdit={this.onEdit}
1365
- tabBarExtraContent={OperationsSlot}
1366
- animated={false}
1367
- hideAdd
1368
- >
1369
- {listenRouterState.map((item, index) => (
1370
- <TabPane
1371
- tab={
1372
- <TabTitle
1373
- item={item}
1374
- index={index}
1375
- updateState={this.updateState}
1376
- />
1377
- }
1378
- style={{ marginTop: isWeiqianduan ? 0 : 30 }}
1379
- key={item.key}
1380
- closable={item.key !== '/'}
1381
- closeIcon={<img src="./biaoqian-guanbi-icon.svg" />}
1382
- >
1383
- <WrapperComponent
1384
- item={item}
1385
- routerProps={this.props}
1386
- getDictionarySource={this.getDictionarySource}
1387
- getDictionaryTextByValue={this.getDictionaryTextByValue}
1388
- timeFormat={this.timeFormat}
1389
- transparentProps={transparentProps}
1390
- />
1391
- </TabPane>
1392
- ))}
1393
- </DraggableTabs>
1394
- <div
1395
- className="globalTabsOper"
1396
- style={{
1397
- position: 'fixed',
1398
- top: '50px',
1399
- zIndex: 10,
1400
- background: '#fff',
1401
- display: isWeiqianduan ? 'none' : 'block',
1402
- borderLeft: '1px solid #E4E4E4',
1403
- }}
1404
- >
1405
- <Dropdown overlay={menu} trigger={['click']}>
1406
- <a
1407
- className="ant-dropdown-link"
1408
- onClick={(e) => e.preventDefault()}
1409
- >
1410
- <DashOutlined />
1411
- </a>
1412
- </Dropdown>
1413
- </div>
1414
- <SearchFunc itemPath={itemPath} {...drawerLeftParams}></SearchFunc>
1415
- <div
1416
- onMouseEnter={() => {
1417
- this.setShowMenu(true);
1418
- }}
1419
- onMouseLeave={() => {
1420
- this.setShowMenu(false);
1421
- }}
1422
- className={'sub_menu_content'}
1423
- style={{ display: showSubMenu && !collapse ? 'block' : 'none' }}
1424
- >
1425
- {this.getMenuDom(currentSubMenuData)}
1426
- </div>
1427
- </div>
1428
- </ProLayout>
1429
- );
1430
- }
1431
- }
1432
-
1433
- class WrapperComponent extends React.Component {
1434
- constructor(props) {
1435
- super(props);
1436
- }
1437
-
1438
- shouldComponentUpdate() {
1439
- return false;
1440
- }
1441
-
1442
- render() {
1443
- const {
1444
- item,
1445
- routerProps,
1446
- getDictionarySource,
1447
- getDictionaryTextByValue,
1448
- timeFormat,
1449
- transparentProps,
1450
- } = this.props;
1451
- return (
1452
- <>
1453
- {React.createElement(item.content, {
1454
- getDictionarySource: getDictionarySource,
1455
- getDictionaryTextByValue: getDictionaryTextByValue,
1456
- timeFormat: timeFormat,
1457
- ...routerProps,
1458
- ...transparentProps,
1459
- match: item.match,
1460
- })}
1461
- </>
1462
- );
1463
- }
1464
- }
1465
-
1466
- export default (props) => {
1467
- const { initialState = {} } = useModel('@@initialState');
1468
-
1469
- const { dictionaryData } = initialState;
1470
- const intl = useIntl();
1471
- const { formatMessage } = intl;
1472
- return (
1473
- <BasicLayout
1474
- {...props}
1475
- dictionaryData={dictionaryData}
1476
- formatMessage={formatMessage}
1477
- />
1478
- );
1479
- };
1
+ // @ts-nocheck
2
+ import type {
3
+ MenuDataItem,
4
+ BasicLayoutProps as ProLayoutProps,
5
+ Settings,
6
+ } from '@ant-design/pro-layout';
7
+ import ProLayout from '@ant-design/pro-layout';
8
+ import React, { useState, createRef, useRef } from 'react';
9
+ import {
10
+ Tabs,
11
+ Dropdown,
12
+ Menu,
13
+ } from 'antd';
14
+ import {
15
+ Link,
16
+ useIntl,
17
+ history,
18
+ useModel,
19
+ } from 'umi';
20
+ import {
21
+ DashOutlined,
22
+ MenuUnfoldOutlined,
23
+ CaretLeftOutlined,
24
+ HomeOutlined,
25
+ DoubleLeftOutlined,
26
+ DoubleRightOutlined,
27
+ } from '@ant-design/icons';
28
+ import SearchFunc from './Components/SearchFunc';
29
+ import { debounce } from 'lodash';
30
+
31
+ import AllFunc from './Components/AllFunc';
32
+ import {
33
+ getBreadcrumbNameMap,
34
+ ergodicMenuRoutes,
35
+ matchPath,
36
+ encodeUrlQuery,
37
+ } from './utils';
38
+ import moment from 'moment';
39
+ import GlobalHeaderCom from './Components/GlobalHeader';
40
+ import CustomerMenu from './Components/CustomerMenu';
41
+ import CustomerMenuHeader from './Components/CustomerMenu/globalMenu/customMenuHeader';
42
+ import './index.less';
43
+ import { DndProvider, useDrag, useDrop } from 'react-dnd';
44
+ import { HTML5Backend } from 'react-dnd-html5-backend';
45
+ import ENUM from '@/utils/enumConfig';
46
+ import { memoizeOneFormatter } from '@/utils/utils';
47
+
48
+ const { TabPane } = Tabs;
49
+
50
+ export const RouterContext = React.createContext({});
51
+
52
+ export type BasicLayoutProps = {
53
+ breadcrumbNameMap: Record<string, MenuDataItem>;
54
+ route: ProLayoutProps['route'] & {
55
+ authority: string[];
56
+ };
57
+ settings: Settings;
58
+ } & ProLayoutProps;
59
+
60
+ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
61
+ breadcrumbNameMap: Record<string, MenuDataItem>;
62
+ };
63
+
64
+ const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
65
+ menuList.map((item) => {
66
+ return {
67
+ ...item,
68
+ children: item.children ? menuDataRender(item.children) : undefined,
69
+ };
70
+ });
71
+
72
+ let UN_LISTTEN_DRP;
73
+ let routerArray = [];
74
+ let lastTwoRouterArray = [1, 2];
75
+
76
+ let draggerTabKeys = [];
77
+
78
+ const type = 'DraggableTabNode';
79
+ const DraggableTabNode = ({ index, children, moveNode }) => {
80
+ const ref = useRef(null);
81
+ const [{ isOver, dropClassName }, drop] = useDrop({
82
+ accept: type,
83
+ collect: (monitor) => {
84
+ const { index: dragIndex } = monitor.getItem() || {};
85
+
86
+ if (dragIndex === index) {
87
+ return {};
88
+ }
89
+
90
+ return {
91
+ isOver: monitor.isOver(),
92
+ dropClassName: 'dropping',
93
+ };
94
+ },
95
+ drop: (item) => {
96
+ moveNode(item.index, index);
97
+ },
98
+ });
99
+ const [, drag] = useDrag({
100
+ type,
101
+ item: {
102
+ index,
103
+ },
104
+ collect: (monitor) => ({
105
+ isDragging: monitor.isDragging(),
106
+ }),
107
+ });
108
+ drop(drag(ref));
109
+ return (
110
+ <div
111
+ ref={ref}
112
+ style={{
113
+ marginRight: 24,
114
+ }}
115
+ className={isOver ? dropClassName : ''}
116
+ >
117
+ {children}
118
+ </div>
119
+ );
120
+ };
121
+
122
+ const DraggableTabs = (props) => {
123
+ const { children, changeListenRouterState } = props;
124
+ const [order, setOrder] = useState([]);
125
+
126
+ const moveTabNode = (dragKey, hoverKey) => {
127
+ const newOrder = order.slice();
128
+ React.Children.forEach(children, (c) => {
129
+ if (c.key && newOrder.indexOf(c.key) === -1) {
130
+ newOrder.push(c.key);
131
+ }
132
+ });
133
+ const dragIndex = newOrder.indexOf(dragKey);
134
+ const hoverIndex = newOrder.indexOf(hoverKey);
135
+ newOrder.splice(dragIndex, 1);
136
+ newOrder.splice(hoverIndex, 0, dragKey);
137
+ changeListenRouterState(dragIndex, hoverIndex);
138
+ setOrder(newOrder);
139
+ };
140
+
141
+ const renderTabBar = (tabBarProps, DefaultTabBar) => (
142
+ <DefaultTabBar {...tabBarProps}>
143
+ {(node) => (
144
+ <DraggableTabNode
145
+ key={node.key}
146
+ index={node.key}
147
+ moveNode={moveTabNode}
148
+ >
149
+ {node}
150
+ </DraggableTabNode>
151
+ )}
152
+ </DefaultTabBar>
153
+ );
154
+
155
+ const tabs = [];
156
+ React.Children.forEach(children, (c) => {
157
+ tabs.push(c);
158
+ });
159
+ const orderTabs = tabs.slice().sort((a, b) => {
160
+ const orderA = order.indexOf(a.key);
161
+ const orderB = order.indexOf(b.key);
162
+
163
+ if (orderA !== -1 && orderB !== -1) {
164
+ return orderA - orderB;
165
+ }
166
+
167
+ if (orderA !== -1) {
168
+ return -1;
169
+ }
170
+
171
+ if (orderB !== -1) {
172
+ return 1;
173
+ }
174
+
175
+ const ia = tabs.indexOf(a);
176
+ const ib = tabs.indexOf(b);
177
+ return ia - ib;
178
+ });
179
+ return (
180
+ <DndProvider backend={HTML5Backend}>
181
+ <Tabs renderTabBar={renderTabBar} {...props}>
182
+ {orderTabs}
183
+ </Tabs>
184
+ </DndProvider>
185
+ );
186
+ };
187
+
188
+ const ItemMenu = (props) => {
189
+ const {
190
+ info: { key },
191
+ operateFun,
192
+ listenRouterState,
193
+ } = props;
194
+ let index = listenRouterState.findIndex((item) => item.key === key);
195
+
196
+ const menu = (
197
+ <Menu>
198
+ <Menu.Item key="0" style={{ fontSize: '12px', textAlign: 'center' }}>
199
+ <a
200
+ onClick={(e) => {
201
+ e.stopPropagation();
202
+ operateFun(key, 'self');
203
+ }}
204
+ >
205
+ 关闭当前标签
206
+ </a>
207
+ </Menu.Item>
208
+ <Menu.Item
209
+ disabled={index === 0}
210
+ key="1"
211
+ style={{ fontSize: '12px', textAlign: 'center' }}
212
+ >
213
+ <a
214
+ onClick={(e) => {
215
+ e.stopPropagation();
216
+ operateFun(key, 'left');
217
+ }}
218
+ >
219
+ 关闭其左侧标签
220
+ </a>
221
+ </Menu.Item>
222
+ <Menu.Item
223
+ disabled={index === listenRouterState.length - 1}
224
+ key="2"
225
+ style={{ fontSize: '12px', textAlign: 'center' }}
226
+ >
227
+ <a
228
+ onClick={(e) => {
229
+ e.stopPropagation();
230
+ operateFun(key, 'right');
231
+ }}
232
+ >
233
+ 关闭其右侧标签
234
+ </a>
235
+ </Menu.Item>
236
+ <Menu.Item
237
+ disabled={index === listenRouterState.length - 1}
238
+ key="3"
239
+ style={{ fontSize: '12px', textAlign: 'center' }}
240
+ >
241
+ <a
242
+ onClick={(e) => {
243
+ e.stopPropagation();
244
+ operateFun(key, 'other');
245
+ }}
246
+ >
247
+ 关闭其他标签
248
+ </a>
249
+ </Menu.Item>
250
+ <Menu.Item
251
+ disabled={index === listenRouterState.length - 1}
252
+ key="4"
253
+ style={{ fontSize: '12px', textAlign: 'center' }}
254
+ >
255
+ <a
256
+ onClick={(e) => {
257
+ e.stopPropagation();
258
+ operateFun(key, 'all');
259
+ }}
260
+ >
261
+ 关闭全部标签
262
+ </a>
263
+ </Menu.Item>
264
+ </Menu>
265
+ );
266
+ return (
267
+ <Dropdown overlay={menu} trigger={['hover']}>
268
+ <a
269
+ className="ant-dropdown-link"
270
+ onClick={(e) => {
271
+ e.preventDefault();
272
+ e.stopPropagation();
273
+ }}
274
+ >
275
+ <img style={{ marginRight: '-12px' }} src="./biaoqian-icon.svg" />
276
+ </a>
277
+ </Dropdown>
278
+ );
279
+ };
280
+
281
+ class BasicLayout extends React.PureComponent {
282
+ allFunc: any = createRef('');
283
+ customerMenuRef: any = createRef('');
284
+ actionRef: any = createRef<{
285
+ reload: () => void;
286
+ }>();
287
+ constructor(props) {
288
+ super(props);
289
+ routerArray = this.updateTree(props.route.routes);
290
+ const homeRouter = routerArray.filter(
291
+ (itemroute) => itemroute.key === '/',
292
+ )[0];
293
+ const breadcrumbNameMap = getBreadcrumbNameMap(
294
+ memoizeOneFormatter(props.route.routes, ''),
295
+ );
296
+ const hideMenuArray = ergodicMenuRoutes(props.route.routes);
297
+
298
+ this.state = {
299
+ listenRouterState: [
300
+ { ...homeRouter, key: '/', tab: '欢迎', closable: false },
301
+ ],
302
+ listenRouterKey: ['/'],
303
+ activeKey: '/',
304
+ homeRouter,
305
+ customerMatchs: [],
306
+ breadcrumbNameMap,
307
+ hideMenuArray,
308
+ keyWord: '',
309
+ collapse: false,
310
+ drawerLeftParams: {
311
+ visible: false,
312
+ width: 690,
313
+ title: '搜索',
314
+ onClose: () => {
315
+ this.setState({
316
+ drawerLeftParams: {
317
+ ...this.state.drawerLeftParams,
318
+ visible: false,
319
+ },
320
+ });
321
+ },
322
+ },
323
+ currentSubMenuData: [],
324
+ showSubMenu: false,
325
+ isSlider: false,
326
+ };
327
+ }
328
+
329
+ componentDidMount() {
330
+ const {
331
+ history,
332
+ location,
333
+ itemPath,
334
+ pathToRegexp,
335
+ } = this.props;
336
+
337
+ let istParent = 0;
338
+
339
+ var self = this;
340
+
341
+ window.top != window &&
342
+ window.addEventListener('message', function (e) {
343
+ istParent = 1;
344
+ if (localStorage.getItem(ENUM.BROWSER_CACHE.CHILD_APP_BACK)) {
345
+ localStorage.removeItem(ENUM.BROWSER_CACHE.CHILD_APP_BACK);
346
+ } else {
347
+ localStorage.setItem('isTabChange', true);
348
+ }
349
+
350
+ if (typeof e.data === 'string') {
351
+ let newKey = encodeUrlQuery(e.data.replace(/^\/\w+\//, '/'));
352
+ history.push(newKey);
353
+ } else {
354
+ const info = e.data;
355
+ if (info.type === 'remove') {
356
+ self.tabActions['remove'](info.key.replace(/^\/\w+\//, '/'));
357
+ }
358
+ }
359
+ });
360
+
361
+ UN_LISTTEN_DRP = history.listen((route) => {
362
+ if ((window as any).__POWERED_BY_QIANKUN__) {
363
+ if (window.location.href.indexOf(`/${itemPath}`) === -1) return;
364
+ }
365
+ const {
366
+ listenRouterState,
367
+ listenRouterKey,
368
+ customerMatchs,
369
+ hideMenuArray,
370
+ } = this.state;
371
+ let newListenRouterState = [...listenRouterState];
372
+ let newListenRouterKey = [...listenRouterKey];
373
+
374
+ let replaceRouter = routerArray.filter((itemRoute) =>
375
+ pathToRegexp(itemRoute.key || '').test(route.pathname),
376
+ )[0];
377
+
378
+ let currentKey = '';
379
+
380
+ if (replaceRouter && replaceRouter.isOnlyOnePage) {
381
+ // 处理中英文和特殊字符
382
+ currentKey = decodeURIComponent(route.pathname);
383
+ } else {
384
+ currentKey = decodeURIComponent(
385
+ route.pathname + this.parseQueryString(route.search),
386
+ );
387
+ }
388
+
389
+ if (!istParent) {
390
+ if (route.pathname === '/') return;
391
+ window.parent.postMessage(`/parent/${itemPath}${currentKey}`, '*');
392
+ }
393
+
394
+ // 防止出错
395
+ if (listenRouterKey.length !== listenRouterState.length) {
396
+ listenRouterState.forEach((item, index) => {
397
+ listenRouterKey[index] = item.key;
398
+ });
399
+ }
400
+
401
+ if (!listenRouterKey.includes(currentKey)) {
402
+ if (!replaceRouter) {
403
+ replaceRouter = routerArray.filter(
404
+ (itemroute) => itemroute.key === '/404',
405
+ )?.[0];
406
+
407
+ this.setState(
408
+ {
409
+ listenRouterState: [
410
+ ...listenRouterState,
411
+ { ...replaceRouter, key: currentKey, tab: '404' },
412
+ ],
413
+ activeKey: currentKey,
414
+ listenRouterKey: [...listenRouterKey, currentKey],
415
+ },
416
+ () => {
417
+ this.checkisNavSlide();
418
+ },
419
+ );
420
+ } else {
421
+ const match = matchPath(route.pathname, { path: replaceRouter.key }, pathToRegexp);
422
+ newListenRouterState = [
423
+ ...newListenRouterState,
424
+ {
425
+ ...replaceRouter,
426
+ query: route.query,
427
+ match: match,
428
+ key: currentKey,
429
+ tab: this.getPageTitle(route.pathname) + '',
430
+ },
431
+ ];
432
+ newListenRouterKey = [...listenRouterKey, currentKey];
433
+ }
434
+ }
435
+
436
+ // 处理hideMenu页面自动关闭
437
+ lastTwoRouterArray.push(route.pathname);
438
+ lastTwoRouterArray.shift();
439
+ if (
440
+ !localStorage.getItem('isTabChange') &&
441
+ !localStorage.getItem('isMenuClick')
442
+ ) {
443
+ if (
444
+ lastTwoRouterArray[0] &&
445
+ typeof lastTwoRouterArray[0] === 'string'
446
+ ) {
447
+ let needRemoveKeyArray = hideMenuArray.filter((itemRoute) =>
448
+ pathToRegexp(itemRoute.path || '').test(lastTwoRouterArray[0]),
449
+ );
450
+ // lastTwoRouterArray[0] != lastTwoRouterArray[1] 该判断条件用于判断是否是tab删除操作,如果是tab页删除操作,删除的是不是最后一个打开的tab页,执行history.push会导致错误的将最后打开的那个tab页也删除掉
451
+ if (
452
+ needRemoveKeyArray.length &&
453
+ lastTwoRouterArray[0] != lastTwoRouterArray[1]
454
+ ) {
455
+ if (
456
+ (!(
457
+ lastTwoRouterArray[0].indexOf('/order/mainOrder/supplement') >=
458
+ 0
459
+ ) ||
460
+ !pathToRegexp(
461
+ '/order/mainOrder/:parmode/separateOrder/:id',
462
+ ).test(lastTwoRouterArray[1])) &&
463
+ (!pathToRegexp(
464
+ '/order/mainOrder/:parmode/separateOrder/:id',
465
+ ).test(lastTwoRouterArray[0]) ||
466
+ !(
467
+ lastTwoRouterArray[1].indexOf(
468
+ 'order/mainOrder/separateOrder/',
469
+ ) >= 0
470
+ ))
471
+ ) {
472
+ if (!route.state?.thisHideInMenuDoNotClose) {
473
+ newListenRouterState = newListenRouterState.filter((item) => {
474
+ const [pathname] = item.key ? item.key.split('?') : [];
475
+ return pathname && pathname !== lastTwoRouterArray[0];
476
+ });
477
+ newListenRouterKey = newListenRouterKey.filter((item) => {
478
+ const [pathname] = item ? item.split('?') : [];
479
+ return pathname && pathname !== lastTwoRouterArray[0];
480
+ });
481
+ }
482
+ }
483
+ }
484
+ }
485
+ // refs?.tableRef?.current?.refreshTable();
486
+ } else {
487
+ setTimeout(() => {
488
+ // 处理页面刷新两面
489
+ localStorage.removeItem('isTabChange');
490
+ localStorage.removeItem('isMenuClick');
491
+ }, 0);
492
+ }
493
+ this.setState(
494
+ {
495
+ //路由监听函数最后执行setState,避免处理hideMenu类型页面自动关闭的逻辑块内获取不到最新state的listenRouterState和listenRouterKey
496
+ activeKey: currentKey,
497
+ listenRouterState: newListenRouterState,
498
+ listenRouterKey: newListenRouterKey,
499
+ },
500
+ () => {
501
+ this.checkisNavSlide();
502
+ },
503
+ );
504
+
505
+ istParent = 0;
506
+ });
507
+
508
+ if (
509
+ localStorage.getItem('firstPage') &&
510
+ localStorage.getItem('firstPage')?.startsWith(`#/${itemPath}/`)
511
+ ) {
512
+ istParent = 1;
513
+ history.push(
514
+ localStorage
515
+ .getItem('firstPage')
516
+ ?.slice(1)
517
+ .replace(/^\/\w+\//, '/'),
518
+ );
519
+ } else {
520
+ history.push(location);
521
+ }
522
+ }
523
+
524
+ componentWillUnmount() {
525
+ // eslint-disable-next-line no-unused-expressions
526
+ UN_LISTTEN_DRP && UN_LISTTEN_DRP();
527
+ }
528
+
529
+ parseQueryString = (queryString) => {
530
+ if (!queryString) {
531
+ return '';
532
+ }
533
+
534
+ if (queryString.indexOf('?') < 0) {
535
+ return `?${queryString}`;
536
+ }
537
+
538
+ return queryString;
539
+ };
540
+
541
+ updateTree = (Tree) => {
542
+ const treeData = Tree;
543
+ const treeList = [];
544
+ // 递归获取树列表
545
+ const getTreeList = (data) => {
546
+ data.forEach((node) => {
547
+ if (node.routes && node.routes.length > 0) {
548
+ getTreeList(node.routes);
549
+ } else {
550
+ treeList.push({
551
+ tab: node.locale,
552
+ key: node.path,
553
+ locale: node.locale,
554
+ closable: true,
555
+ content: node.component,
556
+ name: node.name,
557
+ hideInMenu: node.hideInMenu,
558
+ isOnlyOnePage: node.isOnlyOnePage,
559
+ });
560
+ }
561
+ });
562
+ };
563
+ getTreeList(treeData);
564
+ return treeList;
565
+ };
566
+
567
+ getDictionarySource = (dicCode: string, needConvertInterger = false) => {
568
+ const { dictionaryData } = this.props;
569
+
570
+ let dicData = {};
571
+
572
+ if (!dictionaryData) {
573
+ let storageDic = localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES)
574
+ ? JSON.parse(localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES))
575
+ : {};
576
+ dicData = storageDic[dicCode];
577
+ } else {
578
+ dicData = dictionaryData[dicCode];
579
+ }
580
+ // if (!dicData || !dicData.length) {
581
+ // throw new Error(`当前没有${dicCode}字典值`);
582
+ // }
583
+
584
+ try {
585
+ if (needConvertInterger) {
586
+ dicData = dicData.map((item: { text: string; value: string }) => ({
587
+ ...item,
588
+ value: parseFloat(item.value),
589
+ }));
590
+ }
591
+ } catch (e) { }
592
+
593
+ return dicData;
594
+ };
595
+
596
+ getDictionaryTextByValue = (dicCode: string, value: string) => {
597
+ let dicData = [];
598
+ let dictionaryData: any;
599
+ if (!dictionaryData) {
600
+ let storageDic = localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES)
601
+ ? JSON.parse(localStorage.getItem(ENUM.BROWSER_CACHE.DICT_CODES))
602
+ : {};
603
+ dicData = storageDic[dicCode];
604
+ } else {
605
+ dicData = dictionaryData[dicCode];
606
+ }
607
+
608
+ if (!dicData || !dicData.length) {
609
+ // throw new Error(`当前没有${dicCode}字典值`);
610
+ }
611
+
612
+ if (value === undefined) return '- -';
613
+
614
+ const dicItemArray = dicData?.filter(
615
+ (item: { value: string }) => item.value === value.toString(),
616
+ );
617
+
618
+ if (!dicItemArray?.length) {
619
+ // throw new Error(`当前${dicCode}字典值合没有${value}的数据`)
620
+ return value;
621
+ }
622
+
623
+ return dicItemArray[0].text;
624
+ };
625
+
626
+ timeFormat = (timeStr, format, notNeedConvertTimeZone) => {
627
+ if (!timeStr) return '- -';
628
+
629
+ if (notNeedConvertTimeZone) {
630
+ return moment(timeStr).format(format);
631
+ }
632
+
633
+ return moment(timeStr).add(8, 'hours').format(format) || '- -';
634
+ };
635
+
636
+ onChange = (key) => {
637
+ // console.log('onChange');
638
+ if (key !== this.state.activeKey) {
639
+ this.setState({
640
+ activeKey: key,
641
+ });
642
+ localStorage.setItem('isTabChange', '1');
643
+ let newKey = encodeUrlQuery(key);
644
+ history.push(newKey);
645
+ }
646
+ };
647
+
648
+ getPageTitle = (pathname) => {
649
+ const { formatMessage } = this.props;
650
+ const { breadcrumbNameMap } = this.state;
651
+ const currRouterData = this.matchParamsPath(pathname, breadcrumbNameMap);
652
+
653
+ if (!currRouterData) {
654
+ return '';
655
+ }
656
+ const pageName = formatMessage({
657
+ id: currRouterData.locale || currRouterData.name,
658
+ defaultMessage: currRouterData.name,
659
+ });
660
+
661
+ return `${pageName}`;
662
+ };
663
+
664
+ matchParamsPath = (pathname, breadcrumbNameMap) => {
665
+ const { pathToRegexp } = this.props;
666
+ const pathKey = Object.keys(breadcrumbNameMap).find((key) =>
667
+ pathToRegexp(key).test(pathname),
668
+ );
669
+ return breadcrumbNameMap[pathKey];
670
+ };
671
+
672
+ onEdit = (
673
+ targetKey: React.MouseEvent | React.KeyboardEvent | string,
674
+ action: string,
675
+ ) => {
676
+ this.tabActions[action](targetKey);
677
+ };
678
+
679
+ tabActions: any = {
680
+ remove: (targetKey: string) => {
681
+ const { listenRouterState, activeKey, customerMatchs, listenRouterKey } =
682
+ this.state;
683
+
684
+ let lastIndex: number = 0;
685
+ let newActiveKey: string | undefined = activeKey;
686
+ let newListenRouterState = [];
687
+ let newListenRouterKey = [];
688
+
689
+ if (targetKey === activeKey) {
690
+ listenRouterState.forEach((pane, i) => {
691
+ if (pane.key === targetKey) {
692
+ lastIndex = i - 1;
693
+ }
694
+ });
695
+
696
+ newListenRouterState = listenRouterState.filter(
697
+ (item) => item.key !== targetKey,
698
+ );
699
+ newListenRouterKey = listenRouterKey.filter(
700
+ (item) => item !== targetKey,
701
+ );
702
+
703
+ if (lastIndex < 0) {
704
+ lastIndex = 0;
705
+ }
706
+
707
+ newActiveKey = newListenRouterState[lastIndex].key;
708
+ } else {
709
+ newListenRouterState = listenRouterState.filter(
710
+ (item) => item.key !== targetKey,
711
+ );
712
+ newListenRouterKey = listenRouterKey.filter(
713
+ (item) => item !== targetKey,
714
+ );
715
+ }
716
+
717
+ this.setState(
718
+ {
719
+ activeKey: newActiveKey,
720
+ listenRouterState: newListenRouterState,
721
+ listenRouterKey: newListenRouterKey,
722
+ },
723
+ () => {
724
+ let newKey = encodeUrlQuery(newActiveKey);
725
+ history.push({
726
+ pathname: newKey,
727
+ });
728
+ this.checkisNavSlide();
729
+ },
730
+ );
731
+ },
732
+ };
733
+
734
+ updateState = (newListenRouterState, newListenRouterKey, cb) => {
735
+ this.setState(
736
+ {
737
+ listenRouterState: newListenRouterState,
738
+ listenRouterKey: newListenRouterKey,
739
+ },
740
+ () => {
741
+ this.checkisNavSlide();
742
+ if (cb) cb();
743
+ },
744
+ );
745
+ };
746
+
747
+ handleClose = () => {
748
+ this.setState({
749
+ drawerLeftParams: {
750
+ ...this.state.drawerLeftParams,
751
+ visible: false,
752
+ },
753
+ isCollapse: true,
754
+ });
755
+ this.allFunc.current?.close?.();
756
+ this.customerMenuRef.current?.close?.();
757
+ };
758
+
759
+ handleMenuClick = (item: any) => {
760
+ if (item.children || !item.component) return;
761
+ let newKey = encodeUrlQuery(item.path);
762
+ history.push({
763
+ pathname: newKey,
764
+ });
765
+ this.setShowMenu(false);
766
+ };
767
+
768
+ getMenuDom = (menuData) => {
769
+ return menuData.map((item) => (
770
+ <div>
771
+ <div
772
+ onClick={() => {
773
+ this.handleMenuClick(item);
774
+ }}
775
+ className={`${'menu_item'} ${item.children || !item.component ? '' : 'link_style'
776
+ }`}
777
+ style={{
778
+ fontWeight: item.children || !item.component ? 'bolder' : '400',
779
+ paddingLeft: '10px',
780
+ marginTop: item.children || !item.component ? '5px' : '0px',
781
+ fontSize: item.children || !item.component ? '14px' : '12px',
782
+ }}
783
+ >
784
+ {item.name}
785
+ </div>
786
+ {!!item.children &&
787
+ !!item.children.length &&
788
+ this.getMenuDom(item.children)}
789
+ </div>
790
+ ));
791
+ };
792
+
793
+ setShowMenu = debounce((isShow) => {
794
+ this.setState({
795
+ showSubMenu: isShow,
796
+ });
797
+ }, 500);
798
+
799
+ //设置tabs标签左右滚动
800
+ setTabNavTransLate = (num) => {
801
+ let globalTabsNav = document
802
+ .getElementById('globalTabs')
803
+ ?.getElementsByClassName('ant-tabs-nav-list')?.[0];
804
+ let globalTabsNavWrap = document
805
+ .getElementById('globalTabs')
806
+ ?.getElementsByClassName('ant-tabs-nav-wrap')?.[0];
807
+ let wrapWidth = globalTabsNavWrap.offsetWidth; //tabsNav父节点宽度
808
+ let navListWidth = globalTabsNav.offsetWidth; //tabsNav总宽度
809
+ if (navListWidth - wrapWidth <= 0) return;
810
+ let maxTransX = navListWidth - wrapWidth; // 允许移动最大宽度
811
+ let transXStr = document.defaultView?.getComputedStyle(
812
+ globalTabsNav,
813
+ null,
814
+ ).transform;
815
+ let transx = transXStr?.split(',')[4]; //当前translateX的值
816
+
817
+ let targetTransX = Math.abs(Number(transx)) + num;
818
+ if (targetTransX <= 0) targetTransX = 0;
819
+ if (targetTransX >= Number(maxTransX)) targetTransX = Number(maxTransX);
820
+ globalTabsNav.style.transform = 'translateX(-' + targetTransX + 'px)';
821
+ };
822
+
823
+ checkisNavSlide = () => {
824
+ if (window.top != window) return;
825
+ //监听tabs页签总长度判断是否可点击滑动
826
+ let globalTabsNav = document
827
+ .getElementById('globalTabs')
828
+ ?.getElementsByClassName('ant-tabs-nav-list')?.[0];
829
+ let globalTabsNavWrap = document
830
+ .getElementById('globalTabs')
831
+ ?.getElementsByClassName('ant-tabs-nav-wrap')?.[0];
832
+ let wrapWidth = globalTabsNavWrap?.offsetWidth; //tabsNav父节点宽度
833
+ let navListWidth = globalTabsNav?.offsetWidth; //tabsNav总宽度
834
+ if (navListWidth - wrapWidth <= 0) {
835
+ this.setState({
836
+ isSlider: false,
837
+ });
838
+ return;
839
+ }
840
+ this.setState({
841
+ isSlider: true,
842
+ });
843
+ };
844
+
845
+ changeListenRouterState = (dragIndex: number, hoverIndex: number) => {
846
+ const { listenRouterState, listenRouterKey } = this.state;
847
+ let dragItem = listenRouterState[dragIndex];
848
+ let dragKeyItem = listenRouterKey[dragIndex];
849
+
850
+ listenRouterState.splice(dragIndex, 1);
851
+ listenRouterState.splice(hoverIndex, 0, dragItem);
852
+
853
+ listenRouterKey.splice(dragIndex, 1);
854
+ listenRouterKey.splice(hoverIndex, 0, dragKeyItem);
855
+ };
856
+
857
+ operateFun = (key, type) => {
858
+ const { listenRouterState, activeKey, listenRouterKey } = this.state;
859
+ let deleteKey = '';
860
+ let newlistenRouterState = [];
861
+ let newlistenRouterKey = [];
862
+ let newActiveKey = '';
863
+ let deleteIndex = 0;
864
+ if (type === 'self') {
865
+ deleteIndex = listenRouterState.findIndex((item) => item.key === key);
866
+ deleteKey = key;
867
+ if (deleteIndex > 0) {
868
+ newActiveKey = listenRouterState[deleteIndex - 1].key;
869
+ } else {
870
+ newActiveKey = listenRouterState[1].key;
871
+ }
872
+ newlistenRouterState = listenRouterState.filter((d) => d.key !== key);
873
+ newlistenRouterKey = listenRouterKey.filter((d) => d !== key);
874
+ this.updateState(newlistenRouterState, newlistenRouterKey, () => {
875
+ if (deleteKey === activeKey) {
876
+ let newKey = encodeUrlQuery(newActiveKey);
877
+ history.push({
878
+ pathname: newKey,
879
+ });
880
+ }
881
+ });
882
+ }
883
+ if (type === 'left') {
884
+ const index = listenRouterState.findIndex((item) => item.key === key);
885
+ newlistenRouterState = listenRouterState.filter(
886
+ (d: any, i: number) => i >= index || d.key === '/',
887
+ );
888
+ newlistenRouterKey = listenRouterKey.filter(
889
+ (d: any, i: number) => i >= index || d === '/',
890
+ );
891
+ this.updateState(newlistenRouterState, newlistenRouterKey, () => {
892
+ if (newlistenRouterKey.find((item) => item === activeKey)) {
893
+ return;
894
+ } else {
895
+ let newKey = encodeUrlQuery(key);
896
+ history.push({
897
+ pathname: newKey,
898
+ });
899
+ }
900
+ });
901
+ }
902
+ if (type === 'right') {
903
+ const index = listenRouterState.findIndex((item) => item.key === key);
904
+ newlistenRouterState = listenRouterState.filter(
905
+ (d: any, i: number) => i <= index || d.key === '/',
906
+ );
907
+ newlistenRouterKey = listenRouterKey.filter(
908
+ (d: any, i: number) => i <= index || d === '/',
909
+ );
910
+ this.updateState(
911
+ listenRouterState.filter(
912
+ (d: any, i: number) => i <= index || d.key === '/',
913
+ ),
914
+ listenRouterKey.filter((d: any, i: number) => i <= index || d === '/'),
915
+ () => {
916
+ if (newlistenRouterKey.find((item) => item === activeKey)) {
917
+ return;
918
+ } else {
919
+ let newKey = encodeUrlQuery(key);
920
+ history.push({
921
+ pathname: newKey,
922
+ });
923
+ }
924
+ },
925
+ );
926
+ }
927
+ if (type === 'all') {
928
+ this.updateState(
929
+ listenRouterState.filter((item) => item.key === '/'),
930
+ listenRouterKey.filter((item) => item === '/'),
931
+ () => {
932
+ history.push({
933
+ pathname: '/',
934
+ });
935
+ },
936
+ );
937
+ }
938
+ if (type === 'other') {
939
+ this.updateState(
940
+ listenRouterState.filter(
941
+ (item) => item.key === key || item.key === '/',
942
+ ),
943
+ listenRouterKey.filter((item) => item === key || item === '/'),
944
+ () => {
945
+ if (key !== activeKey) {
946
+ let newKey = encodeUrlQuery(key);
947
+ history.push({
948
+ pathname: newKey,
949
+ });
950
+ }
951
+ },
952
+ );
953
+ }
954
+ };
955
+
956
+ render() {
957
+ const {
958
+ listenRouterState,
959
+ activeKey,
960
+ listenRouterKey,
961
+ drawerLeftParams,
962
+ collapse,
963
+ currentSubMenuData,
964
+ showSubMenu,
965
+ currentSubPath,
966
+ } = this.state;
967
+ const { originRoutes, itemPath, defaultSettings, transparentProps={} } = this.props;
968
+ const TabTitle: React.FC<{}> = ({ item, index, updateState }) => {
969
+ return (
970
+ <div className="tab_title_content">
971
+ {item.tab}
972
+ {item.key !== '/' && (
973
+ <ItemMenu
974
+ info={item}
975
+ operateFun={this.operateFun}
976
+ listenRouterState={listenRouterState}
977
+ />
978
+ )}
979
+ </div>
980
+ );
981
+ };
982
+
983
+ // 左侧菜单 route
984
+ const dataShowRoute = this.props.routes.find(
985
+ (route) => route.path === '/homePage/data-show',
986
+ ); // 添加数据大屏
987
+ const { route, ...restPrpos } = this.props;
988
+ const exist = route.routes.find(
989
+ (route) => route.path === '/homePage/data-show',
990
+ );
991
+ if (dataShowRoute && !exist) {
992
+ route.routes.splice(1, 0, dataShowRoute);
993
+ }
994
+
995
+ const menu = (
996
+ <Menu>
997
+ <Menu.Item
998
+ key="0"
999
+ style={{
1000
+ background: '#FFFFFF',
1001
+ color: '#848484',
1002
+ fontSize: '12px',
1003
+ textAlign: 'center',
1004
+ }}
1005
+ >
1006
+ <div>已打开的页签数: {listenRouterState.length}</div>
1007
+ </Menu.Item>
1008
+ <Menu.Item key="1" style={{ fontSize: '12px', textAlign: 'center' }}>
1009
+ <a
1010
+ onClick={() => {
1011
+ // 关闭全部
1012
+ this.updateState(
1013
+ [
1014
+ {
1015
+ ...this.state.homeRouter,
1016
+ key: '/',
1017
+ tab: '欢迎',
1018
+ closable: false,
1019
+ },
1020
+ ],
1021
+ ['/'],
1022
+ () => {
1023
+ history.push('/');
1024
+ },
1025
+ );
1026
+ }}
1027
+ >
1028
+ 关闭全部标签
1029
+ </a>
1030
+ </Menu.Item>
1031
+ <Menu.Item key="2" style={{ fontSize: '12px', textAlign: 'center' }}>
1032
+ <a
1033
+ onClick={() => {
1034
+ if (activeKey === '/') return;
1035
+ const index = listenRouterState.findIndex(
1036
+ (item) => item.key === activeKey,
1037
+ );
1038
+ let newActiveKey = '';
1039
+ if (index > 0) {
1040
+ newActiveKey = listenRouterState[index - 1].key;
1041
+ } else {
1042
+ newActiveKey = listenRouterState[1].key;
1043
+ }
1044
+ this.updateState(
1045
+ listenRouterState.filter((d) => d.key !== activeKey),
1046
+ listenRouterKey.filter((d) => d !== activeKey),
1047
+ () => {
1048
+ let newKey = encodeUrlQuery(newActiveKey);
1049
+ history.push({
1050
+ pathname: newKey,
1051
+ });
1052
+ },
1053
+ );
1054
+ }}
1055
+ >
1056
+ 关闭当前标签
1057
+ </a>
1058
+ </Menu.Item>
1059
+ <Menu.Item key="3" style={{ fontSize: '12px', textAlign: 'center' }}>
1060
+ <a
1061
+ onClick={() => {
1062
+ const index = listenRouterState.findIndex(
1063
+ (item) => item.key === activeKey,
1064
+ );
1065
+ // let deleteKey = listenRouterState[index - 1]?.key;
1066
+ // if (deleteKey === '/') {
1067
+ // message.warning('首页不可关闭。');
1068
+ // return;
1069
+ // }
1070
+
1071
+ this.updateState(
1072
+ listenRouterState.filter(
1073
+ (d: any, i: number) => i >= index || d.key === '/',
1074
+ ),
1075
+ listenRouterKey.filter(
1076
+ (d: any, i: number) => i >= index || d === '/',
1077
+ ),
1078
+ );
1079
+ }}
1080
+ >
1081
+ 关闭其左侧标签
1082
+ </a>
1083
+ </Menu.Item>
1084
+ <Menu.Item key="4" style={{ fontSize: '12px', textAlign: 'center' }}>
1085
+ <a
1086
+ onClick={() => {
1087
+ let index = listenRouterState.findIndex(
1088
+ (item) => item.key === activeKey,
1089
+ );
1090
+ this.updateState(
1091
+ listenRouterState.filter(
1092
+ (d: any, i: number) => i <= index || d.key === '/',
1093
+ ),
1094
+ listenRouterKey.filter(
1095
+ (d: any, i: number) => i <= index || d === '/',
1096
+ ),
1097
+ );
1098
+ }}
1099
+ >
1100
+ 关闭其右侧标签
1101
+ </a>
1102
+ </Menu.Item>
1103
+ </Menu>
1104
+ );
1105
+
1106
+ const filterByMenuDate = (
1107
+ data: MenuDataItem[],
1108
+ keyWord: string,
1109
+ ): MenuDataItem[] =>
1110
+ data
1111
+ .map((item) => {
1112
+ if (item.name && item.name.includes(keyWord)) {
1113
+ return {
1114
+ ...item,
1115
+ };
1116
+ }
1117
+ return undefined;
1118
+ })
1119
+ .filter((item) => item) as MenuDataItem[];
1120
+
1121
+ let weiqianduanProps = {};
1122
+ let isWeiqianduan = false;
1123
+
1124
+ if (window.top != window) {
1125
+ isWeiqianduan = true;
1126
+ weiqianduanProps = {
1127
+ headerRender: false,
1128
+ footerRender: false,
1129
+ menuRender: false,
1130
+ menuHeaderRender: false,
1131
+ menuExtraRender: false,
1132
+ };
1133
+ }
1134
+
1135
+ const OperationsSlot: Record<PositionType, React.ReactNode> = {
1136
+ left: (
1137
+ <div className={'tab_left_operate'}>
1138
+ <div
1139
+ onClick={() => {
1140
+ history.push({
1141
+ pathname: '/',
1142
+ });
1143
+ }}
1144
+ >
1145
+ <HomeOutlined />
1146
+ </div>
1147
+ <div
1148
+ style={{ opacity: this.state.isSlider ? 1 : 0.5 }}
1149
+ onClick={() => {
1150
+ this.setTabNavTransLate(-100);
1151
+ }}
1152
+ >
1153
+ <DoubleLeftOutlined />
1154
+ </div>
1155
+ </div>
1156
+ ),
1157
+ right: (
1158
+ <div
1159
+ style={{ opacity: this.state.isSlider ? 1 : 0.5 }}
1160
+ className={'tab_right_operate'}
1161
+ onClick={() => {
1162
+ this.setTabNavTransLate(100);
1163
+ }}
1164
+ >
1165
+ <DoubleRightOutlined />
1166
+ </div>
1167
+ ),
1168
+ };
1169
+
1170
+ return (
1171
+ <ProLayout
1172
+ actionRef={this.actionRef}
1173
+ onMenuHeaderClick={() => history.push('/')}
1174
+ menuHeaderRender={({ }) => (
1175
+ <CustomerMenuHeader
1176
+ originRoutes={originRoutes}
1177
+ itemPath={itemPath}
1178
+ handleClose={this.handleClose}
1179
+ collapsed={collapse}
1180
+ />
1181
+ )}
1182
+ menuExtraRender={() => {
1183
+ if (!collapse) {
1184
+ return (
1185
+ <div>
1186
+ <CustomerMenu
1187
+ originRoutes={originRoutes}
1188
+ itemPath={itemPath}
1189
+ ref={this.customerMenuRef}
1190
+ actionRef={this.actionRef}
1191
+ handleClose={this.handleClose}
1192
+ isCollapse={this.state.collapse}
1193
+ />
1194
+ </div>
1195
+ );
1196
+ }
1197
+ return (
1198
+ <div className="collapse_icon_close">
1199
+ <span
1200
+ className="collapse_icon"
1201
+ onClick={() => {
1202
+ this.setState({
1203
+ collapse: !collapse,
1204
+ });
1205
+ }}
1206
+ >
1207
+ <MenuUnfoldOutlined />
1208
+ </span>
1209
+ </div>
1210
+ );
1211
+ }}
1212
+ menuProps={{
1213
+ onClick: () => {
1214
+ localStorage.setItem('isMenuClick', 'true');
1215
+ },
1216
+ }}
1217
+ collapsed={collapse}
1218
+ onCollapse={(boo: boolean) => {
1219
+ this.setState({
1220
+ collapse: boo,
1221
+ });
1222
+ }}
1223
+ menuItemRender={(menuItemProps, defaultDom) => {
1224
+ if (menuItemProps?.path === '/') {
1225
+ return (
1226
+ <>
1227
+ <div className="one_menu_wrap">
1228
+ <Link
1229
+ onClick={() => {
1230
+ localStorage.setItem('isMenuClick', 'true');
1231
+ }}
1232
+ to={menuItemProps.path}
1233
+ >
1234
+ {defaultDom}
1235
+ </Link>
1236
+ </div>
1237
+ </>
1238
+ );
1239
+ }
1240
+ return (
1241
+ <Link
1242
+ onClick={() => {
1243
+ localStorage.setItem('isMenuClick', 'true');
1244
+ }}
1245
+ to={menuItemProps.path}
1246
+ >
1247
+ {defaultDom}
1248
+ </Link>
1249
+ );
1250
+ }}
1251
+ subMenuItemRender={(menuItemProps, defaultDom) => {
1252
+ return (
1253
+ <div
1254
+ style={{
1255
+ height: '40px',
1256
+ lineHeight: '40px',
1257
+ position: 'relative',
1258
+ overflow: 'hidden',
1259
+ textOverflow: 'ellipsis',
1260
+ whiteSpace: 'nowrap',
1261
+ boxSizing: 'border-box',
1262
+ paddingRight: '10px',
1263
+ }}
1264
+ onMouseEnter={() => {
1265
+ if (
1266
+ menuItemProps.pro_layout_parentKeys &&
1267
+ menuItemProps.pro_layout_parentKeys.length
1268
+ )
1269
+ return;
1270
+ this.setState({
1271
+ currentSubMenuData: menuItemProps.children,
1272
+ currentSubPath: menuItemProps.path,
1273
+ });
1274
+ this.setShowMenu(true);
1275
+ }}
1276
+ onMouseLeave={() => {
1277
+ this.setShowMenu(false);
1278
+ }}
1279
+ >
1280
+ {defaultDom}
1281
+ {showSubMenu &&
1282
+ currentSubPath === menuItemProps.path &&
1283
+ !collapse && (
1284
+ <CaretLeftOutlined
1285
+ style={{ position: 'absolute', top: '14px', right: '-4px' }}
1286
+ />
1287
+ )}
1288
+ </div>
1289
+ );
1290
+ }}
1291
+ collapsedButtonRender={() => {
1292
+ return (
1293
+ <div
1294
+ onClick={(e) => {
1295
+ e.stopPropagation();
1296
+ }}
1297
+ className="banquan"
1298
+ >
1299
+ {''}
1300
+ </div>
1301
+ );
1302
+ }}
1303
+ postMenuData={(menus) => {
1304
+ return [...filterByMenuDate(menus || [], this.state.keyWord)];
1305
+ }}
1306
+ links={[
1307
+ !this.state.collapse ? (
1308
+ <AllFunc
1309
+ ref={this.allFunc}
1310
+ itemPath={itemPath}
1311
+ handleClose={this.handleClose}
1312
+ isCollapse={this.state.collapse}
1313
+ />
1314
+ ) : (
1315
+ ''
1316
+ ),
1317
+ ]}
1318
+ onPageChange={() => {
1319
+ const { location } = history;
1320
+ // 如果没有登录,重定向到 login
1321
+ if (
1322
+ !localStorage.getItem(ENUM.BROWSER_CACHE.USER_INFO) &&
1323
+ location.pathname !== '/user/login'
1324
+ ) {
1325
+ history.push('/user/login');
1326
+ }
1327
+ }}
1328
+ headerRender={(props) => <GlobalHeaderCom {...props} />}
1329
+ menu={{
1330
+ request: async () => {
1331
+ return JSON.parse(
1332
+ localStorage.getItem(`customerMenu_${itemPath}_front`) || '[]',
1333
+ );
1334
+ },
1335
+ type: 'group',
1336
+ }}
1337
+ route={route}
1338
+ {...restPrpos}
1339
+ {...defaultSettings}
1340
+ {...weiqianduanProps}
1341
+ >
1342
+ <div id="globalTabsContent" className="globalTabs">
1343
+ <DraggableTabs
1344
+ activeKey={activeKey}
1345
+ id="globalTabs"
1346
+ onChange={this.onChange}
1347
+ // tabBarExtraContent={operations}
1348
+ type="editable-card"
1349
+ tabBarStyle={{
1350
+ background: '#f3f3f3',
1351
+ height: '28px',
1352
+ marginRight: 0,
1353
+ fontSize: '12px',
1354
+ color: '#2C2F2E70',
1355
+ marginBottom: '-2px',
1356
+ position: 'fixed',
1357
+ top: 50,
1358
+ zIndex: 10,
1359
+ width: collapse ? 'calc(100% - 75px)' : 'calc(100% - 167px)',
1360
+ display: isWeiqianduan ? 'none' : 'flex',
1361
+ }}
1362
+ tabPosition="top"
1363
+ tabBarGutter={8}
1364
+ onEdit={this.onEdit}
1365
+ tabBarExtraContent={OperationsSlot}
1366
+ animated={false}
1367
+ hideAdd
1368
+ >
1369
+ {listenRouterState.map((item, index) => (
1370
+ <TabPane
1371
+ tab={
1372
+ <TabTitle
1373
+ item={item}
1374
+ index={index}
1375
+ updateState={this.updateState}
1376
+ />
1377
+ }
1378
+ style={{ marginTop: isWeiqianduan ? 0 : 30 }}
1379
+ key={item.key}
1380
+ closable={item.key !== '/'}
1381
+ closeIcon={<img src="./biaoqian-guanbi-icon.svg" />}
1382
+ >
1383
+ <WrapperComponent
1384
+ item={item}
1385
+ routerProps={this.props}
1386
+ getDictionarySource={this.getDictionarySource}
1387
+ getDictionaryTextByValue={this.getDictionaryTextByValue}
1388
+ timeFormat={this.timeFormat}
1389
+ transparentProps={transparentProps}
1390
+ />
1391
+ </TabPane>
1392
+ ))}
1393
+ </DraggableTabs>
1394
+ <div
1395
+ className="globalTabsOper"
1396
+ style={{
1397
+ position: 'fixed',
1398
+ top: '50px',
1399
+ zIndex: 10,
1400
+ background: '#fff',
1401
+ display: isWeiqianduan ? 'none' : 'block',
1402
+ borderLeft: '1px solid #E4E4E4',
1403
+ }}
1404
+ >
1405
+ <Dropdown overlay={menu} trigger={['click']}>
1406
+ <a
1407
+ className="ant-dropdown-link"
1408
+ onClick={(e) => e.preventDefault()}
1409
+ >
1410
+ <DashOutlined />
1411
+ </a>
1412
+ </Dropdown>
1413
+ </div>
1414
+ <SearchFunc itemPath={itemPath} {...drawerLeftParams}></SearchFunc>
1415
+ <div
1416
+ onMouseEnter={() => {
1417
+ this.setShowMenu(true);
1418
+ }}
1419
+ onMouseLeave={() => {
1420
+ this.setShowMenu(false);
1421
+ }}
1422
+ className={'sub_menu_content'}
1423
+ style={{ display: showSubMenu && !collapse ? 'block' : 'none' }}
1424
+ >
1425
+ {this.getMenuDom(currentSubMenuData)}
1426
+ </div>
1427
+ </div>
1428
+ </ProLayout>
1429
+ );
1430
+ }
1431
+ }
1432
+
1433
+ class WrapperComponent extends React.Component {
1434
+ constructor(props) {
1435
+ super(props);
1436
+ }
1437
+
1438
+ shouldComponentUpdate() {
1439
+ return false;
1440
+ }
1441
+
1442
+ render() {
1443
+ const {
1444
+ item,
1445
+ routerProps,
1446
+ getDictionarySource,
1447
+ getDictionaryTextByValue,
1448
+ timeFormat,
1449
+ transparentProps,
1450
+ } = this.props;
1451
+ return (
1452
+ <>
1453
+ {React.createElement(item.content, {
1454
+ getDictionarySource: getDictionarySource,
1455
+ getDictionaryTextByValue: getDictionaryTextByValue,
1456
+ timeFormat: timeFormat,
1457
+ ...routerProps,
1458
+ ...transparentProps,
1459
+ match: item.match,
1460
+ })}
1461
+ </>
1462
+ );
1463
+ }
1464
+ }
1465
+
1466
+ export default (props) => {
1467
+ const { initialState = {} } = useModel('@@initialState');
1468
+
1469
+ const { dictionaryData } = initialState;
1470
+ const intl = useIntl();
1471
+ const { formatMessage } = intl;
1472
+ return (
1473
+ <BasicLayout
1474
+ {...props}
1475
+ dictionaryData={dictionaryData}
1476
+ formatMessage={formatMessage}
1477
+ />
1478
+ );
1479
+ };