duplicate.js 1.3 KB

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