index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const { Router } = require('express');
  2. const gaf = require('./gaf');
  3. const user = require('./user');
  4. const log = require('./log');
  5. const app = require('./app');
  6. const authorize = require('./authorize');
  7. const policy = require('./policy');
  8. const link = require('./link');
  9. const register = require('./register');
  10. const cred = require('./cred');
  11. const journal = require('./journal');
  12. const dev = require('./dev');
  13. const terminal = require('./terminal');
  14. const router = Router();
  15. const navDatas = [
  16. {
  17. title: '用户管理',
  18. path: '/xms',
  19. module: '@user',
  20. },
  21. {
  22. title: '终端管理',
  23. path: '/xms',
  24. module: '@terminal',
  25. },
  26. {
  27. title: '用户审核',
  28. path: '/xms/',
  29. module: '@register',
  30. },
  31. {
  32. title: '授权管理',
  33. path: '/xms',
  34. module: '@auth',
  35. },
  36. {
  37. title: '凭证管理',
  38. path: '/xms',
  39. module: '@cred',
  40. },
  41. {
  42. title: '凭证设备',
  43. path: '/xms',
  44. module: '@dev',
  45. },
  46. {
  47. title: '应用管理',
  48. path: '/xms',
  49. module: '@app',
  50. },
  51. {
  52. title: '策略管理',
  53. path: '/xms',
  54. module: '@policy',
  55. },
  56. {
  57. title: '用户审计',
  58. path: '/log/audit/logon',
  59. module: '@log',
  60. },
  61. {
  62. title: '责任认定',
  63. path: '/log/audit/duty',
  64. module: '@log',
  65. },
  66. {
  67. title: '日志审计',
  68. path: '/log/query/c1',
  69. module: '@log',
  70. },
  71. {
  72. title: '系统管理',
  73. path: '/gaf',
  74. module: '@gaf',
  75. },
  76. // ...link,
  77. ];
  78. const home = [
  79. {
  80. title: '工作台',
  81. path: '/xms/dashboard',
  82. icon: 'home',
  83. module: '@user',
  84. },
  85. ];
  86. const transItems = (items, pid) =>
  87. items.map((p, i) => {
  88. p.pid = pid || '0';
  89. p.id = p.id || (pid ? `${pid}-${i + 1}` : `${i + 1}`);
  90. if (p.children && p.children.length > 0) p.children = transItems(p.children, p.id);
  91. return p;
  92. });
  93. const datas = transItems([...home, ...user, ...terminal, ...register, ...authorize, ...cred, ...dev, ...app, ...policy, ...log, ...journal, ...gaf]);
  94. const MapMenu = (catalog = [], module = undefined) => item => ({
  95. title: item.title,
  96. options: {
  97. icon: item.icon,
  98. path: `/${item.module || module}${item.path}`,
  99. url: item.url,
  100. target: item.target,
  101. tooltip: item.tooltip,
  102. module: item.module,
  103. platform: item.platform,
  104. roles: item.roels,
  105. tags: item.tags,
  106. meta: { catalog: catalog.concat(item.title) },
  107. },
  108. children: (item.children || []).map(MapMenu(catalog.concat(item.title), item.module || module)),
  109. });
  110. const menus = datas.map(MapMenu());
  111. const modules = navDatas.map(MapMenu());
  112. /* GET menus define. */
  113. router.get('/menu/load', function(req, res, next) {
  114. console.log("!!!I'm menu/load!!!");
  115. res.json({ errcode: 0, errmsg: 'ok', data: { items: menus, modules } });
  116. });
  117. // router.get('/menu/:module', function(req, res, next) {
  118. // const module = req.params.module;
  119. // const items = menus.filter(p => p.options.module == module);
  120. // res.json({ errcode: 0, errmsg: 'ok', data: { items, modules } });
  121. // });
  122. router.get('/menu/items', function(req, res, next) {
  123. res.json({ errcode: 0, errmsg: 'ok', data: datas });
  124. });
  125. router.get('/menu/menus', function(req, res, next) {
  126. res.json({ errcode: 0, errmsg: 'ok', data: navDatas });
  127. });
  128. router.get('/menu/:module/items', function(req, res, next) {
  129. const module = req.params.module;
  130. const items = datas.filter(p => p.options.module == module);
  131. res.json({ errcode: 0, errmsg: 'ok', data: items });
  132. });
  133. module.exports = router;