app.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. window.test = () => {
  11. console.log(1)
  12. }
  13. function ergodicRoutes(routes, authKey, authority) {
  14. routes.forEach(element => {
  15. if (element.path === authKey) {
  16. if (!element.authority) element.authority = []; // eslint-disable-line
  17. Object.assign(element.authority, authority || []);
  18. } else if (element.routes) {
  19. ergodicRoutes(element.routes, authKey, authority);
  20. }
  21. return element;
  22. });
  23. }
  24. export function patchRoutes(routes) {
  25. Object.keys(authRoutes).map(authKey =>
  26. ergodicRoutes(routes, authKey, authRoutes[authKey].authority)
  27. );
  28. window.g_routes = routes;
  29. }
  30. export function render(oldRender) {
  31. authRoutes={
  32. '/form/advanced-form': { authority: ['admin', 'user'] },
  33. }
  34. oldRender();
  35. // fetch('/api/auth_routes')
  36. // .then(res => res.json())
  37. // .then(
  38. // ret => {
  39. // authRoutes = ret;
  40. // oldRender();
  41. // },
  42. // () => {
  43. // oldRender();
  44. // }
  45. // );
  46. }