feat(分类系统): 实现分类属性功能并重构文章列表

重构文章分类系统,新增分类属性服务及相关API接口
修改文章列表页面以支持按属性筛选文章
调整路由和样式以适配新功能
This commit is contained in:
qingfeng1121
2025-10-18 10:28:49 +08:00
parent 266310dea3
commit 02d17d7260
13 changed files with 648 additions and 433 deletions

View File

@@ -23,6 +23,15 @@ class ArticleService {
return apiService.get(`/articles/${id}`)
}
/**
* 根据属性ID获取文章列表
* @param {number} attributeId - 属性ID
* @returns {Promise}
*/
getArticlesByAttributeId(attributeId) {
return apiService.get(`/articles/attribute/${attributeId}`)
}
/**
* 根据标题查询文章列表
* @param {string} title - 文章标题
@@ -68,7 +77,7 @@ class ArticleService {
deleteArticle(id) {
return apiService.delete(`/articles/${id}`)
}
/**
* 增加文章浏览量
* @param {number} id - 文章ID
@@ -77,6 +86,33 @@ class ArticleService {
incrementArticleViews(id) {
return apiService.post(`/articles/${id}/views`)
}
/**
* 根据分类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}`)
}
/**
* 根据属性ID获取最新文章
* @param {number} attributeId - 属性ID
* @returns {Promise}
*/
getLatestArticlesByAttribute(attributeId) {
return apiService.get(`/articles/attribute/${attributeId}/latest`)
}
}
// 导出文章服务实例

View File

@@ -0,0 +1,66 @@
// 分类属性相关API服务
import apiService from './apiService'
/**
* 分类属性服务类
*/
class CategoryAttributeService {
/**
* 根据ID获取分类属性
* @param {number} id - 属性ID
* @returns {Promise}
*/
getAttributeById(id) {
return apiService.get(`/category-attributes/${id}`)
}
/**
* 根据分类ID获取属性列表
* @param {number} categoryId - 分类ID
* @returns {Promise}
*/
getAttributesByCategory(categoryId) {
return apiService.get(`/category-attributes/category/${categoryId}`)
}
/**
* 创建分类属性
* @param {Object} attributeData - 属性数据
* @returns {Promise}
*/
createAttribute(attributeData) {
return apiService.post('/category-attributes', attributeData)
}
/**
* 更新分类属性
* @param {number} id - 属性ID
* @param {Object} attributeData - 属性数据
* @returns {Promise}
*/
updateAttribute(id, attributeData) {
return apiService.put(`/category-attributes/${id}`, attributeData)
}
/**
* 删除分类属性
* @param {number} id - 属性ID
* @returns {Promise}
*/
deleteAttribute(id) {
return apiService.delete(`/category-attributes/${id}`)
}
/**
* 检查分类下是否存在指定名称的属性
* @param {number} categoryId - 分类ID
* @param {string} attributeName - 属性名称
* @returns {Promise}
*/
checkAttributeExists(categoryId, attributeName) {
return apiService.get(`/category-attributes/check-exists?categoryId=${categoryId}&attributeName=${encodeURIComponent(attributeName)}`)
}
}
// 导出分类属性服务实例
export default new CategoryAttributeService()

View File

@@ -0,0 +1,54 @@
import apiService from './apiService'
/**
* 分类服务
*/
class CategoryService {
/**
* 获取所有分类
* @returns {Promise}
*/
getAllCategories() {
return apiService.get('/categories')
}
/**
* 获取指定分类
* @param {number} id - 分类ID
* @returns {Promise}
*/
getCategory(id) {
return apiService.get(`/categories/${id}`)
}
/**
* 创建新分类
* @param {Object} categoryData - 分类数据
* @returns {Promise}
*/
createCategory(categoryData) {
return apiService.post('/categories', categoryData)
}
/**
* 更新分类
* @param {number} id - 分类ID
* @param {Object} categoryData - 分类数据
* @returns {Promise}
*/
updateCategory(id, categoryData) {
return apiService.put(`/categories/${id}`, categoryData)
}
/**
* 删除分类
* @param {number} id - 分类ID
* @returns {Promise}
*/
deleteCategory(id) {
return apiService.delete(`/categories/${id}`)
}
}
// 导出分类服务实例
export default new CategoryService()

View File

@@ -1,8 +1,17 @@
// 导出所有服务
import articleService from './articleService'
import messageService from './messageService'
import categoryAttributeService from './categoryAttributeService'
import categoryService from './categoryService'
export {
articleService,
messageService
messageService,
categoryAttributeService,
categoryService
}