|
|
@@ -188,10 +188,22 @@ const fetchReportNews = async () => {
|
|
|
// Group news by category
|
|
|
const grouped: Record<string, NewsItem[]> = {}
|
|
|
newsList.forEach((news) => {
|
|
|
- if (!grouped[news.categoryName]) {
|
|
|
- grouped[news.categoryName] = []
|
|
|
+ // 检查是否有categoryNames数组
|
|
|
+ if (news.categoryNames && news.categoryNames.length > 0) {
|
|
|
+ // 遍历每个分类名称,将新闻添加到对应的分类组中
|
|
|
+ news.categoryNames.forEach((categoryName) => {
|
|
|
+ if (!grouped[categoryName]) {
|
|
|
+ grouped[categoryName] = []
|
|
|
+ }
|
|
|
+ grouped[categoryName].push(news)
|
|
|
+ })
|
|
|
+ } else if (news.categoryName) {
|
|
|
+ // 如果没有categoryNames数组但有categoryName,则使用单个分类名称
|
|
|
+ if (!grouped[news.categoryName]) {
|
|
|
+ grouped[news.categoryName] = []
|
|
|
+ }
|
|
|
+ grouped[news.categoryName].push(news)
|
|
|
}
|
|
|
- grouped[news.categoryName].push(news)
|
|
|
})
|
|
|
const arr = []
|
|
|
for (const key in grouped) {
|
|
|
@@ -230,7 +242,7 @@ const fetchCategories = async () => {
|
|
|
const startEdit = (news: NewsItem) => {
|
|
|
editingNewsId.value = news.articleId
|
|
|
editForm.value = {
|
|
|
- categoryIds:[news.categoryId],
|
|
|
+ categoryIds: news.categoryIds,
|
|
|
categoryId: news.categoryId,
|
|
|
digest: news.digest,
|
|
|
}
|
|
|
@@ -248,7 +260,6 @@ const saveEdit = async () => {
|
|
|
articleId: editingNewsId.value,
|
|
|
...editForm.value,
|
|
|
}
|
|
|
- params.categoryIds = editForm.value.categoryIds ? Object.values(editForm.value.categoryIds) : []
|
|
|
await newsApi.updateNews(params)
|
|
|
ElMessage.success('资讯更新成功')
|
|
|
editingNewsId.value = null
|