feat: 添加登录功能与文章编辑功能
refactor: 重构API服务与全局状态管理 style: 优化UI样式与布局 fix: 修复文章列表与详情页的显示问题 docs: 更新类型定义与注释 chore: 更新依赖包与配置文件
This commit is contained in:
@@ -1,119 +1,122 @@
|
||||
// 文章相关API服务
|
||||
import apiService from './apiService'
|
||||
import api from './apiService'
|
||||
|
||||
/**
|
||||
* 文章服务类
|
||||
*/
|
||||
class ArticleService {
|
||||
/**
|
||||
* 获取已发布文章
|
||||
* @param {Object} params - 查询参数
|
||||
* @returns {Promise}
|
||||
* 获取已发布文章列表
|
||||
* @param {import('../types').PaginationParams} params - 查询参数
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getAllArticles(params = {}) {
|
||||
return apiService.get('/articles/published', { params })
|
||||
return api.get('/articles/published', { params })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单篇文章
|
||||
* @param {number} id - 文章ID
|
||||
* @returns {Promise}
|
||||
* 根据ID获取文章详情
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article>>}
|
||||
*/
|
||||
getArticleById(id) {
|
||||
return apiService.get(`/articles/${id}`)
|
||||
getArticleById(articleid) {
|
||||
return api.get(`/articles/${articleid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID获取文章列表
|
||||
* @param {number} attributeId - 属性ID
|
||||
* @returns {Promise}
|
||||
* @param {number} attributeid - 属性ID
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getArticlesByAttributeId(attributeId) {
|
||||
return apiService.get(`/articles/attribute/${attributeId}`)
|
||||
getArticlesByAttributeId(attributeid) {
|
||||
return api.get(`/articles/attribute/${attributeid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标题查询文章列表
|
||||
* @param {string} title - 文章标题
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getArticlesByTitle(title) {
|
||||
return apiService.get(`/articles/title/${title}`)
|
||||
return api.get(`/articles/title/${title}`)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取热门文章
|
||||
* @returns {Promise}
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getPopularArticles() {
|
||||
return apiService.get('/articles/popular')
|
||||
return api.get('/articles/popular')
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文章
|
||||
* @param {Object} articleData - 文章数据
|
||||
* @returns {Promise}
|
||||
* @param {import('../types').ArticleDto} articleData - 文章数据
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article>>}
|
||||
*/
|
||||
createArticle(articleData) {
|
||||
return apiService.post('/articles', articleData)
|
||||
createArticle(Article) {
|
||||
return api.post('/articles', Article)
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
* @param {number} id - 文章ID
|
||||
* @param {Object} articleData - 文章数据
|
||||
* @returns {Promise}
|
||||
* @param {number} articleid - 文章ID
|
||||
* @param {import('../types').ArticleDto} articleData - 文章数据
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article>>}
|
||||
*/
|
||||
updateArticle(id, articleData) {
|
||||
return apiService.put(`/articles/${id}`, articleData)
|
||||
updateArticle(articleid, articleData) {
|
||||
return api.put(`/articles/${articleid}`, articleData)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param {number} id - 文章ID
|
||||
* @returns {Promise}
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<boolean>>}
|
||||
*/
|
||||
deleteArticle(id) {
|
||||
return apiService.delete(`/articles/${id}`)
|
||||
deleteArticle(articleid) {
|
||||
return api.delete(`/articles/${articleid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类获取文章
|
||||
* @param {number} categoryid - 分类ID
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getArticlesByCategory(categoryid) {
|
||||
return api.get(`/articles/category/${categoryid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加文章浏览量
|
||||
* @param {number} id - 文章ID
|
||||
* @returns {Promise}
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<boolean>>}
|
||||
*/
|
||||
incrementArticleViews(id) {
|
||||
return apiService.post(`/articles/view/${id}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID获取文章(兼容旧接口)
|
||||
* @param {number} categoryId - 分类ID
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getArticlesByCategory(categoryId) {
|
||||
return apiService.get(`/articles/category/${categoryId}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID获取文章
|
||||
* @param {number} attributeId - 属性ID
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getArticlesByAttribute(attributeId) {
|
||||
return apiService.get(`/articles/attribute/${attributeId}`)
|
||||
incrementArticleViews(articleid) {
|
||||
return api.post(`/articles/view/${articleid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID获取最新文章
|
||||
* @param {number} attributeId - 属性ID
|
||||
* @returns {Promise}
|
||||
* @param {number} attributeid - 属性ID
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getLatestArticlesByAttribute(attributeId) {
|
||||
return apiService.get(`/articles/attribute/${attributeId}/latest`)
|
||||
getLatestArticlesByAttribute(attributeid) {
|
||||
return api.get(`/articles/attribute/${attributeid}/latest`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞文章
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<boolean>>}
|
||||
*/
|
||||
likeArticle(articleid) {
|
||||
return api.post(`/articles/like/${articleid}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 导出文章服务实例
|
||||
export default new ArticleService()
|
||||
// 创建并导出服务实例
|
||||
const articleService = new ArticleService()
|
||||
export default articleService
|
||||
|
||||
// 导出服务类供特殊场景使用
|
||||
export { ArticleService }
|
||||
Reference in New Issue
Block a user