MessagesPage.vue
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!--
* @Date: 2025-03-24 12:56:07
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-06-12 15:34:41
* @FilePath: /mlaj/src/views/profile/MessagesPage.vue
* @Description: 消息中心页面
-->
<template>
<AppLayout>
<div class="bg-gradient-to-br from-green-50 via-green-100/30 to-blue-50/30 min-h-screen">
<van-list
v-model:loading="loading"
:finished="finished"
:finished-text="finishText"
@load="onLoad"
class="px-4 py-4"
>
<FrostedGlass
v-for="message in messages"
:key="message.id"
class="mb-4 rounded-xl overflow-hidden"
@click="handleMessageClick(message)"
>
<div class="p-4">
<div class="flex justify-between items-start mb-2">
<h3 class="text-base font-medium flex items-center">
<span v-if="!message.isRead" class="w-2 h-2 bg-red-500 rounded-full mr-2"></span>
<!-- {{ message.title }} -->
消息
</h3>
<span class="text-xs text-gray-500">{{ message.created_time }}</span>
</div>
<p class="text-sm text-gray-600 line-clamp-2">{{ message.note }}</p>
</div>
</FrostedGlass>
</van-list>
<!-- 无数据提示 -->
<div
v-if="!loading && messages.length === 0"
class="flex flex-col items-center justify-center py-12"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-16 w-16 text-gray-300"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
/>
</svg>
<p class="mt-4 text-gray-500">暂无消息</p>
</div>
</div>
</AppLayout>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import AppLayout from '@/components/layout/AppLayout.vue';
import FrostedGlass from '@/components/ui/FrostedGlass.vue';
import { useTitle } from '@vueuse/core';
// 导入接口
import { getNewsListAPI } from '@/api/news';
const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);
const router = useRouter();
const loading = ref(false);
const finished = ref(false);
const messages = ref([]);
const limit = ref(10);
const page = ref(0);
const finishText = ref('没有更多了');
// 加载更多
const onLoad = async() => {
const res = await getNewsListAPI({ page: page.value, limit: limit.value });
if (res.code) {
messages.value = [...messages.value, ...res.data];
finished.value = res.data.length < limit.value;
page.value++;
loading.value = false;
} else {
loading.value = false;
finished.value = true;
finishText.value = '';
}
};
// 更新消息已读状态
const updateMessageReadStatus = (messageId) => {
const index = messages.value.findIndex(msg => msg.id === messageId);
if (index !== -1) {
messages.value[index].isRead = true;
}
};
// 处理消息点击
const handleMessageClick = (message) => {
return;
updateMessageReadStatus(message.id);
router.push(`/profile/messages/${message.id}`);
};
</script>