优化
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user