menu.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. title: { type: String, required: false, maxLength: 100 }, // 菜单名称
  16. type: { type: String, required: false, maxLength: 5 }, // :类型,'content'=>信息内容类型/'column'=>'栏目',
  17. is_use: { type: String, required: false, maxLength: 5 }, // 是否使用,0=>使用中;1=>已禁止
  18. url: String, // 外部链接
  19. content_id: { type: String, required: false, maxLength: 64 }, // 信息Id
  20. meta: {
  21. createdBy: String, // 创建用户
  22. updatedBy: String, // 修改用户
  23. },
  24. // remark: { type: String, maxLength: 500 }, // 备注
  25. };
  26. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  27. schema.plugin(metaPlugin);
  28. schema.index({ site: 1 });
  29. schema.index({ 'meta.state': 1 });
  30. schema.index({ 'meta.createdAt': -1 });
  31. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  32. module.exports = app => {
  33. const { mongoose } = app;
  34. return mongoose.model('MenuInfo', schema, 'cms_menu');
  35. };