content.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 内容相关API
  2. const api = require('../utils/api');
  3. // 分页获取内容列表
  4. function getContentList(current = 1, size = 10, keyword = '', contentType = null, categoryId = null) {
  5. const params = { current, size };
  6. if (keyword && keyword.trim()) {
  7. params.keyword = keyword;
  8. }
  9. // 只有当 contentType 不为 null 且不为 undefined 时才添加
  10. if (contentType !== null && contentType !== undefined) {
  11. params.contentType = contentType;
  12. }
  13. // 只有当 categoryId 不为 null 且不为 undefined 时才添加
  14. if (categoryId !== null && categoryId !== undefined && categoryId !== 0) {
  15. params.categoryId = categoryId;
  16. }
  17. return api.get('/app/content/page', params);
  18. }
  19. // 获取内容详情
  20. function getContentDetail(contentId) {
  21. return api.get(`/app/content/${contentId}`);
  22. }
  23. // 增加内容浏览量
  24. function increaseViewCount(contentId) {
  25. return api.post(`/content/${contentId}/view`, {}, false);
  26. }
  27. // 获取今日推荐内容
  28. function getRecommended(size = 6) {
  29. return api.get('/app/content/recommended', { size }, false);
  30. }
  31. module.exports = {
  32. getContentList,
  33. getContentDetail,
  34. increaseViewCount,
  35. getRecommended
  36. };