commonUtils.js
1.3 KB
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
import store from '../redux/store';
/*
*key转小写
*/
export const typeToLowerCase = (type) => {
if (type && typeof (type) === 'string') {
return type.toLowerCase();
} else {
return type;
}
};
/*
*reducer生成方法
*/
export const reducerFactory = (state = {}, action = {}) => {
const { payload, type } = action;
if (state && state.hasOwnProperty(typeToLowerCase(type))) {
return { ...state, [typeToLowerCase(type)]: payload };
} else {
return state;
}
};
export const dispatch = (action) => {
return store.dispatch(action);
};
/*
*修改路由
*/
export const pushRoute = (url) => {
document.location.href = `#${url}`;
};
/*
获取当前选中的菜单
*/
export const getSystemSelect = (pathname, perms) => {
let moduleName = '', openKeys = [], selectedKeys = [];
if (pathname && pathname.indexOf('/main/') != -1 && pathname.split("/").length > 2) {
const pathArray = pathname.split("/");
moduleName = pathArray[2];
}
perms.map((perm, i) => {
if (perm.module == moduleName) {
selectedKeys = [moduleName];
if (perm.parent_module) {
openKeys = [perm.parent_module];
}
}
});
return {
openKeys,
selectedKeys
};
};