feat(分类系统): 实现分类属性功能并重构文章列表
重构文章分类系统,新增分类属性服务及相关API接口 修改文章列表页面以支持按属性筛选文章 调整路由和样式以适配新功能
This commit is contained in:
@@ -61,17 +61,33 @@ const fetchArticles = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
let res = {} // 使用let而不是const
|
||||
// 使用route对象获取参数,而不是检查pathname
|
||||
if (route.params.type ) {
|
||||
console.log('根据type获取文章列表成功')
|
||||
res = await articleService.getAllArticlesByType(route.params.type)
|
||||
} else if (route.params.title) {
|
||||
res = await articleService.getAllArticlesByTitle(route.params.title)
|
||||
console.log('根据title获取文章列表成功')
|
||||
} else {
|
||||
res = await articleService.getAllArticles()
|
||||
console.log('获取所有文章列表成功')
|
||||
|
||||
// 检查URL参数
|
||||
const query = route.query
|
||||
const params = route.params
|
||||
|
||||
// 优先使用attributeId参数(新接口)
|
||||
if (query.attributeId) {
|
||||
console.log('根据属性ID获取文章列表')
|
||||
res = await articleService.getArticlesByAttribute(query.attributeId)
|
||||
}
|
||||
// 兼容旧的type参数
|
||||
else if (params.type) {
|
||||
console.log('根据类型ID获取文章列表(兼容模式)')
|
||||
res = await articleService.getArticlesByCategory(params.type)
|
||||
}
|
||||
// 搜索标题
|
||||
else if (params.title || query.title) {
|
||||
const title = params.title || query.title
|
||||
console.log('根据标题获取文章列表')
|
||||
res = await articleService.getArticlesByTitle(title)
|
||||
}
|
||||
// 获取所有文章
|
||||
else {
|
||||
res = await articleService.getAllArticles()
|
||||
console.log('获取所有文章列表')
|
||||
}
|
||||
|
||||
datas.value = res.data || []
|
||||
console.log('获取文章列表成功:', datas.value)
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user