// 文章相关API服务 import apiService from './apiService' /** * 文章服务类 */ class ArticleService { /** * 获取所有文章 * @param {Object} params - 查询参数 * @returns {Promise} */ getAllArticles(params = {}) { return apiService.get('/articles', { params }) } /** * 获取单篇文章 * @param {number} id - 文章ID * @returns {Promise} */ getArticleById(id) { return apiService.get(`/articles/${id}`) } /** * 获取热门文章 * @returns {Promise} */ getPopularArticles() { return apiService.get('/articles/popular') } /** * 创建文章 * @param {Object} articleData - 文章数据 * @returns {Promise} */ createArticle(articleData) { return apiService.post('/articles', articleData) } /** * 更新文章 * @param {number} id - 文章ID * @param {Object} articleData - 文章数据 * @returns {Promise} */ updateArticle(id, articleData) { return apiService.put(`/articles/${id}`, articleData) } /** * 删除文章 * @param {number} id - 文章ID * @returns {Promise} */ deleteArticle(id) { return apiService.delete(`/articles/${id}`) } /** * 增加文章浏览量 * @param {number} id - 文章ID * @returns {Promise} */ incrementArticleViews(id) { return apiService.post(`/articles/${id}/views`) } } // 导出文章服务实例 export default new ArticleService()