organization.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. // 路由配置
  3. const rkey = 'organization';
  4. const ckey = 'user.organization';
  5. const keyZh = '机构管理(o)';
  6. const routes = [
  7. { method: 'post', path: `${rkey}/wxLogin`, controller: `${ckey}.wxLogin`, name: `${ckey}WxLogin`, zh: `${keyZh}微信登陆` },
  8. { method: 'post', path: `${rkey}/bindRemove`, controller: `${ckey}.bindRemove`, name: `${ckey}BindRemove`, zh: `${keyZh}微信解绑` },
  9. { method: 'post', path: `${rkey}/bind`, controller: `${ckey}.bind`, name: `${ckey}Bind`, zh: `${keyZh}微信绑定` },
  10. { method: 'get', path: `${rkey}/getList`, controller: `${ckey}.getList`, name: `${ckey}GetList`, zh: `${keyZh}获取微信列表` },
  11. { method: 'post', path: `${rkey}/login`, controller: `${ckey}.login`, name: `${ckey}Login`, zh: `${keyZh}登陆` },
  12. { method: 'post', path: `${rkey}/password/:id`, controller: `${ckey}.password`, name: `${ckey}Password`, zh: `${keyZh}修改密码` },
  13. { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
  14. { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
  15. { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
  16. { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
  17. { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
  18. ];
  19. module.exports = app => {
  20. const { router, config } = app;
  21. const mwares = app.middleware;
  22. console.log(`${keyZh}: ${rkey}`);
  23. for (const route of routes) {
  24. const { method, path, controller: ctl, zh } = route;
  25. let { middleware = [] } = route;
  26. if (!method || !path || !ctl) continue;
  27. // 拼全路径
  28. const allPath = `${config.routePrefix}/${path}`;
  29. // 处理中间件
  30. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
  31. // 注册路由
  32. router[method](zh, allPath, ...middleware, ctl);
  33. }
  34. };