浏览代码

分类功能调整

guanyongjie 1 周之前
父节点
当前提交
7d72e8efac

+ 2 - 0
src/types/index.ts

@@ -37,6 +37,8 @@ export interface NewsItem {
   articleUrl: string //资讯连接
   categoryId: number // 类别id
   categoryName: string // 类别名称
+  categoryIds?:number[] // 类别id数组
+  categoryNames?:string[] // 类别名称数组
   digest: string //摘要
   publicTime: Date //发布时间
   createTime?: Date //创建时间

+ 18 - 4
src/views/news/NewsList.vue

@@ -393,6 +393,8 @@ const fetchNews = async () => {
     newsList.value = response.data.data.map((news) => ({
       ...news,
       isEditing: false,
+      categoryIds: news.categoryIds || [news.categoryId], // 初始化categoryIds数组
+      categoryNames: news.categoryNames || [news.categoryName], // 初始化categoryNames数组
     }))
     pagination.value.total = response.data.total
     // 下一帧恢复选中状态(确保表格渲染完成)
@@ -459,7 +461,11 @@ const saveNewsField = async (news: EditableNewsItem, field?: string) => {
     // 如果没有指定字段,保存所有字段
     const updates: Partial<NewsItem> = field
       ? { [field]: news[field as keyof NewsItem] }
-      : { categoryIds: news.categoryIds ? Object.values(news.categoryIds) : [], digest: news.digest, articleId: news.articleId }
+      : { 
+          categoryIds: news.categoryIds || [], 
+          digest: news.digest, 
+          articleId: news.articleId 
+        }
     // 更新资讯
     await newsApi.updateNews(updates)
     ElMessage.success('资讯更新成功')
@@ -468,9 +474,17 @@ const saveNewsField = async (news: EditableNewsItem, field?: string) => {
     if (!field) {
       news.isEditing = false
       // 更新本地列表中的分类名称
-      const category = categories.value.find((c) => c.id === news.categoryIds)
-      if (category) {
-        news.categoryName = category.name
+      // const category = categories.value.find((c) => c.id === news.categoryIds)
+      // if (category) {
+      //   news.categoryName = category.name
+      // }
+      if (news.categoryIds && news.categoryIds.length > 0) {
+        const categoryNames = news.categoryIds.map(id => 
+          categories.value.find(c => c.id === id)?.name
+        ).filter(Boolean)
+        news.categoryNames = categoryNames
+        news.categoryName = categoryNames[0] || news.categoryName
+        news.categoryId = news.categoryIds[0] || news.categoryId
       }
       // 清除原始数据
       news.originalData = undefined

+ 10 - 17
src/views/news/components/dialog/oneClickExportReport.vue

@@ -74,31 +74,24 @@ const shortcuts = [
     text: '上周',
     value: () => {
       const end = new Date();
-      // 设置为上周日(结束日期)
-      end.setDate(end.getDate() - end.getDay()); // 本周日
-      end.setHours(23, 59, 59, 999); // 设置为当天最后一刻
-      
+      end.setUTCDate(end.getDate() - end.getDay())
+      end.setUTCHours(23, 59, 59, 999)
       const start = new Date(end);  
-      start.setDate(start.getDate() - 6); // 上周一
-      start.setHours(0, 0, 0, 0); // 设置为当天最开始
-      
-      return [start, end];
+      start.setUTCDate(start.getDate() - 7)
+      start.setUTCHours(0, 0, 0, 0)
+      return [start,end]
     },
   },
   {
     text: '上个月',
     value: () => {
       const end = new Date();
-      // 先设置到当月1日,再减去1天得到上个月最后一天
-      end.setDate(1);
-      end.setHours(0, 0, 0, 0);
-      end.setMilliseconds(-1); // 减去1毫秒得到上个月最后一天的23:59:59.999
-      
+      end.setUTCDate(0);
+      end.setUTCHours(23, 59, 59, 999);
       const start = new Date(end);
-      start.setDate(1); // 上个月第1天
-      start.setHours(0, 0, 0, 0);
-      
-      return [start, end];
+      start.setUTCDate(1); 
+      start.setUTCHours(0, 0, 0, 0);
+      return [start,end]
     },
   },
 ]

+ 16 - 5
src/views/report/ReportDetail.vue

@@ -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