1
0

list.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { faker } from '@faker-js/faker';
  2. import { verifyAccessToken } from '~/utils/jwt-utils';
  3. import { unAuthorizedResponse } from '~/utils/response';
  4. function generateMockDataList(count: number) {
  5. const dataList = [];
  6. for (let i = 0; i < count; i++) {
  7. const dataItem = {
  8. id: faker.string.uuid(),
  9. imageUrl: faker.image.avatar(),
  10. imageUrl2: faker.image.avatar(),
  11. open: faker.datatype.boolean(),
  12. status: faker.helpers.arrayElement(['success', 'error', 'warning']),
  13. productName: faker.commerce.productName(),
  14. price: faker.commerce.price(),
  15. currency: faker.finance.currencyCode(),
  16. quantity: faker.number.int({ min: 1, max: 100 }),
  17. available: faker.datatype.boolean(),
  18. category: faker.commerce.department(),
  19. releaseDate: faker.date.past(),
  20. rating: faker.number.float({ min: 1, max: 5 }),
  21. description: faker.commerce.productDescription(),
  22. weight: faker.number.float({ min: 0.1, max: 10 }),
  23. color: faker.color.human(),
  24. inProduction: faker.datatype.boolean(),
  25. tags: Array.from({ length: 3 }, () => faker.commerce.productAdjective()),
  26. };
  27. dataList.push(dataItem);
  28. }
  29. return dataList;
  30. }
  31. const mockData = generateMockDataList(100);
  32. export default eventHandler(async (event) => {
  33. const userinfo = verifyAccessToken(event);
  34. if (!userinfo) {
  35. return unAuthorizedResponse(event);
  36. }
  37. await sleep(600);
  38. const { page, pageSize } = getQuery(event);
  39. return usePageResponseSuccess(page as string, pageSize as string, mockData);
  40. });