table.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const { mock } = require("mockjs");
  2. const { handleRandomImage } = require("../utils");
  3. const List = [];
  4. const count = 50;
  5. for (let i = 0; i < count; i++) {
  6. List.push(
  7. mock({
  8. uuid: "@uuid",
  9. id: "@id",
  10. title: "@title(1, 2)",
  11. description: "@csentence",
  12. "status|1": ["published", "draft", "deleted"],
  13. author: "@cname",
  14. datetime: "@datetime",
  15. pageViews: "@integer(300, 5000)",
  16. img: handleRandomImage(228, 228),
  17. switch: "@boolean",
  18. percent: "@integer(80,99)",
  19. "rate|1": [1, 2, 3, 4, 5],
  20. })
  21. );
  22. }
  23. module.exports = [
  24. {
  25. url: "/table/getList",
  26. type: "get",
  27. response(config) {
  28. const { title, pageNo = 1, pageSize = 20 } = config.query;
  29. let mockList = List.filter((item) => {
  30. if (title && item.title.indexOf(title) < 0) return false;
  31. return true;
  32. });
  33. const pageList = mockList.filter(
  34. (item, index) =>
  35. index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
  36. );
  37. return {
  38. code: 200,
  39. msg: "success",
  40. totalCount: mockList.length,
  41. data: pageList,
  42. };
  43. },
  44. },
  45. {
  46. url: "/table/doEdit",
  47. type: "post",
  48. response() {
  49. return {
  50. code: 200,
  51. msg: "模拟保存成功",
  52. };
  53. },
  54. },
  55. {
  56. url: "/table/doDelete",
  57. type: "post",
  58. response() {
  59. return {
  60. code: 200,
  61. msg: "模拟删除成功",
  62. };
  63. },
  64. },
  65. ];