app.js 1.0 KB

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