menu.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. parent_id: { type: String, required: false, maxLength: 64 }, // 父级ID
  16. parent_name: { type: String, required: false, maxLength: 64 }, // 父级名称
  17. level: { type: String, required: false, maxLength: 5 }, // 层级
  18. path: { type: String, required: false, maxLength: 500 }, // 路径
  19. position: { type: Number, required: false, maxLength: 5 }, // 位置
  20. name: { type: String, required: false, maxLength: 100 }, // 菜单名称
  21. picurl: { type: String, required: false, maxLength: 256 }, // 栏目图片URL
  22. description: { type: String, required: false, maxLength: 256 }, // 栏目描述
  23. isShow: { type: String, required: false, maxLength: 5 }, // 是否需要审核
  24. // attachment: [ Attachment ], // 附件
  25. issuer: String, // 栏目单位
  26. meta: {
  27. createdBy: String, // 创建用户
  28. updatedBy: String, // 修改用户
  29. },
  30. remark: { type: String, maxLength: 500 }, // 备注
  31. };
  32. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  33. schema.plugin(metaPlugin);
  34. schema.index({ column: 1 });
  35. schema.index({ 'meta.state': 1 });
  36. schema.index({ 'meta.createdAt': -1 });
  37. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  38. module.exports = app => {
  39. const { mongoose } = app;
  40. return mongoose.model('MenuInfo', schema, 'cms_menu');
  41. };