12345678910111213141516171819202122232425 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- const { ObjectId } = require('mongoose').Types;
- const Menu = {
- title: { type: String, required: true }, // 菜单标题
- route: { type: String, required: false }, // 路由
- pid: { type: ObjectId, required: false }, // 上级id
- disabled: { type: Boolean, default: false }, // 禁用状态
- sort: { type: Number, required: false, default: 0 }, // 顺序,默认为0,使用降序排序,数值越大在前面
- can_delete: { type: Boolean, default: true }, // 可以删除
- params: { type: Object }, // 参数字段,需要就用,不需要就不用
- icon: { type: String }, // 图标
- remark: { type: String },
- };
- const schema = new Schema(Menu, {
- toJSON: { virtuals: true },
- });
- schema.index({ id: 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Menu', schema, 'menu');
- };
|