admin.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const { DataTypes } = require('sequelize');
  2. const connect = require('./connect');
  3. const { isProd } = require('../../config');
  4. /*
  5. type: DataTypes.STRING,
  6. allowNull: false,
  7. defaultValue:'',
  8. comment: '名',
  9. */
  10. function formatTime(m) {
  11. // m.auth && (m.auth = JSON.parse(m.auth));
  12. }
  13. const model = connect.define(
  14. __filename.slice(__dirname.length + 1).replace('.js', ''),
  15. {
  16. id: {
  17. type: DataTypes.INTEGER,
  18. autoIncrement: true,
  19. primaryKey: true,
  20. comment: 'id',
  21. },
  22. name: {
  23. type: DataTypes.STRING,
  24. allowNull: false,
  25. defaultValue: '',
  26. comment: '名',
  27. },
  28. img: {
  29. type: DataTypes.STRING,
  30. defaultValue: '',
  31. comment: '头像',
  32. },
  33. phone: {
  34. type: DataTypes.STRING,
  35. defaultValue: '',
  36. comment: '电话',
  37. },
  38. pwd: {
  39. type: DataTypes.STRING,
  40. defaultValue: '',
  41. comment: '密码',
  42. },
  43. auth: {
  44. type: DataTypes.JSON,
  45. allowNull: false,
  46. comment: '权限',
  47. },
  48. },
  49. {
  50. comment: '管理员',
  51. hooks: {
  52. beforeFind(option) {
  53. if (!option.order) {
  54. option.order = [['id', 'desc']];
  55. }
  56. },
  57. afterFind(m) {
  58. m && (Array.isArray(m) ? m.forEach(item => formatTime(item)) : formatTime(m));
  59. },
  60. },
  61. }
  62. );
  63. module.exports = model;