install.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose/lib/service');
  3. // 初始化
  4. class InstallService extends CrudService {
  5. constructor(ctx) {
  6. super(ctx, 'install');
  7. this.admin = this.ctx.model.Admin;
  8. this.menu = this.ctx.model.Menu;
  9. }
  10. async index() {
  11. // await this.checkAdmin();
  12. await this.checkMenu();
  13. }
  14. /**
  15. * 检查是否有管理员
  16. */
  17. async checkAdmin() {
  18. const count = await this.admin.count({ role: '0' });
  19. if (count <= 0) {
  20. const data = {
  21. name: '超级管理员',
  22. phone: '11111111111',
  23. passwd: { secret: '123456' },
  24. role: '0',
  25. };
  26. this.admin.create(data);
  27. }
  28. }
  29. /**
  30. * 检查菜单是否有菜单管理
  31. */
  32. async checkMenu() {
  33. const count = await this.menu.count({ index: 'menu' });
  34. if (count <= 0) {
  35. const data = {
  36. title: '菜单管理',
  37. index: 'menu',
  38. sort: 1,
  39. icon: 'el-icon-star-off',
  40. };
  41. this.menu.create(data);
  42. }
  43. }
  44. }
  45. module.exports = InstallService;