|
@@ -0,0 +1,28 @@
|
|
|
+'use strict';
|
|
|
+// 路由配置
|
|
|
+const mainKey = 'template';
|
|
|
+const keyZh = '绩效模板';
|
|
|
+const routes = [
|
|
|
+ { method: 'get', path: `/${mainKey}`, controller: `${mainKey}.index`, name: `${mainKey}Query`, zh: `${keyZh}设置列表查询` },
|
|
|
+ { method: 'get', path: `/${mainKey}/:id`, controller: `${mainKey}.show`, name: `${mainKey}Fetch`, zh: `${keyZh}设置查询` },
|
|
|
+ { method: 'post', path: `/${mainKey}`, controller: `${mainKey}.create`, name: `${mainKey}Create`, zh: `创建${keyZh}设置` },
|
|
|
+ { method: 'post', path: `/${mainKey}/:id`, controller: `${mainKey}.update`, name: `${mainKey}Update`, zh: `修改${keyZh}` },
|
|
|
+ { method: 'delete', path: `/${mainKey}/:id`, controller: `${mainKey}.destroy`, name: `${mainKey}Delete`, zh: `删除${keyZh}` },
|
|
|
+ { method: 'post', path: `/${mainKey}/toUse/:id`, controller: `${mainKey}.toUse`, name: `${mainKey}toUse`, zh: `设置${keyZh}为使用` },
|
|
|
+];
|
|
|
+
|
|
|
+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);
|
|
|
+ }
|
|
|
+};
|