12345678910111213141516171819202122232425262728293031323334353637 |
- 'use strict';
- const menu = require('../../config/menu');
- const Service = require('egg').Service;
- class MenuService extends Service {
- constructor(ctx) {
- super(ctx);
- this.RoleBindMenu = this.ctx.model.RoleBindMenu;
- this.UserBindRole = this.ctx.model.UserBindRole;
- }
- async query() {
- try {
- return { errcode: 0, errmsg: 'ok', data: menu.data };
- } catch (error) {
- throw error;
- }
- }
- async queryUserMenu({ userId }) {
- const menuList = [];
- try {
- const roleList = await this.UserBindRole.find({ userId });
- await Promise.all(
- roleList.map(async e => {
- const menuCodeItem = await this.RoleBindMenu.find({ roleCode: e.roleCode });
- menuCodeItem.forEach(i => {
- menuList.push(menu.data.find(e => e.code === i.menuCode));
- });
- })
- );
- return { errcode: 0, errmsg: '', data: menuList };
- } catch (error) {
- throw error;
- }
- }
- }
- module.exports = MenuService;
|