goodsList.js 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { mock } from "mockjs";
  2. const List = [];
  3. const count = 999;
  4. let num = 0;
  5. for (let i = 0; i < count; i++) {
  6. List.push(
  7. mock({
  8. uuid: "@uuid",
  9. image: `https://picsum.photos/300/600?random=${num++}`,
  10. title: "@ctitle",
  11. description: "@csentence",
  12. link: "https://www.baidu.com",
  13. price: "@integer(100, 500)",
  14. "status|1": [1, 0],
  15. "isRecommend|1": [1, 0],
  16. })
  17. );
  18. }
  19. export default [
  20. {
  21. url: "/goodsList/getList",
  22. type: "post",
  23. response: (config) => {
  24. const { title = "", pageNo = 1, pageSize = 20 } = config.body;
  25. let mockList = List.filter((item) => {
  26. if (title && item.title.indexOf(title) < 0) return false;
  27. return true;
  28. });
  29. const pageList = mockList.filter(
  30. (item, index) =>
  31. index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
  32. );
  33. return {
  34. code: 200,
  35. msg: "success",
  36. totalCount: count,
  37. data: pageList,
  38. };
  39. },
  40. },
  41. ];