home.js 804 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class HomeController extends Controller {
  4. async index() {
  5. const { ctx } = this;
  6. ctx.body = 'hi, homeEgg';
  7. }
  8. // 获取地区(下一级地区)
  9. async findDept() {
  10. const { ctx } = this;
  11. const body = ctx.request.body;
  12. delete body.deptId;
  13. delete body.dept1;
  14. delete body.dept2;
  15. delete body.dept3;
  16. delete body.dept4;
  17. delete body.dept5;
  18. if (body.name) {
  19. body.name = { $regex: body.name };
  20. }
  21. const result = await this.ctx.model.SysDeptModel.aggregate([
  22. { $match: ctx.alterDeptId(body) },
  23. {
  24. $project: {
  25. _id: 0,
  26. label: '$name',
  27. value: '$_id',
  28. },
  29. },
  30. ]);
  31. ctx.body = result;
  32. }
  33. }
  34. module.exports = HomeController;