perf: 修复我的约课列表不展示的问题
This commit is contained in:
@@ -7,6 +7,14 @@ import type {
|
||||
} from '@mp-pilates/shared'
|
||||
import { get, post, put } from '../utils/request'
|
||||
|
||||
/** Server paginated responses use `data` field, not `items` from the shared type */
|
||||
interface ServerPaginatedResult<T> {
|
||||
readonly data: readonly T[]
|
||||
readonly total: number
|
||||
readonly page: number
|
||||
readonly limit: number
|
||||
}
|
||||
|
||||
export const useBookingStore = defineStore('booking', () => {
|
||||
const slots = ref<readonly TimeSlotWithBookingStatus[]>([])
|
||||
const myBookings = ref<readonly BookingWithDetails[]>([])
|
||||
@@ -39,10 +47,12 @@ export const useBookingStore = defineStore('booking', () => {
|
||||
async function fetchMyBookings(status?: string) {
|
||||
loadingBookings.value = true
|
||||
try {
|
||||
const params = status ? { status } : {}
|
||||
myBookings.value = await get<BookingWithDetails[]>('/booking/my', params)
|
||||
const params: Record<string, unknown> = status ? { status } : {}
|
||||
const paginated = await get<ServerPaginatedResult<BookingWithDetails>>('/booking/my', params)
|
||||
myBookings.value = Array.isArray(paginated.data) ? paginated.data : []
|
||||
} catch (err) {
|
||||
console.error('Fetch bookings failed:', err)
|
||||
myBookings.value = []
|
||||
} finally {
|
||||
loadingBookings.value = false
|
||||
}
|
||||
@@ -50,9 +60,11 @@ export const useBookingStore = defineStore('booking', () => {
|
||||
|
||||
async function fetchUpcomingBookings() {
|
||||
try {
|
||||
upcomingBookings.value = await get<BookingWithDetails[]>('/booking/my/upcoming')
|
||||
const result = await get<BookingWithDetails[]>('/booking/my/upcoming')
|
||||
upcomingBookings.value = Array.isArray(result) ? result : []
|
||||
} catch (err) {
|
||||
console.error('Fetch upcoming bookings failed:', err)
|
||||
upcomingBookings.value = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user