'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose/lib/model/schema'); const { ObjectId } = require('mongoose').Types; // 系统管理员表 const admin = { name: { type: String, default: '管理员' }, // 昵称 login_id: { type: String }, // 登陆用户名 password: { type: Secret, select: false }, // 密码 menu: { type: Array }, // 菜单(管理员默认全有),如果里面不为空,或者有内容了,就按内容换菜单 is_root: { type: Boolean, default: false }, // 为之后用,这个管理员是不是拥有最高权限:可不可以更改菜单或者其他操作 openid: { type: String }, // 微信openid remark: { type: String }, }; const schema = new Schema(admin, { 'multi-tenancy': true, toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ name: 1 }); schema.index({ login_id: 1 }); schema.index({ is_root: 1 }); schema.index({ openid: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Admin', schema, 'admin'); };