template.js 1.4 KB

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. // 路由配置
  3. const mainKey = 'template';
  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. { method: 'post', path: `/${mainKey}/toUse/:id`, controller: `${mainKey}.toUse`, name: `${mainKey}toUse`, zh: `设置${keyZh}为使用` },
  12. ];
  13. module.exports = app => {
  14. const { router, config } = app;
  15. const mwares = app.middleware;
  16. for (const route of routes) {
  17. const { method, path, controller: ctl, zh } = route;
  18. let { middleware = [] } = route;
  19. if (!method || !path || !ctl) continue;
  20. // 拼全路径
  21. const allPath = `${config.routePrefix}${path}`;
  22. // 处理中间件
  23. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
  24. // 注册路由
  25. router[method](zh, allPath, ...middleware, ctl);
  26. }
  27. };