fetchSearchResult.js 966 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable no-param-reassign */
  2. import { config } from '../../config/index';
  3. /** 获取搜索历史 */
  4. function mockSearchResult(params) {
  5. const { delay } = require('../_utils/delay');
  6. const { getSearchResult } = require('../../model/search');
  7. const data = getSearchResult(params);
  8. if (data.spuList.length) {
  9. data.spuList.forEach((item) => {
  10. item.spuId = item.spuId;
  11. item.thumb = item.primaryImage;
  12. item.title = item.title;
  13. item.price = item.minSalePrice;
  14. item.originPrice = item.maxLinePrice;
  15. if (item.spuTagList) {
  16. item.tags = item.spuTagList.map((tag) => ({ title: tag.title }));
  17. } else {
  18. item.tags = [];
  19. }
  20. });
  21. }
  22. return delay().then(() => {
  23. return data;
  24. });
  25. }
  26. /** 获取搜索历史 */
  27. export function getSearchResult(params) {
  28. if (config.useMock) {
  29. return mockSearchResult(params);
  30. }
  31. return new Promise((resolve) => {
  32. resolve('real api');
  33. });
  34. }