base.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. /**
  3. * [autoCreateRouter 自动创建路由]
  4. * @param {[type]} routerName [description]
  5. * @param {[type]} path [description]
  6. * @param {Array} params [description]
  7. * @return {[type]} [description]
  8. */
  9. const autoCreateRouter = function(namespaceRouter, path, actionController, params = [ 'get', 'post', 'put', 'delete' ], others = { get: 'select', post: 'create', put: 'update', delete: 'delete' }) {
  10. params.forEach(item => {
  11. namespaceRouter[item](path, actionController[others[item]]);
  12. });
  13. };
  14. /**
  15. * [框架基本路由]
  16. * @author szjcomo
  17. * @date 2021-05-25
  18. * @param {[type]} app [description]
  19. * @param {[type]} managerRouter [description]
  20. * @return {[type]} [description]
  21. */
  22. module.exports = (app, managerRouter) => {
  23. const manager = app.controller.manager;
  24. // 获取控制台数据
  25. autoCreateRouter(managerRouter, '/console', manager.login, [ 'get' ], { get: 'manager' });
  26. // 管理员数据接口
  27. autoCreateRouter(managerRouter, '/admin_user', manager.adminUser);
  28. // 管理员角色数据接口
  29. autoCreateRouter(managerRouter, '/roles', manager.roles);
  30. // 获取角色权限接口
  31. autoCreateRouter(managerRouter, '/roles/auth', manager.roles, [ 'get', 'post' ], { get: 'getRoleAuth', post: 'roleAuth' });
  32. // 权限节点接口
  33. autoCreateRouter(managerRouter, '/accesss', manager.accesss);
  34. // 配置操作接口
  35. autoCreateRouter(managerRouter, '/configs', manager.configs);
  36. // 配置设置接口
  37. autoCreateRouter(managerRouter, '/configs/setting', manager.configs, [ 'post' ], { post: 'setting' });
  38. // 文章操作接口
  39. autoCreateRouter(managerRouter, '/articles', manager.articles);
  40. // 文章分数接口
  41. autoCreateRouter(managerRouter, '/articles/category', manager.articlesCategory);
  42. };