feat: 支持秒杀活动
This commit is contained in:
@@ -15,6 +15,9 @@ import type {
|
||||
PaginatedData,
|
||||
ScheduleSlotPreview,
|
||||
PublishDaySlotsDto,
|
||||
FlashSaleAdminItem,
|
||||
CreateFlashSaleDto,
|
||||
UpdateFlashSaleDto,
|
||||
} from '@mp-pilates/shared'
|
||||
|
||||
export interface AdminStats {
|
||||
@@ -206,6 +209,26 @@ export const useAdminStore = defineStore('admin', () => {
|
||||
return get<AdminStats>('/admin/stats')
|
||||
}
|
||||
|
||||
// ── Flash sales ─────────────────────────────────────────────────
|
||||
async function fetchFlashSales(params?: {
|
||||
page?: number
|
||||
limit?: number
|
||||
}): Promise<PaginatedData<FlashSaleAdminItem>> {
|
||||
return get<PaginatedData<FlashSaleAdminItem>>('/admin/flash-sales', params as Record<string, unknown>)
|
||||
}
|
||||
|
||||
async function createFlashSale(dto: CreateFlashSaleDto): Promise<FlashSaleAdminItem> {
|
||||
return post<FlashSaleAdminItem>('/admin/flash-sales', dto as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
async function updateFlashSale(id: string, dto: UpdateFlashSaleDto): Promise<FlashSaleAdminItem> {
|
||||
return put<FlashSaleAdminItem>(`/admin/flash-sales/${id}`, dto as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
async function deleteFlashSale(id: string): Promise<{ deleted: boolean }> {
|
||||
return del<{ deleted: boolean }>(`/admin/flash-sales/${id}`)
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
weekTemplates,
|
||||
@@ -243,5 +266,10 @@ export const useAdminStore = defineStore('admin', () => {
|
||||
publishDaySlots,
|
||||
// Stats
|
||||
fetchDashboardStats,
|
||||
// Flash sales
|
||||
fetchFlashSales,
|
||||
createFlashSale,
|
||||
updateFlashSale,
|
||||
deleteFlashSale,
|
||||
}
|
||||
})
|
||||
|
||||
43
packages/app/src/stores/flash-sale.ts
Normal file
43
packages/app/src/stores/flash-sale.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type {
|
||||
FlashSaleListItem,
|
||||
FlashSaleDetail,
|
||||
FlashSalePurchaseResponse,
|
||||
} from '@mp-pilates/shared'
|
||||
import { get, post } from '../utils/request'
|
||||
|
||||
export const useFlashSaleStore = defineStore('flash-sale', () => {
|
||||
const flashSales = ref<FlashSaleListItem[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchFlashSales(): Promise<FlashSaleListItem[]> {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await get<FlashSaleListItem[]>('/flash-sales')
|
||||
flashSales.value = [...data]
|
||||
return data
|
||||
} catch {
|
||||
flashSales.value = []
|
||||
return []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchDetail(id: string): Promise<FlashSaleDetail> {
|
||||
return get<FlashSaleDetail>(`/flash-sales/${id}`)
|
||||
}
|
||||
|
||||
async function purchase(id: string): Promise<FlashSalePurchaseResponse> {
|
||||
return post<FlashSalePurchaseResponse>(`/flash-sales/${id}/purchase`)
|
||||
}
|
||||
|
||||
return {
|
||||
flashSales,
|
||||
loading,
|
||||
fetchFlashSales,
|
||||
fetchDetail,
|
||||
purchase,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user