user.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. const await = require('await-stream-ready/lib/await');
  3. const Controller = require('egg').Controller;
  4. class UserController extends Controller {
  5. async list() {
  6. const {ctx, service} = this;
  7. let query = ctx.request.query;
  8. let ret = await service.adminUser.list(query);
  9. ctx.adminOK(ret);
  10. }
  11. async delete() {
  12. const {ctx, service} = this;
  13. let id = ctx.request.query.id;
  14. let ret = await service.adminUser.delete(id);
  15. ctx.adminOK(ret, "删除成功");
  16. }
  17. async edit() {
  18. const {ctx, service} = this;
  19. let data = ctx.request.body;
  20. let ret = await service.adminUser.edit( data );
  21. ctx.adminOK(ret, "更新成功");
  22. }
  23. async add() {
  24. const {ctx, service} = this;
  25. let data = ctx.request.body;
  26. let ret = await service.adminUser.add( data );
  27. ctx.adminOK(ret, "添加成功");
  28. }
  29. async resetpwd() {
  30. const {ctx, service} = this;
  31. let data = ctx.request.body;
  32. let ret = await service.adminUser.resetpwd( data );
  33. ctx.adminOK(ret, "重置成功");
  34. }
  35. async lock() {
  36. const {ctx, service} = this;
  37. let data = ctx.request.body;
  38. let ret = await service.adminUser.lockUser( data );
  39. ctx.adminOK(ret, "冻结成功");
  40. }
  41. async teachers() {
  42. const {ctx, service} = this;
  43. let query = ctx.request.query;
  44. query.role = 1;
  45. let ret = await service.adminUser.list(query);
  46. ctx.adminOK(ret);
  47. }
  48. async getProfile() {
  49. const {ctx, service} = this;
  50. await ctx.queryHandleByService(service.adminUser, "getUserProfile");
  51. }
  52. async getUserRecord() {
  53. const {ctx, service} = this;
  54. await ctx.queryHandleByService(service.record, "getUserRecord");
  55. }
  56. async getUserRecordList() {
  57. const {ctx, service} = this;
  58. await ctx.queryHandleByService(service.record, "getUserRecordList");
  59. }
  60. async commentUserRecord() {
  61. const {ctx, service} = this;
  62. await ctx.bodyHandleByService(service.adminUser, "commentUserRecord", "提交成功");
  63. }
  64. async exportXls() {
  65. const {ctx, service} = this;
  66. ctx.set("Content-Type", "application/vnd.openxmlformats");
  67. ctx.set("Content-Disposition","attachment;filename*=UTF-8 xx.xlsx");
  68. let ret = await service.adminUser.exportUserListXls( ctx.request.query );
  69. ctx.body = ret;
  70. }
  71. async exportProfileXls() {
  72. const {ctx, service} = this;
  73. ctx.set("Content-Type", "application/vnd.openxmlformats");
  74. ctx.set("Content-Disposition","attachment;filename*=UTF-8 xx.xlsx");
  75. let ret = await service.adminUser.exportProfileXls( ctx.request.query );
  76. ctx.body = ret;
  77. }
  78. }
  79. module.exports = UserController;