comm.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Provide, Inject, Get, Post, Body, ALL } from '@midwayjs/decorator';
  2. import { Context } from 'egg';
  3. import { CoolController, BaseController, ICoolFile } from 'midwayjs-cool-core';
  4. import { BaseSysUserEntity } from '../../entity/sys/user';
  5. import { BaseSysLoginService } from '../../service/sys/login';
  6. import { BaseSysPermsService } from '../../service/sys/perms';
  7. import { BaseSysUserService } from '../../service/sys/user';
  8. /**
  9. * Base 通用接口 一般写不需要权限过滤的接口
  10. */
  11. @Provide()
  12. @CoolController()
  13. export class BaseCommController extends BaseController {
  14. @Inject()
  15. baseSysUserService: BaseSysUserService;
  16. @Inject()
  17. baseSysPermsService: BaseSysPermsService;
  18. @Inject()
  19. baseSysLoginService: BaseSysLoginService;
  20. @Inject()
  21. ctx: Context;
  22. @Inject('cool:file')
  23. coolFile: ICoolFile;
  24. /**
  25. * 获得个人信息
  26. */
  27. @Get('/person')
  28. async person() {
  29. return this.ok(await this.baseSysUserService.person());
  30. }
  31. /**
  32. * 修改个人信息
  33. */
  34. @Post('/personUpdate')
  35. async personUpdate(@Body(ALL) user: BaseSysUserEntity) {
  36. await this.baseSysUserService.personUpdate(user);
  37. return this.ok();
  38. }
  39. /**
  40. * 权限菜单
  41. */
  42. @Get('/permmenu')
  43. async permmenu() {
  44. return this.ok(
  45. await this.baseSysPermsService.permmenu(this.ctx.admin.roleIds)
  46. );
  47. }
  48. /**
  49. * 文件上传
  50. */
  51. @Post('/upload')
  52. async upload() {
  53. return this.ok(await this.coolFile.upload(this.ctx));
  54. }
  55. /**
  56. * 文件上传模式,本地或者云存储
  57. */
  58. @Get('/uploadMode')
  59. async uploadMode() {
  60. return this.ok(this.coolFile.getMode());
  61. }
  62. /**
  63. * 退出
  64. */
  65. @Post('/logout')
  66. async logout() {
  67. await this.baseSysLoginService.logout();
  68. return this.ok();
  69. }
  70. }