feat(app): initialize uni-app with routing, stores, and infrastructure
- Vue 3 + TypeScript + Pinia + SCSS - 3-tab navigation (home, booking, profile) + 11 sub-pages - HTTP client with JWT auth, request interceptors - Pinia stores: user (auth, profile, memberships), studio, booking - Utility functions: price formatting, date helpers - WeChat login helper - All pages as stubs ready for implementation
This commit is contained in:
71
packages/app/src/stores/booking.ts
Normal file
71
packages/app/src/stores/booking.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type {
|
||||
TimeSlotWithBookingStatus,
|
||||
BookingWithDetails,
|
||||
CreateBookingDto,
|
||||
} from '@mp-pilates/shared'
|
||||
import { get, post, put } from '../utils/request'
|
||||
|
||||
export const useBookingStore = defineStore('booking', () => {
|
||||
const slots = ref<readonly TimeSlotWithBookingStatus[]>([])
|
||||
const myBookings = ref<readonly BookingWithDetails[]>([])
|
||||
const upcomingBookings = ref<readonly BookingWithDetails[]>([])
|
||||
const loadingSlots = ref(false)
|
||||
const loadingBookings = ref(false)
|
||||
|
||||
async function fetchSlots(date: string) {
|
||||
loadingSlots.value = true
|
||||
try {
|
||||
slots.value = await get<TimeSlotWithBookingStatus[]>('/time-slot/available', { date })
|
||||
} catch (err) {
|
||||
console.error('Fetch slots failed:', err)
|
||||
slots.value = []
|
||||
} finally {
|
||||
loadingSlots.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createBooking(dto: CreateBookingDto) {
|
||||
const result = await post<BookingWithDetails>('/booking', dto as unknown as Record<string, unknown>)
|
||||
return result
|
||||
}
|
||||
|
||||
async function cancelBooking(bookingId: string) {
|
||||
const result = await put<BookingWithDetails>(`/booking/${bookingId}/cancel`)
|
||||
return result
|
||||
}
|
||||
|
||||
async function fetchMyBookings(status?: string) {
|
||||
loadingBookings.value = true
|
||||
try {
|
||||
const params = status ? { status } : {}
|
||||
myBookings.value = await get<BookingWithDetails[]>('/booking/my', params)
|
||||
} catch (err) {
|
||||
console.error('Fetch bookings failed:', err)
|
||||
} finally {
|
||||
loadingBookings.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUpcomingBookings() {
|
||||
try {
|
||||
upcomingBookings.value = await get<BookingWithDetails[]>('/booking/my/upcoming')
|
||||
} catch (err) {
|
||||
console.error('Fetch upcoming bookings failed:', err)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
slots,
|
||||
myBookings,
|
||||
upcomingBookings,
|
||||
loadingSlots,
|
||||
loadingBookings,
|
||||
fetchSlots,
|
||||
createBooking,
|
||||
cancelBooking,
|
||||
fetchMyBookings,
|
||||
fetchUpcomingBookings,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user