menu.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 Attachment = new Schema({
  9. name: { type: String, maxLength: 128 },
  10. uri: { type: String, maxLength: 128 },
  11. }, { _id: false });
  12. // 栏目信息
  13. const SchemaDefine = {
  14. site: { type: String, required: true, maxLength: 64 }, // 归属站点
  15. parentId: { type: String, required: false, maxLength: 64 }, // 父级ID
  16. name: { type: String, required: true, maxLength: 100 }, // 菜单名称
  17. picurl: { type: String, required: false, maxLength: 256 }, // 栏目图片URL
  18. description: { type: String, required: false, maxLength: 256 }, // 栏目描述
  19. isShow: { type: String, required: false, maxLength: 5 }, // 是否需要审核
  20. attachment: [ Attachment ], // 附件
  21. issuer: String, // 栏目单位
  22. meta: {
  23. createdBy: String, // 创建用户
  24. updatedBy: String, // 修改用户
  25. },
  26. remark: { type: String, maxLength: 500 }, // 备注
  27. };
  28. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  29. schema.plugin(metaPlugin);
  30. schema.index({ column: 1 });
  31. schema.index({ 'meta.state': 1 });
  32. schema.index({ 'meta.createdAt': -1 });
  33. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  34. module.exports = app => {
  35. const { mongoose } = app;
  36. return mongoose.model('MenuInfo', schema, 'cms_menu');
  37. };