apply.js 1.2 KB

12345678910111213141516171819202122232425
  1. 'use strict';
  2. // 路由配置
  3. const routes = [
  4. { method: 'get', path: '/apply', controller: 'apply.index', name: 'applyQuery', zh: '绩效申请设置列表查询' },
  5. { method: 'get', path: '/apply/:id', controller: 'apply.show', name: 'applyFetch', zh: '绩效申请设置查询' },
  6. { method: 'post', path: '/apply', controller: 'apply.create', name: 'applyCreate', middleware: [ 'flow' ], zh: '创建绩效申请设置' },
  7. { method: 'post', path: '/apply/:id', controller: 'apply.update', name: 'applyUpdate', middleware: [ 'flow' ], zh: '修改绩效申请' },
  8. { method: 'delete', path: '/apply/:id', controller: 'apply.destroy', name: 'applyDelete', zh: '删除绩效申请' },
  9. ];
  10. module.exports = app => {
  11. const { router, config } = app;
  12. const mwares = app.middleware;
  13. for (const route of routes) {
  14. const { method, path, controller: ctl, zh } = route;
  15. let { middleware = [] } = route;
  16. if (!method || !path || !ctl) continue;
  17. // 拼全路径
  18. const allPath = `${config.routePrefix}${path}`;
  19. // 处理中间件
  20. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
  21. // 注册路由
  22. router[method](zh, allPath, ...middleware, ctl);
  23. }
  24. };