|
@@ -8,8 +8,19 @@ import {
|
|
|
Post,
|
|
|
Query,
|
|
|
} from '@midwayjs/decorator';
|
|
|
-import { BaseController } from 'free-midway-component';
|
|
|
+import {
|
|
|
+ BaseController,
|
|
|
+ FrameworkErrorEnum,
|
|
|
+ SearchBase,
|
|
|
+ ServiceError,
|
|
|
+} from 'free-midway-component';
|
|
|
import { RoleService } from '../../service/system/role.service';
|
|
|
+import { ModuleService } from '../../service/system/module.service';
|
|
|
+import { MenusService } from '../../service/system/menus.service';
|
|
|
+import { AdminService } from '../../service/user/admin.service';
|
|
|
+import { CompanyService } from '../../service/user/company.service';
|
|
|
+import { ExpertService } from '../../service/user/expert.service';
|
|
|
+import { PersonalService } from '../../service/user/personal.service';
|
|
|
import {
|
|
|
CDTO_role,
|
|
|
CVO_role,
|
|
@@ -19,13 +30,78 @@ import {
|
|
|
UDTO_role,
|
|
|
UVAO_role,
|
|
|
} from '../../interface/system/role.interface';
|
|
|
-import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
|
|
|
+import {
|
|
|
+ ApiOperation,
|
|
|
+ ApiQuery,
|
|
|
+ ApiResponse,
|
|
|
+ ApiTags,
|
|
|
+} from '@midwayjs/swagger';
|
|
|
import { Validate } from '@midwayjs/validate';
|
|
|
+import get = require('lodash/get');
|
|
|
@ApiTags(['角色'])
|
|
|
@Controller('/role')
|
|
|
export class RoleController extends BaseController {
|
|
|
@Inject()
|
|
|
service: RoleService;
|
|
|
+ @Inject()
|
|
|
+ moduleService: ModuleService;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ menusService: MenusService;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ adminService: AdminService;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ companyService: CompanyService;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ expertService: ExpertService;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ personalService: PersonalService;
|
|
|
+
|
|
|
+ @Get('/um')
|
|
|
+ @ApiOperation({ description: '获取用户的菜单' })
|
|
|
+ async userMenu() {
|
|
|
+ const user = this.ctx.user;
|
|
|
+ if (!user)
|
|
|
+ throw new ServiceError('用户未登录', FrameworkErrorEnum.NOT_LOGIN);
|
|
|
+ const type = get(user, 'type');
|
|
|
+ const user_id = get(this.ctx.user, '_id');
|
|
|
+ let udata = {};
|
|
|
+ if (type === '1') udata = await this.adminService.fetch(user_id);
|
|
|
+ else if (type === '3') udata = await this.personalService.fetch(user_id);
|
|
|
+ else if (type === '4') udata = await this.companyService.fetch(user_id);
|
|
|
+ else if (type === '5') udata = await this.expertService.fetch(user_id);
|
|
|
+ else if (type === '0') {
|
|
|
+ // 超级管理员
|
|
|
+ const f = new SearchBase({});
|
|
|
+ const modules = await this.moduleService.query(f);
|
|
|
+ const allMenus = {};
|
|
|
+ for (const i of modules) {
|
|
|
+ const menus = await this.menusService.queryMenu(get(i, '_id'));
|
|
|
+ allMenus[get(i, '_id')] = menus;
|
|
|
+ }
|
|
|
+ return allMenus;
|
|
|
+ }
|
|
|
+ const menus = await this.service.getMenuByRoles(get(udata, 'role', []));
|
|
|
+ return menus;
|
|
|
+ }
|
|
|
+ @Get('/am')
|
|
|
+ @ApiOperation({ description: '获取所有菜单提供选择' })
|
|
|
+ async roleAllMenu() {
|
|
|
+ const f = new SearchBase({});
|
|
|
+ const moduleList = await this.moduleService.query(f, null, { lean: true });
|
|
|
+ const result = [];
|
|
|
+ for (const i of moduleList) {
|
|
|
+ const menus = await this.menusService.queryMenu(i._id);
|
|
|
+ const obj: any = { _id: i._id, name: i.name };
|
|
|
+ if (menus.length > 0) obj.children = menus;
|
|
|
+ result.push(obj);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
@Post('/')
|
|
|
@Validate()
|