menu.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * 栏目信息
  3. */
  4. 'use strict';
  5. const Schema = require('mongoose').Schema;
  6. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  7. // 栏目信息
  8. const SchemaDefine = {
  9. site: { type: String, required: true, maxLength: 64 }, // 归属站点
  10. parentId: { type: String, required: true, maxLength: 64 }, // 父级ID
  11. name: { type: String, required: true, maxLength: 100 }, // 菜单名称
  12. picurl: { type: String, required: false, maxLength: 256 }, // 栏目图片URL
  13. sort: [{ type: Number, maxLength: 5 }], // 排序
  14. description: { type: String, required: false, maxLength: 256 }, // 栏目描述
  15. isShow: { type: String, required: false, maxLength: 5 }, // 是否需要审核
  16. issuer: String, // 栏目单位
  17. meta: {
  18. createdBy: String, // 创建用户
  19. updatedBy: String, // 修改用户
  20. },
  21. remark: { type: String, maxLength: 500 }, // 备注
  22. };
  23. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  24. schema.plugin(metaPlugin);
  25. schema.index({ column: 1 });
  26. schema.index({ 'meta.state': 1 });
  27. schema.index({ 'meta.createdAt': -1 });
  28. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  29. module.exports = app => {
  30. const { mongoose } = app;
  31. return mongoose.model('MenuInfo', schema, 'cms_menu');
  32. };