This commit is contained in:
2026-08-12 18:24:03 +08:00
parent 3366c58a5e
commit 13a856cef9
11 changed files with 228 additions and 1 deletions
@@ -0,0 +1,27 @@
import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import { getMyUnreadNotificationCount } from '../api/notifications'
export const useNotificationsStore = defineStore('client-notifications', () => {
const unreadCount = ref<number | null>(null)
const loading = ref(false)
const errorMessage = ref('')
const hasUnread = computed(() => (unreadCount.value ?? 0) > 0)
async function refreshUnreadCount() {
loading.value = true
errorMessage.value = ''
try {
unreadCount.value = await getMyUnreadNotificationCount()
} catch (error) {
unreadCount.value = null
errorMessage.value = error instanceof Error ? error.message : '未读数量加载失败'
} finally {
loading.value = false
}
}
return { unreadCount, hasUnread, loading, errorMessage, refreshUnreadCount }
})