Просмотр исходного кода

feat(frontend): 改版v1 通知入首页动态 (W3)

- index-home 新增 loadNotifications:用户通知合并到 FamilyFeed 动态
  - 未读通知优先显示(isRead=0 在前)
  - 使用 parseDate 解析时间(遵守小程序日期解析规范)

Ultraworked with [Sisyphus](https://github.com/OhMyOpenCode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
E2E Test Bot 1 месяц назад
Родитель
Сommit
d90b9b538e
1 измененных файлов с 31 добавлено и 1 удалено
  1. 31 1
      cfc-frontend/pages/index-home/index.vue

+ 31 - 1
cfc-frontend/pages/index-home/index.vue

@@ -345,9 +345,10 @@ import ArticleBookshelf from '../../components/ArticleBookshelf.vue'
 import FamilyChallengeCard from '../../components/FamilyChallengeCard.vue'
 import IntentPicker from '../../components/intent-picker.vue'
 import JourneyCard from '../../components/journey-card.vue'
-import { acceptParentInvite, productList, getActivityList, getFeaturedArticles, getFamilyEnergySandbox, getVisibleFamilyMembers, getChildren, getChallengeList, switchToFamilyMember, getMyMembership, updateChallengeProgress, respondChallenge, getTodayTasks, completeTask as completeTaskApi, getTodayParentTasks, completeParentTask as completeParentTaskApi, getTaskHistory, getNotices, getUserIntent, chooseUserIntent } from '../../utils/api.js'
+import { acceptParentInvite, productList, getActivityList, getFeaturedArticles, getFamilyEnergySandbox, getVisibleFamilyMembers, getChildren, getChallengeList, switchToFamilyMember, getMyMembership, updateChallengeProgress, respondChallenge, getTodayTasks, completeTask as completeTaskApi, getTodayParentTasks, completeParentTask as completeParentTaskApi, getTaskHistory, getNotices, getNotificationList, getUserIntent, chooseUserIntent } from '../../utils/api.js'
 import nav from '../../utils/nav.js'
 import config from '@/config.js'
+import { parseDate } from '../../utils/format.js'
 
 export default {
   components: {
@@ -545,6 +546,7 @@ export default {
         self.loadTodayTasks()
         self.loadFamilyFeed()
         self.loadNotices()
+        self.loadNotifications()
       }).catch(function(e) {
         console.log('获取孩子列表失败', e)
         self.childrenChecked = true
@@ -684,6 +686,34 @@ export default {
         }
       }).catch(function() {})
     },
+    // W3: 用户通知入动态(未读优先显示在 familyFeed 顶部)
+    loadNotifications: function() {
+      var self = this
+      getNotificationList().then(function(res) {
+        if (res.code === 200 && res.data) {
+          var notifications = res.data.map(function(n) {
+            var timeStr = ''
+            if (n.createdAt) {
+              var d = parseDate(n.createdAt)
+              if (d) {
+                timeStr = (d.getMonth() + 1) + '月' + d.getDate() + '日'
+              }
+            }
+            return {
+              text: '📬 ' + n.title,
+              time: timeStr,
+              type: 'notification',
+              unread: (n.isRead === 0),
+              notice: n
+            }
+          })
+          var unread = notifications.filter(function(n) { return n.unread })
+          var read = notifications.filter(function(n) { return !n.unread })
+          // 未读在前,已读在后,合并到 familyFeed 顶部
+          self.familyFeed = unread.concat(read, self.familyFeed).slice(0, 10)
+        }
+      }).catch(function() {})
+    },
     quickCompleteTask: function(task) {
       var self = this
       completeTaskApi(task.id, self.currentChildId, '').then(function(res) {