img.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * 图片信息
  3. */
  4. 'use strict';
  5. const Schema = require('mongoose').Schema;
  6. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  7. // 图片信息
  8. const SchemaDefine = {
  9. site: { type: String, required: true, maxLength: 64 }, // 归属站点
  10. title: { type: String, required: false, maxLength: 100 }, // 图片名称
  11. type: { type: String, required: false, maxLength: 5 }, // 图片类型
  12. pic: { type: String, required: false, maxLength: 200 }, // 图片地址
  13. url: { type: String, required: false, maxLength: 200 }, // 链接
  14. is_use: { type: String, required: false, maxLength: 5 }, // 是否使用,0=>使用中;1=>已禁止
  15. meta: {
  16. createdBy: String, // 创建用户
  17. updatedBy: String, // 修改用户
  18. },
  19. // remark: { type: String, maxLength: 500 }, // 备注
  20. };
  21. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  22. schema.plugin(metaPlugin);
  23. schema.index({ site: 1 });
  24. schema.index({ 'meta.state': 1 });
  25. schema.index({ 'meta.createdAt': -1 });
  26. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  27. module.exports = app => {
  28. const { mongoose } = app;
  29. return mongoose.model('ImgInfo', schema, 'cms_img');
  30. };