| | |
| | | // import { getToken } from '@/utils/authority'; |
| | | import pathRegexp from 'path-to-regexp'; |
| | | import { parse } from 'querystring'; |
| | | import { uploadFile } from './service' |
| | | /* eslint no-useless-escape:0 import/prefer-default-export:0 */ |
| | |
| | | }) |
| | | .catch(error => console.error('Error downloading file:', error)); |
| | | } |
| | | export const getAuthorityFromRouter = (router = [], pathname) => { |
| | | const authority = router.find( |
| | | ({ routes, path = '/' }) => |
| | | (path && pathRegexp(path).exec(pathname)) || |
| | | (routes && getAuthorityFromRouter(routes, pathname)), |
| | | ); |
| | | if (authority) return authority; |
| | | return undefined; |
| | | }; |
| | | export const getRouteAuthority = (path, routeData) => { |
| | | let authorities; |
| | | routeData.forEach((route) => { |
| | | // match prefix |
| | | if (pathRegexp(`${route.path}/(.*)`).test(`${path}/`)) { |
| | | if (route.authority) { |
| | | authorities = route.authority; |
| | | } // exact match |
| | | |
| | | if (route.path === path) { |
| | | authorities = route.authority || authorities; |
| | | } // get children authority recursively |
| | | |
| | | if (route.routes) { |
| | | authorities = getRouteAuthority(path, route.routes) || authorities; |
| | | } |
| | | } |
| | | }); |
| | | return authorities; |
| | | }; |