index.hbs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const { mock } = require("mockjs");
  2. const List = [];
  3. const count = 50;
  4. for (let i = 0; i < count; i++) {
  5. List.push(mock({ uuid: "@uuid", id: "@id", title: "@title(1, 2)" }));
  6. }
  7. module.exports = [
  8. {
  9. url: "/{{name}}/getList",
  10. type: "get",
  11. response: (config) => {
  12. const { title, pageNo = 1, pageSize = 20 } = config.query;
  13. let mockList = List.filter((item) => {
  14. if (title && item.title.indexOf(title) < 0) return false;
  15. return true;
  16. });
  17. const pageList = mockList.filter(
  18. (item, index) =>
  19. index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
  20. );
  21. return {
  22. code: 200,
  23. msg: "success",
  24. totalCount: mockList.length,
  25. data: pageList,
  26. };
  27. },
  28. },
  29. {
  30. url: "/{{name}}/doEdit",
  31. type: "post",
  32. response: () => {
  33. return {
  34. code: 200,
  35. msg: "模拟保存成功",
  36. };
  37. },
  38. },
  39. {
  40. url: "/{{name}}/doDelete",
  41. type: "post",
  42. response: () => {
  43. return {
  44. code: 200,
  45. msg: "模拟删除成功",
  46. };
  47. },
  48. },
  49. ];