adminMenu.js 986 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const menu = require('../../config/menu');
  3. const Service = require('egg').Service;
  4. class MenuService extends Service {
  5. constructor(ctx) {
  6. super(ctx);
  7. this.RoleBindMenu = this.ctx.model.RoleBindMenu;
  8. this.UserBindRole = this.ctx.model.UserBindRole;
  9. }
  10. async query() {
  11. try {
  12. return { errcode: 0, errmsg: 'ok', data: menu.data };
  13. } catch (error) {
  14. throw error;
  15. }
  16. }
  17. async queryUserMenu({ userId }) {
  18. const menuList = [];
  19. try {
  20. const roleList = await this.UserBindRole.find({ userId });
  21. await Promise.all(
  22. roleList.map(async e => {
  23. const menuCodeItem = await this.RoleBindMenu.find({ roleCode: e.roleCode });
  24. menuCodeItem.forEach(i => {
  25. menuList.push(menu.data.find(e => e.code === i.menuCode));
  26. });
  27. })
  28. );
  29. return { errcode: 0, errmsg: '', data: menuList };
  30. } catch (error) {
  31. throw error;
  32. }
  33. }
  34. }
  35. module.exports = MenuService;