app.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import fetch from 'dva/fetch';
  2. export const dva = {
  3. config: {
  4. onError(err) {
  5. console.error(err);
  6. err.preventDefault();
  7. },
  8. },
  9. };
  10. let authRoutes = {};
  11. function ergodicRoutes(routes, authKey, authority) {
  12. routes.forEach(element => {
  13. if (element.path === authKey) {
  14. if (!element.authority) element.authority = []; // eslint-disable-line
  15. Object.assign(element.authority, authority || []);
  16. } else if (element.routes) {
  17. ergodicRoutes(element.routes, authKey, authority);
  18. }
  19. return element;
  20. });
  21. }
  22. export function patchRoutes(routes) {
  23. Object.keys(authRoutes).map(authKey =>
  24. ergodicRoutes(routes, authKey, authRoutes[authKey].authority)
  25. );
  26. window.g_routes = routes;
  27. }
  28. export function render(oldRender) {
  29. authRoutes={
  30. '/form/advanced-form': { authority: ['admin', 'user'] },
  31. }
  32. oldRender();
  33. // fetch('/api/auth_routes')
  34. // .then(res => res.json())
  35. // .then(
  36. // ret => {
  37. // authRoutes = ret;
  38. // oldRender();
  39. // },
  40. // () => {
  41. // oldRender();
  42. // }
  43. // );
  44. }