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