index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const { Router } = require('express');
  2. const gaf = require('./gaf');
  3. const user = require('./user');
  4. const app = require('./app');
  5. const authorize = require('./authorize');
  6. const link = require('./link');
  7. const router = Router();
  8. const navDatas = [
  9. {
  10. title: '用户管理',
  11. path: '/xms',
  12. module: '@user',
  13. },
  14. {
  15. title: '授权管理',
  16. path: '/xms',
  17. module: '@authorize',
  18. },
  19. {
  20. title: '应用管理',
  21. path: '/xms',
  22. module: '@app',
  23. },
  24. {
  25. title: '系统管理',
  26. path: '/gaf',
  27. module: '@gaf',
  28. },
  29. // ...link,
  30. ];
  31. const transItems = (items, pid) =>
  32. items.map((p, i) => {
  33. p.pid = pid || '0';
  34. p.id = p.id || (pid ? `${pid}-${i + 1}` : `${i + 1}`);
  35. if (p.children && p.children.length > 0) p.children = transItems(p.children, p.id);
  36. return p;
  37. });
  38. const datas = transItems([...user, ...authorize, ...app, ...gaf]);
  39. const MapMenu = (catalog = [], module = undefined) => item => ({
  40. title: item.title,
  41. options: {
  42. icon: item.icon,
  43. path: `/${item.module || module}${item.path}`,
  44. url: item.url,
  45. target: item.target,
  46. tooltip: item.tooltip,
  47. module: item.module,
  48. platform: item.platform,
  49. roles: item.roels,
  50. tags: item.tags,
  51. meta: { catalog: catalog.concat(item.title) },
  52. },
  53. children: (item.children || []).map(MapMenu(catalog.concat(item.title), item.module || module)),
  54. });
  55. const menus = datas.map(MapMenu());
  56. const modules = navDatas.map(MapMenu());
  57. /* GET menus define. */
  58. router.get('/menu/load', function(req, res, next) {
  59. console.log("!!!I'm menu/load!!!");
  60. res.json({ errcode: 0, errmsg: 'ok', data: { items: menus, modules } });
  61. });
  62. // router.get('/menu/:module', function(req, res, next) {
  63. // const module = req.params.module;
  64. // const items = menus.filter(p => p.options.module == module);
  65. // res.json({ errcode: 0, errmsg: 'ok', data: { items, modules } });
  66. // });
  67. router.get('/menu/items', function(req, res, next) {
  68. res.json({ errcode: 0, errmsg: 'ok', data: datas });
  69. });
  70. router.get('/menu/menus', function(req, res, next) {
  71. res.json({ errcode: 0, errmsg: 'ok', data: navDatas });
  72. });
  73. router.get('/menu/:module/items', function(req, res, next) {
  74. const module = req.params.module;
  75. const items = datas.filter(p => p.options.module == module);
  76. res.json({ errcode: 0, errmsg: 'ok', data: items });
  77. });
  78. module.exports = router;