system.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. const Controller = require('../core/base_controller');
  3. const pMap = require('p-map');
  4. class HomeController extends Controller {
  5. // 登录
  6. async login() {
  7. const {
  8. ctx,
  9. } = this;
  10. try {
  11. const res = await ctx.helper.http('/user/login', ctx.request.body);
  12. this.success(res);
  13. } catch (error) {
  14. this.notFound(error);
  15. }
  16. }
  17. // 注册
  18. async register() {
  19. const {
  20. ctx,
  21. } = this;
  22. try {
  23. const res = await ctx.helper.http('/user/register', ctx.request.body);
  24. this.success(res);
  25. } catch (error) {
  26. this.notFound(error);
  27. }
  28. }
  29. // 重置密码
  30. async forget() {
  31. const {
  32. ctx,
  33. } = this;
  34. try {
  35. const res = await ctx.helper.http('/user/forget', ctx.request.body);
  36. this.success(res);
  37. } catch (error) {
  38. this.notFound(error);
  39. }
  40. }
  41. // 获取登录用户详情
  42. async getUser() {
  43. const {
  44. ctx,
  45. } = this;
  46. try {
  47. const res = await ctx.helper.http('/user/getUser');
  48. this.success(res);
  49. } catch (error) {
  50. this.notFound(error);
  51. }
  52. }
  53. // 获取列表
  54. async getList() {
  55. const {
  56. ctx,
  57. } = this;
  58. try {
  59. const res = await ctx.helper.http('/list/getList', ctx.request.body);
  60. this.success(res);
  61. } catch (error) {
  62. this.notFound(error);
  63. }
  64. }
  65. // 聚合数据
  66. async makeUpList() {
  67. const {
  68. ctx,
  69. } = this;
  70. const urls = [{ name: 'product', url: '/product' }, { name: 'news', url: '/news' }, { name: 'order', url: '/order' }, { name: 'tree', url: '/tree' }];
  71. const arr = {};
  72. await pMap(urls, async item => {
  73. const res = await ctx.helper.http(item.url);
  74. arr[item.name] = res.data;
  75. });
  76. this.success({ code: 1, msg: 'success', data: arr });
  77. }
  78. // 十万条数据
  79. getMuchList(){
  80. let arr=[]
  81. for(let i=0;i<100000;i++){
  82. arr.push(i)
  83. }
  84. this.success({code:1,msg:'success',data:arr})
  85. }
  86. }
  87. module.exports = HomeController;