12345678910111213141516171819202122232425 |
- 'use strict';
- // 路由配置
- const routes = [
- { method: 'get', path: '/apply', controller: 'apply.index', name: 'applyQuery', zh: '绩效申请设置列表查询' },
- { method: 'get', path: '/apply/:id', controller: 'apply.show', name: 'applyFetch', zh: '绩效申请设置查询' },
- { method: 'post', path: '/apply', controller: 'apply.create', name: 'applyCreate', middleware: [ 'flow' ], zh: '创建绩效申请设置' },
- { method: 'post', path: '/apply/:id', controller: 'apply.update', name: 'applyUpdate', middleware: [ 'flow' ], zh: '修改绩效申请' },
- { method: 'delete', path: '/apply/:id', controller: 'apply.destroy', name: 'applyDelete', zh: '删除绩效申请' },
- ];
- module.exports = app => {
- const { router, config } = app;
- const mwares = app.middleware;
- for (const route of routes) {
- const { method, path, controller: ctl, zh } = route;
- let { middleware = [] } = route;
- if (!method || !path || !ctl) continue;
- // 拼全路径
- const allPath = `${config.routePrefix}${path}`;
- // 处理中间件
- if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
- // 注册路由
- router[method](zh, allPath, ...middleware, ctl);
- }
- };
|