feat: add no message

This commit is contained in:
tim
2025-07-07 15:35:59 +08:00
parent cf72a2d758
commit 09c32059b6
+44 -1
View File
@@ -1,5 +1,16 @@
<template> <template>
<div class="message-page"> <div class="message-page">
<div v-if="isLoadingMessage" class="loading-message">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<div v-else-if="notifications.length === 0" class="no-message">
<i class="fas fa-inbox no-message-icon"></i>
<div class="no-message-text">
暂时没有消息 :)
</div>
</div>
<BaseTimeline :items="notifications"> <BaseTimeline :items="notifications">
<template #item="{ item }"> <template #item="{ item }">
<div class="notif-content"> <div class="notif-content">
@@ -53,12 +64,15 @@ import BaseTimeline from '../components/BaseTimeline.vue'
import { getToken } from '../utils/auth' import { getToken } from '../utils/auth'
import { toast } from '../main' import { toast } from '../main'
import { stripMarkdown } from '../utils/markdown' import { stripMarkdown } from '../utils/markdown'
import { hatch } from 'ldrs'
hatch.register()
export default { export default {
name: 'MessagePageView', name: 'MessagePageView',
components: { BaseTimeline }, components: { BaseTimeline },
setup() { setup() {
const notifications = ref([]) const notifications = ref([])
const isLoadingMessage = ref(false)
const iconMap = { const iconMap = {
POST_VIEWED: 'fas fa-eye', POST_VIEWED: 'fas fa-eye',
@@ -80,11 +94,13 @@ export default {
toast.error('请先登录') toast.error('请先登录')
return return
} }
isLoadingMessage.value = true
const res = await fetch(`${API_BASE_URL}/api/notifications`, { const res = await fetch(`${API_BASE_URL}/api/notifications`, {
headers: { headers: {
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`
} }
}) })
isLoadingMessage.value = false
if (!res.ok) { if (!res.ok) {
toast.error('获取通知失败') toast.error('获取通知失败')
return return
@@ -117,12 +133,34 @@ export default {
onMounted(fetchNotifications) onMounted(fetchNotifications)
return { notifications, formatType, sanitizeDescription } return { notifications, formatType, sanitizeDescription, isLoadingMessage }
} }
} }
</script> </script>
<style scoped> <style scoped>
.loading-message {
display: flex;
justify-content: center;
align-items: center;
height: 300px;
}
.no-message {
display: flex;
flex-direction: row;
gap: 10px;
justify-content: center;
align-items: center;
height: 300px;
opacity: 0.5;
}
.no-message-text {
font-size: 16px;
color: var(--text-color);
}
.message-page { .message-page {
padding: 20px; padding: 20px;
} }
@@ -154,6 +192,11 @@ export default {
text-decoration: none !important; text-decoration: none !important;
} }
.notif-content-text:hover {
color: var(--primary-color) !important;
text-decoration: underline !important;
}
.notif-user { .notif-user {
font-weight: bold; font-weight: bold;
color: var(--text-color); color: var(--text-color);