feat(router): 添加消息中心和消息详情页面的路由配置
新增消息中心和消息详情页面的路由配置,并创建相应的Vue组件文件。消息中心页面展示用户消息列表,消息详情页面展示具体消息内容,支持消息已读状态的更新。
Showing
3 changed files
with
178 additions
and
0 deletions
| ... | @@ -116,6 +116,18 @@ const routes = [ | ... | @@ -116,6 +116,18 @@ const routes = [ |
| 116 | meta: { title: '我的收藏' }, | 116 | meta: { title: '我的收藏' }, |
| 117 | }, | 117 | }, |
| 118 | { | 118 | { |
| 119 | + path: '/profile/messages', | ||
| 120 | + name: 'Messages', | ||
| 121 | + component: () => import('../views/profile/MessagesPage.vue'), | ||
| 122 | + meta: { title: '消息中心' }, | ||
| 123 | + }, | ||
| 124 | + { | ||
| 125 | + path: '/profile/messages/:id', | ||
| 126 | + name: 'MessageDetail', | ||
| 127 | + component: () => import('../views/profile/MessageDetailPage.vue'), | ||
| 128 | + meta: { title: '消息详情' }, | ||
| 129 | + }, | ||
| 130 | + { | ||
| 119 | path: '/test', | 131 | path: '/test', |
| 120 | name: 'test', | 132 | name: 'test', |
| 121 | component: () => import('../views/test.vue'), | 133 | component: () => import('../views/test.vue'), | ... | ... |
src/views/profile/MessageDetailPage.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2025-03-24 12:56:24 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-24 12:56:26 | ||
| 5 | + * @FilePath: /mlaj/src/views/profile/MessageDetailPage.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <AppLayout title="消息详情"> | ||
| 10 | + <div class="bg-gradient-to-br from-green-50 via-green-100/30 to-blue-50/30 min-h-screen"> | ||
| 11 | + <div class="p-4"> | ||
| 12 | + <FrostedGlass class="p-4 rounded-xl"> | ||
| 13 | + <div class="mb-4"> | ||
| 14 | + <h1 class="text-xl font-medium mb-2">{{ message.title }}</h1> | ||
| 15 | + <div class="text-xs text-gray-500">{{ message.time }}</div> | ||
| 16 | + </div> | ||
| 17 | + <div class="text-gray-700 leading-relaxed whitespace-pre-wrap"> | ||
| 18 | + {{ message.content }} | ||
| 19 | + </div> | ||
| 20 | + </FrostedGlass> | ||
| 21 | + </div> | ||
| 22 | + </div> | ||
| 23 | + </AppLayout> | ||
| 24 | +</template> | ||
| 25 | + | ||
| 26 | +<script setup> | ||
| 27 | +import { ref, onMounted } from 'vue'; | ||
| 28 | +import { useRoute } from 'vue-router'; | ||
| 29 | +import AppLayout from '@/components/layout/AppLayout.vue'; | ||
| 30 | +import FrostedGlass from '@/components/ui/FrostedGlass.vue'; | ||
| 31 | + | ||
| 32 | +const route = useRoute(); | ||
| 33 | +const message = ref({ | ||
| 34 | + title: '', | ||
| 35 | + content: '', | ||
| 36 | + time: '', | ||
| 37 | + isRead: false | ||
| 38 | +}); | ||
| 39 | + | ||
| 40 | +// 模拟获取消息详情 | ||
| 41 | +const mockMessage = { | ||
| 42 | + id: 1, | ||
| 43 | + title: '课程更新通知', | ||
| 44 | + content: '亲爱的用户:\n\n您关注的课程《亲子教育入门》已更新最新一期内容!\n\n本次更新包含以下内容:\n1. 亲子沟通的技巧与方法\n2. 如何培养孩子的学习兴趣\n3. 处理孩子叛逆期的建议\n\n快来查看最新内容,提升您的育儿技能吧!', | ||
| 45 | + time: '2024-01-10 10:30', | ||
| 46 | + isRead: false | ||
| 47 | +}; | ||
| 48 | + | ||
| 49 | +onMounted(() => { | ||
| 50 | + // 模拟异步获取消息详情 | ||
| 51 | + setTimeout(() => { | ||
| 52 | + const messageId = parseInt(route.params.id); | ||
| 53 | + message.value = { ...mockMessage, id: messageId }; | ||
| 54 | + // 更新消息已读状态 | ||
| 55 | + message.value.isRead = true; | ||
| 56 | + }, 500); | ||
| 57 | +}); | ||
| 58 | +</script> |
src/views/profile/MessagesPage.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2025-03-24 12:56:07 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-24 12:56:09 | ||
| 5 | + * @FilePath: /mlaj/src/views/profile/MessagesPage.vue | ||
| 6 | + * @Description: 消息中心页面 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <AppLayout title="消息中心"> | ||
| 10 | + <div class="bg-gradient-to-br from-green-50 via-green-100/30 to-blue-50/30 min-h-screen"> | ||
| 11 | + <van-list | ||
| 12 | + v-model:loading="loading" | ||
| 13 | + :finished="finished" | ||
| 14 | + finished-text="没有更多了" | ||
| 15 | + @load="onLoad" | ||
| 16 | + class="px-4 py-4" | ||
| 17 | + > | ||
| 18 | + <FrostedGlass | ||
| 19 | + v-for="message in messages" | ||
| 20 | + :key="message.id" | ||
| 21 | + class="mb-4 rounded-xl overflow-hidden" | ||
| 22 | + @click="handleMessageClick(message)" | ||
| 23 | + > | ||
| 24 | + <div class="p-4"> | ||
| 25 | + <div class="flex justify-between items-start mb-2"> | ||
| 26 | + <h3 class="text-base font-medium flex items-center"> | ||
| 27 | + <span | ||
| 28 | + v-if="!message.isRead" | ||
| 29 | + class="w-2 h-2 bg-red-500 rounded-full mr-2" | ||
| 30 | + ></span> | ||
| 31 | + {{ message.title }} | ||
| 32 | + </h3> | ||
| 33 | + <span class="text-xs text-gray-500">{{ message.time }}</span> | ||
| 34 | + </div> | ||
| 35 | + <p class="text-sm text-gray-600 line-clamp-2">{{ message.content }}</p> | ||
| 36 | + </div> | ||
| 37 | + </FrostedGlass> | ||
| 38 | + </van-list> | ||
| 39 | + </div> | ||
| 40 | + </AppLayout> | ||
| 41 | +</template> | ||
| 42 | + | ||
| 43 | +<script setup> | ||
| 44 | +import { ref } from 'vue'; | ||
| 45 | +import { useRouter } from 'vue-router'; | ||
| 46 | +import AppLayout from '@/components/layout/AppLayout.vue'; | ||
| 47 | +import FrostedGlass from '@/components/ui/FrostedGlass.vue'; | ||
| 48 | + | ||
| 49 | +const router = useRouter(); | ||
| 50 | +const loading = ref(false); | ||
| 51 | +const finished = ref(false); | ||
| 52 | +const messages = ref([]); | ||
| 53 | +const page = ref(1); | ||
| 54 | + | ||
| 55 | +// 模拟消息数据 | ||
| 56 | +const mockMessages = [ | ||
| 57 | + { | ||
| 58 | + id: 1, | ||
| 59 | + title: '课程更新通知', | ||
| 60 | + content: '您关注的课程《亲子教育入门》已更新最新一期内容,快来查看吧!', | ||
| 61 | + time: '2024-01-10 10:30', | ||
| 62 | + isRead: false | ||
| 63 | + }, | ||
| 64 | + { | ||
| 65 | + id: 2, | ||
| 66 | + title: '活动提醒', | ||
| 67 | + content: '您报名的「亲子互动工作坊」将于本周六下午2点开始,请准时参加。', | ||
| 68 | + time: '2024-01-09 15:20', | ||
| 69 | + isRead: true | ||
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + id: 3, | ||
| 73 | + title: '系统通知', | ||
| 74 | + content: '为了给您提供更好的服务,我们的App将于今晚凌晨2点进行系统升级维护。', | ||
| 75 | + time: '2024-01-08 18:00', | ||
| 76 | + isRead: false | ||
| 77 | + } | ||
| 78 | +]; | ||
| 79 | + | ||
| 80 | +// 加载更多 | ||
| 81 | +const onLoad = () => { | ||
| 82 | + // 模拟异步加载数据 | ||
| 83 | + setTimeout(() => { | ||
| 84 | + if (page.value === 1) { | ||
| 85 | + messages.value = mockMessages; | ||
| 86 | + } else { | ||
| 87 | + // 模拟没有更多数据 | ||
| 88 | + finished.value = true; | ||
| 89 | + } | ||
| 90 | + loading.value = false; | ||
| 91 | + page.value++; | ||
| 92 | + }, 1000); | ||
| 93 | +}; | ||
| 94 | + | ||
| 95 | +// 更新消息已读状态 | ||
| 96 | +const updateMessageReadStatus = (messageId) => { | ||
| 97 | + const index = messages.value.findIndex(msg => msg.id === messageId); | ||
| 98 | + if (index !== -1) { | ||
| 99 | + messages.value[index].isRead = true; | ||
| 100 | + } | ||
| 101 | +}; | ||
| 102 | + | ||
| 103 | +// 处理消息点击 | ||
| 104 | +const handleMessageClick = (message) => { | ||
| 105 | + updateMessageReadStatus(message.id); | ||
| 106 | + router.push(`/profile/messages/${message.id}`); | ||
| 107 | +}; | ||
| 108 | +</script> |
-
Please register or login to post a comment