guhongwei 2 년 전
부모
커밋
ac95e868bd
6개의 변경된 파일142개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      app/controller/appapk.js
  2. 56 0
      app/controller/config/.appapk.js
  3. 29 0
      app/model/appapk.js
  4. 1 0
      app/router.js
  5. 15 0
      app/service/appapk.js
  6. 28 0
      app/z_router/appapk.js

+ 13 - 0
app/controller/appapk.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.appapk.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 应用管理
+class AppapkController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.appapk;
+  }
+}
+module.exports = CrudController(AppapkController, meta);

+ 56 - 0
app/controller/config/.appapk.js

@@ -0,0 +1,56 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "title",
+      "origin",
+      "create_time",
+      "img_url",
+      "web_url",
+      "is_use",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "title",
+      "origin",
+      "create_time",
+      "img_url",
+      "web_url",
+      "is_use",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        title: "title",
+        origin: "origin",
+        create_time: "create_time",
+        web_url: "web_url",
+        is_use: "is_use",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 29 - 0
app/model/appapk.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 应用管理
+const appapk = {
+  title: { type: String, required: false, zh: '名称' }, //
+  origin: { type: String, required: false, zh: '来源' }, //
+  create_time: { type: String, required: false, default: '系统管理员', zh: '时间' }, //
+  img_url: { type: Array, required: false, zh: '图片' }, //
+  web_url: { type: String, required: false, zh: '平台网址' }, //
+  is_use: { type: String, required: false, default: '0', zh: '是否启用' }, //
+};
+const schema = new Schema(appapk, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ title: 1 });
+schema.index({ origin: 1 });
+schema.index({ create_time: 1 });
+schema.index({ web_url: 1 });
+schema.index({ is_use: 1 });
+schema.index({ 'meta.createdAt': 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Appapk', schema, 'appapk');
+};

+ 1 - 0
app/router.js

@@ -22,4 +22,5 @@ module.exports = app => {
   require('./z_router/appbasic')(app); // app基本信息
   require('./z_router/appbanner')(app); // app轮播图
   require('./z_router/hotlink')(app); // 热门链接
+  require('./z_router/appapk')(app); // 应用管理
 };

+ 15 - 0
app/service/appapk.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 应用管理
+class AppapkService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'appapk');
+    this.model = this.ctx.model.Appapk;
+  }
+}
+
+module.exports = AppapkService;

+ 28 - 0
app/z_router/appapk.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'appapk'; // routerKey,路由前缀变量
+const cKey = 'appapk'; // controllerKey,controller名
+const zhKey = '应用管理';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+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);
+  }
+};