| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- // 内容相关API
- const api = require('../utils/api');
- // 分页获取内容列表
- function getContentList(current = 1, size = 10, keyword = '', contentType = null, categoryId = null) {
- const params = { current, size };
- if (keyword && keyword.trim()) {
- params.keyword = keyword;
- }
- // 只有当 contentType 不为 null 且不为 undefined 时才添加
- if (contentType !== null && contentType !== undefined) {
- params.contentType = contentType;
- }
- // 只有当 categoryId 不为 null 且不为 undefined 时才添加
- if (categoryId !== null && categoryId !== undefined && categoryId !== 0) {
- params.categoryId = categoryId;
- }
- return api.get('/app/content/page', params);
- }
- // 获取内容详情
- function getContentDetail(contentId) {
- return api.get(`/app/content/${contentId}`);
- }
- // 增加内容浏览量
- function increaseViewCount(contentId) {
- return api.post(`/content/${contentId}/view`, {}, false);
- }
- // 获取今日推荐内容
- function getRecommended(size = 6) {
- return api.get('/app/content/recommended', { size }, false);
- }
- module.exports = {
- getContentList,
- getContentDetail,
- increaseViewCount,
- getRecommended
- };
|