1
0

online.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { AdminRoute } from '../../../decorator/router_register';
  2. import { KickDto } from '../../../dto/admin/sys/online';
  3. import BaseController from '../../base';
  4. /**
  5. * 在线用户控制器
  6. */
  7. export default class SysOnlineController extends BaseController {
  8. /**
  9. * @api {get} /admin/sys/online/list 获取在线用户列表
  10. * @apiGroup 在线用户
  11. * @apiUse Auth
  12. * @apiUse BaseRes
  13. * @apiSuccess {Number} data.id 用户ID
  14. * @apiSuccess {String} data.ip 用户登陆IP
  15. * @apiSuccess {String} data.username 用户名
  16. * @apiSuccess {Boolean} data.isCurrent 是否为当前用户
  17. * @apiSuccess {String} data.time 登陆时间
  18. * @apiSuccess {Number} data.status 状态
  19. * @apiSuccess {String} data.os 登陆系统
  20. * @apiSuccess {String} data.browser 登陆浏览器
  21. * @apiSuccess {Boolean} data.disable 是否可用
  22. */
  23. @AdminRoute('/sys/online/list', 'get')
  24. async page() {
  25. this.res({
  26. data: await this.service.admin.sys.online.list(),
  27. });
  28. }
  29. /**
  30. * @api {get} /admin/sys/online/list 下线当前用户
  31. * @apiGroup 在线用户
  32. * @apiUse Auth
  33. * @apiUse BaseRes
  34. * @apiParam {Number} id 当前用户ID
  35. */
  36. @AdminRoute('/sys/online/kick', 'post')
  37. async kick() {
  38. const dto = await this.ctx.validate<KickDto>(KickDto);
  39. if (dto.id === this.ctx.token.uid) {
  40. this.res({
  41. code: 10012,
  42. });
  43. return;
  44. }
  45. if (dto.id === this.config.rootRoleId) {
  46. this.res({
  47. code: 10013,
  48. });
  49. return;
  50. }
  51. await this.service.admin.sys.user.forbidden(dto.id);
  52. this.res();
  53. }
  54. }