'use strict'; const { CrudService } = require('naf-framework-mongoose/lib/service'); // 初始化 class InstallService extends CrudService { constructor(ctx) { super(ctx, 'install'); this.admin = this.ctx.model.Admin; this.menu = this.ctx.model.Menu; } async index() { // await this.checkAdmin(); await this.checkMenu(); } /** * 检查是否有管理员 */ async checkAdmin() { const count = await this.admin.count({ role: '0' }); if (count <= 0) { const data = { name: '超级管理员', phone: '11111111111', passwd: { secret: '123456' }, role: '0', }; this.admin.create(data); } } /** * 检查菜单是否有菜单管理 */ async checkMenu() { const count = await this.menu.count({ index: 'menu' }); if (count <= 0) { const data = { title: '菜单管理', index: 'menu', sort: 1, icon: 'el-icon-star-off', }; this.menu.create(data); } } } module.exports = InstallService;