董国庆
91 分钟以前 b3a05a5f241b008599f00070b0086feb46330a15
management/src/utils/utils.js
@@ -1,5 +1,4 @@
// 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 */
@@ -58,7 +57,7 @@
      ...params,
    }),
    headers: {
      Authorization: localStorage.getItem('token'),
      Authorization:'Bearer ' +  localStorage.getItem('token'),
      'ConTent-Type': 'application/json;charset=UTF-8',
      timestamp: new Date().getTime(),
      client: localStorage.getItem('client')
@@ -86,7 +85,7 @@
    method: 'get',
    responseType: 'blob',
    headers: {
      Authorization: localStorage.getItem('token'),
      Authorization:'Bearer ' + localStorage.getItem('token'),
      'ConTent-Type': 'application/json;charset=UTF-8',
      timestamp: new Date().getTime(),
      client: localStorage.getItem('client')
@@ -120,32 +119,3 @@
    })
    .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;
};