import axios from 'axios'; // 假设你的后端 API 地址是 http://localhost:8080 const API_URL = 'http://localhost:8080/api/articles'; export default { // 获取所有文章 getAllArticles() { return axios.get(`${API_URL}`); }, // 获取最新文章 getLatestArticles() { return axios.get(`${API_URL}/latest`); }, // 获取热门文章 getPopularArticles() { return axios.get(`${API_URL}/popular`); }, // 获取推荐文章 getRecommendedArticles() { return axios.get(`${API_URL}/recommended`); }, // 获取当前用户的文章列表 getArticlesByCurrentUser() { return axios.get(`${API_URL}/user/me`); }, // 创建新文章 createArticle(article) { return axios.post(`${API_URL}/create`, article); }, // 获取所有未批准的文章(仅限管理员) getUnapprovedArticles() { return axios.get(`${API_URL}/unapproved`); }, // 审批文章(仅限管理员) approveArticle(id) { return axios.put(`${API_URL}/approve/${id}`); }, // 拒绝文章(仅限管理员) rejectArticle(id) { return axios.put(`${API_URL}/reject/${id}`); }, // 删除文章(仅限管理员) deleteArticle(id) { return axios.delete(`${API_URL}/${id}`); } };