menu.js 1.0 KB

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const Menu = {
  5. project: { type: String, required: true, maxLength: 200 }, // 项目名
  6. title: { type: String, required: true }, // 菜单标题
  7. route: { type: String, required: false, maxLength: 200 }, // 路由
  8. pid: { type: String, required: false, maxLength: 200 }, // 上级id
  9. disabled: { type: Boolean, default: false }, // 使用状态
  10. sort: { type: Number, required: false, default: 0 }, // 顺序,默认为0,使用降序排序,数值越大在前面
  11. params: { type: Object }, // 参数字段,需要就用,不需要就不用
  12. type: { type: String, required: false, maxLength: 200 }, // 类型,每个项目有每个项目的设置,这里只存储,让各自项目记住自己类型对应什么
  13. };
  14. const schema = new Schema(Menu, { toJSON: { virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('Menu', schema, 'menu');
  20. };