menu.js 1.2 KB

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const Menu = {
  5. title: { type: String, required: true, zh: '目录标题', row: 2 }, // 菜单标题
  6. route: { type: String, required: false, maxLength: 200, zh: '路由地址', row: 3 }, // 路由
  7. pid: { type: String, required: false, maxLength: 200, zh: '所属上级', options: { custom: true }, row: 1 }, // 上级id
  8. disabled: { type: Boolean, default: false, zh: '使用状态', options: { type: 'radio', list: [{ label: '使用', value: false }, { label: '禁用', value: true }] }, row: 4 }, // 使用状态
  9. sort: { type: Number, required: false, default: 0, zh: '顺序', options: { type: 'number', remark: '倒序排列,数值大的排在前面' }, row: 5 }, // 顺序,默认为0,使用降序排序,数值越大在前面
  10. params: { type: Object }, // 参数字段,需要就用,不需要就不用
  11. };
  12. const schema = new Schema(Menu, {
  13. 'multi-tenancy': true,
  14. toJSON: { virtuals: true },
  15. });
  16. schema.index({ id: 1 });
  17. schema.plugin(metaPlugin);
  18. schema.index({ _tenant: 1 });
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Menu', schema, 'menu');
  22. };