guhongwei 2 年 前
コミット
f6eb46db7b

+ 13 - 0
app/controller/appbasic.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.appbasic.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// app基本信息
+class AppbasicController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.appbasic;
+  }
+}
+module.exports = CrudController(AppbasicController, meta);

+ 38 - 0
app/controller/config/.appbasic.js

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

+ 22 - 0
app/model/appbasic.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// app基本信息
+const appbasic = {
+  name: { type: String, required: false, zh: '名称' }, //
+  logo_url: { type: Array, required: false, zh: 'logo' }, //
+  foot_menus: { type: Array, required: false, zh: '底部菜单' }, //
+};
+const schema = new Schema(appbasic, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ name: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Appbasic', schema, 'appbasic');
+};

+ 3 - 1
app/router.js

@@ -11,10 +11,12 @@ module.exports = app => {
   require('./z_router/program')(app); // 节目表
   require('./z_router/dicttype')(app); // 字典类型表
   require('./z_router/dictdata')(app); // 字典数据表
-
+  // web
   require('./z_router/company')(app); // 公司信息
   require('./z_router/banner')(app); // 轮播图
   require('./z_router/news')(app); // 新闻资讯
   require('./z_router/cases')(app); // 案例
   require('./z_router/leavemess')(app); // 留言
+  // app
+  require('./z_router/appbasic')(app); // app基本信息
 };

+ 23 - 0
app/service/appbasic.js

@@ -0,0 +1,23 @@
+'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');
+
+// app基本信息
+class AppbasicService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'appbasic');
+    this.model = this.ctx.model.Appbasic;
+  }
+  async query({ ...info }) {
+    let res = {};
+    const data = await this.model.findOne({ ...info });
+    if (data) {
+      res = data;
+    }
+    return res;
+  }
+}
+
+module.exports = AppbasicService;

+ 28 - 0
app/z_router/appbasic.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'appbasic'; // routerKey,路由前缀变量
+const cKey = 'appbasic'; // controllerKey,controller名
+const zhKey = 'app基本信息';
+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);
+  }
+};