app.js 936 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. fetch('/api/auth_routes')
  29. .then(res => res.json())
  30. .then(
  31. ret => {
  32. authRoutes = ret;
  33. oldRender();
  34. },
  35. () => {
  36. oldRender();
  37. }
  38. );
  39. }