patent.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. // 路由配置
  3. const rkey = 'patent';
  4. const ckey = 'dock.patent';
  5. const keyZh = '专利';
  6. const routes = [
  7. { method: 'post', path: `${rkey}/import`, controller: `${ckey}.toImport`, name: `${ckey}import`, zh: `${keyZh}导入` },
  8. { method: 'post', path: `${rkey}/export`, controller: `${ckey}.toExport`, name: `${ckey}export`, zh: `${keyZh}导出` },
  9. { method: 'get', path: `${rkey}/getByCN/:create_number`, controller: `${ckey}.getByCN`, name: `${ckey}getByCN`, zh: `查询${keyZh}-由申请号获取` },
  10. { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
  11. { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
  12. { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
  13. { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
  14. { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
  15. ];
  16. module.exports = app => {
  17. const { router, config } = app;
  18. const mwares = app.middleware;
  19. console.log(`${keyZh}: ${rkey}`);
  20. for (const route of routes) {
  21. const { method, path, controller: ctl, zh } = route;
  22. let { middleware = [] } = route;
  23. if (!method || !path || !ctl) continue;
  24. // 拼全路径
  25. const allPath = `${config.routePrefix}/${path}`;
  26. // 处理中间件
  27. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
  28. // 注册路由
  29. router[method](zh, allPath, ...middleware, ctl);
  30. }
  31. };