admin.js 1.2 KB

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