You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
674 B
31 lines
674 B
/* eslint-disable func-names */
|
|
// import { history } from 'umi';
|
|
|
|
function checkArrayForPrefix(arr, value) {
|
|
if (!arr || !value) {
|
|
return false;
|
|
}
|
|
for (let i = 0; i < arr.length; i++) {
|
|
if (value.startsWith(arr[i])) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export default function (initialState = {}) {
|
|
const { menus, apis } = initialState;
|
|
return {
|
|
authRouteFilter: (route) => {
|
|
const hasRoute = checkArrayForPrefix(
|
|
menus?.map((item) => item.path),
|
|
route.path,
|
|
);
|
|
return hasRoute;
|
|
},
|
|
authActionFilter: (auth) => {
|
|
const hasAction = apis?.includes(auth);
|
|
return hasAction;
|
|
},
|
|
};
|
|
}
|
|
|