1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import lsz from "@/assets/time.gif";
import React from "react";
import config from "@/config/config";
import { formatMessage } from "umi/locale";
import { getSysConfig } from "../utils/basiclayout";
import { isJSON } from "@/webPublic/zyd_public/utils/utils";
import { getYunShangGuiZhouSyStemConfig } from '@/webPublic/one_stop_public/2023yunshangguizhou/utils';
const query = {
"screen-xs": {
maxWidth: 575
},
"screen-sm": {
minWidth: 576,
maxWidth: 767
},
"screen-md": {
minWidth: 768,
maxWidth: 991
},
"screen-lg": {
minWidth: 992,
maxWidth: 1199
},
"screen-xl": {
minWidth: 1200,
maxWidth: 1599
},
"screen-xxl": {
minWidth: 1600
}
};
const getSystemConfig = () => {
const urlParams = new URL(window.location.href);
const systemList = ["/xg/", "/yx/", "/jy/", "/lx/", "/sg/", "/xl/", "/zs/", "/uaa/", "/tw/", "/ytw/", "/wzb/", "/szcp/"];
let findSystem = systemList.find((g) => {
return urlParams.href.indexOf(g) > 0;
});
if (findSystem) {
let systemX = findSystem.replace(/[/]/g, "");
let res = config.systems[systemX];
let systemDiyName = localStorage.getItem('systemDiyName');
res.name = systemDiyName || res.name;
return res;
}
return config.systems["jc"];
};
const antIcon =
<div style={
{
position: "absolute",
zIndex: 999999,
width: 32,
left: "48%"
}}>
<img src={lsz}
style={{ width: 32, height: 32 }} />
</div>;
const formatter = (data, parentPath = "", parentAuthority, parentName) => {
return data.map(item => {
if (config.checkPath) {
item.authority = [item.path];
}
let locale = "menu";
if (parentName && item.name) {
locale = `${parentName}.${item.name}`;
} else if (item.name) {
locale = `menu.${item.name}`;
} else if (parentName) {
locale = parentName;
}
const result = {
...item,
locale,
authority: item.authority || parentAuthority
};
if (item.routes) {
const children = formatter(item.routes, `${parentPath}${item.path}/`, item.authority, locale);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
});
};
const getMenuData = (routes) => {
const newRoutes = formatter(routes);
return newRoutes;
};
// 插入动态菜单
const insertActiveMenus = (routes = [], insertRoutes = []) => {
let deleteIndex = [];
if (!insertRoutes || !insertRoutes.length) {
return routes;
}
for (let i = 0; i < routes.length; i++) {
let item = routes[i];
for (let g = 0; g < insertRoutes.length; g++) {
let targetItem = insertRoutes[g];
if (targetItem.oldBrotherPath && targetItem.oldBrotherPath === item.path) { // 发现哥哥节点 插入
// console.log(targetItem);
routes.splice(i + 1, 0, targetItem);
deleteIndex.push(g);
}
if (targetItem.parentPath === item.path && !targetItem.oldBrotherPath) { // 没有哥哥节点的路由 插入
if (item.children) {
item.children.unshift(targetItem);
} else {
item.children = [targetItem];
}
deleteIndex.push(g);
}
}
if (deleteIndex.length) {
for(let i = 0; i < insertRoutes.length; i++){
if(deleteIndex.includes(i)){
insertRoutes[i].isDelete = true;
}
}
insertRoutes = insertRoutes.filter((g) =>{
return !g.isDelete;
});
deleteIndex = []; // 每次循环完 要清空这个 才行. 不然递归里面会删除多的
}
if (Array.isArray(item.children) && item.children.length) {
insertActiveMenus(item.children, insertRoutes);
}
}
return routes;
};
export { antIcon, query, getSystemConfig, formatter, getMenuData, insertActiveMenus, getYunShangGuiZhouSyStemConfig };
export const getDiyChineseMenus = () => {
const menuChineseConfig = getSysConfig().menuChineseConfig;
const menusList = isJSON(menuChineseConfig) && JSON.parse(menuChineseConfig) || {};
return menusList;
}
export const getChineseName = (item) => { // 获取菜单名字
if(!item){
return '';
}
const menusList = getDiyChineseMenus();
if (menusList[item.path]) {
return menusList[item.path];
}
const menuName = item.chineseLocale || formatMessage({ id: item.locale });
return menuName;
};
export const insertDetailPath = (res = []) => { // 插入详情路由
for(let item of res){
if(item.from === 'onestopApp'
&& (item.component.indexOf('Audit') > -1 || item.component.indexOf('Apply') > -1)
){ // 插入详情路由
const pathSplit = item.path.split('/');
pathSplit[pathSplit.length -1] = 'Detail';
const pathDetail = pathSplit.join('/');
// console.log(pathDetail);
let checkHaveDetail = res.find((g) => {
return g.path === pathDetail;
});
if(!checkHaveDetail){
// console.log(item);
res.push({
...item,
chineseLocale: '详情',
name: '详情',
component: 'Detail',
path: pathDetail,
id: Math.random(),
hideInMenu: '1',
});
}
}
}
return res;
}
export const giveAuthority = (res = []) => {
for(let item of res){
item.authority = [item.path];
item.hideInMenu = item.hideInMenu === '1';
item.exact = true;
if(item.component === 'Parent'){
item.children = [];
}
}
return res;
}