app.js 1.1 KB
Newer Older
1 2
// import fetch from 'dva/fetch';
import getAuthRoutesData from './mock-data/authRoutesData';
sin's avatar
sin committed
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

export const dva = {
  config: {
    onError(err) {
      err.preventDefault();
    },
  },
};

let authRoutes = {};

function ergodicRoutes(routes, authKey, authority) {
  routes.forEach(element => {
    if (element.path === authKey) {
      if (!element.authority) element.authority = []; // eslint-disable-line
      Object.assign(element.authority, authority || []);
    } else if (element.routes) {
      ergodicRoutes(element.routes, authKey, authority);
    }
    return element;
  });
}

export function patchRoutes(routes) {
  Object.keys(authRoutes).map(authKey =>
    ergodicRoutes(routes, authKey, authRoutes[authKey].authority)
  );
  window.g_routes = routes;
}

export function render(oldRender) {
34 35 36 37 38 39 40 41 42 43 44 45 46 47
  // fetch('/api/auth_routes')
  //   .then(res => res.json())
  //   .then(
  //     ret => {
  //       authRoutes = ret;
  //       oldRender();
  //     },
  //     () => {
  //       oldRender();
  //     }
  //   );

  authRoutes = getAuthRoutesData;
  oldRender();
sin's avatar
sin committed
48
}