fix: update some files
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m44s

This commit is contained in:
luo
2026-08-18 17:36:41 +08:00
parent 93f67967c5
commit d9d07422a9
38 changed files with 1140 additions and 728 deletions

View File

@@ -1,7 +1,12 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { NotificationService } from '@/api/modules/notification'
import type { NotificationItem, NotificationUnreadSummary } from '@/types/api'
import type {
BaseResponse,
NotificationItem,
NotificationListResponse,
NotificationUnreadSummary
} from '@/types/api'
const emptySummary = (): NotificationUnreadSummary => ({
approval: 0,
@@ -16,8 +21,22 @@ export const useNotificationStore = defineStore('notificationStore', () => {
const displayCount = ref('0')
const summary = ref<NotificationUnreadSummary>(emptySummary())
const recentNotifications = ref<NotificationItem[]>([])
const notificationPage = ref(1)
const notificationPageSize = 10
const notificationTotal = ref(0)
const loading = ref(false)
const applyNotificationList = (
response: BaseResponse<NotificationListResponse>,
fallbackPage: number
) => {
if (response.code !== 0 || !response.data) return
recentNotifications.value = response.data.items
notificationPage.value = response.data.page || fallbackPage
notificationTotal.value = Math.max(0, response.data.total || 0)
}
const refreshUnreadCount = async () => {
const response = await NotificationService.getUnreadCount()
if (response.code === 0 && response.data) {
@@ -27,19 +46,33 @@ export const useNotificationStore = defineStore('notificationStore', () => {
return unreadCount.value
}
const refreshSummary = async () => {
const loadNotifications = async (page = notificationPage.value) => {
const targetPage = Math.max(1, page)
loading.value = true
try {
const response = await NotificationService.getNotifications({
page: targetPage,
page_size: notificationPageSize
})
applyNotificationList(response, targetPage)
return response
} finally {
loading.value = false
}
}
const refreshSummary = async (page = 1) => {
const targetPage = Math.max(1, page)
loading.value = true
try {
const [summaryResponse, listResponse] = await Promise.all([
NotificationService.getUnreadSummary(),
NotificationService.getNotifications({ page: 1, page_size: 10 })
NotificationService.getNotifications({ page: targetPage, page_size: notificationPageSize })
])
if (summaryResponse.code === 0 && summaryResponse.data) {
summary.value = summaryResponse.data
}
if (listResponse.code === 0 && listResponse.data) {
recentNotifications.value = listResponse.data.items.slice(0, 10)
}
applyNotificationList(listResponse, targetPage)
await refreshUnreadCount()
return summary.value
} finally {
@@ -50,7 +83,7 @@ export const useNotificationStore = defineStore('notificationStore', () => {
const markRead = async (id: number) => {
const response = await NotificationService.markRead(id)
if (response.code === 0) {
await refreshSummary()
await refreshSummary(notificationPage.value)
}
return response
}
@@ -58,7 +91,7 @@ export const useNotificationStore = defineStore('notificationStore', () => {
const markAllRead = async (category?: string) => {
const response = await NotificationService.markAllRead(category ? { category } : {})
if (response.code === 0) {
await refreshSummary()
await refreshSummary(notificationPage.value)
}
return response
}
@@ -68,8 +101,12 @@ export const useNotificationStore = defineStore('notificationStore', () => {
displayCount,
summary,
recentNotifications,
notificationPage,
notificationPageSize,
notificationTotal,
loading,
refreshUnreadCount,
loadNotifications,
refreshSummary,
markRead,
markAllRead