Vue3 前端补充:秒杀和商品 API 类型定义及首页更新
- 添加 flashsale/product API 接口模块 - 添加 flashsale/product TypeScript 类型定义 - 更新首页组件
This commit is contained in:
34
flash-sale-frontend/src/api/flashsale.ts
Normal file
34
flash-sale-frontend/src/api/flashsale.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import request from './request'
|
||||
import type { FlashSale, FlashSaleParams } from '@/types/flashsale'
|
||||
|
||||
export const flashSaleApi = {
|
||||
// 获取秒杀活动列表
|
||||
getList(params?: FlashSaleParams) {
|
||||
return request.get<any, { list: FlashSale[], total: number }>('/api/flashsales', { params })
|
||||
},
|
||||
|
||||
// 获取秒杀活动详情
|
||||
getDetail(id: number) {
|
||||
return request.get<any, FlashSale>(`/api/flashsales/${id}`)
|
||||
},
|
||||
|
||||
// 参与秒杀
|
||||
participate(flashSaleId: number, quantity: number = 1) {
|
||||
return request.post('/api/flashsales/participate', {
|
||||
flashSaleId,
|
||||
quantity
|
||||
})
|
||||
},
|
||||
|
||||
// 获取正在进行的秒杀活动
|
||||
getActive() {
|
||||
return request.get<any, FlashSale[]>('/api/flashsales/active')
|
||||
},
|
||||
|
||||
// 获取即将开始的秒杀活动
|
||||
getUpcoming() {
|
||||
return request.get<any, FlashSale[]>('/api/flashsales/upcoming')
|
||||
}
|
||||
}
|
||||
|
||||
export default flashSaleApi
|
||||
44
flash-sale-frontend/src/api/product.ts
Normal file
44
flash-sale-frontend/src/api/product.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import request from './request'
|
||||
import type { Product, ProductParams } from '@/types/product'
|
||||
|
||||
export const productApi = {
|
||||
// 获取商品列表
|
||||
getList(params?: ProductParams) {
|
||||
return request.get<any, { list: Product[], total: number }>('/api/products', { params })
|
||||
},
|
||||
|
||||
// 获取商品详情
|
||||
getDetail(id: number) {
|
||||
return request.get<any, Product>(`/api/products/${id}`)
|
||||
},
|
||||
|
||||
// 获取热门商品
|
||||
getHot(limit: number = 8) {
|
||||
return request.get<any, Product[]>('/api/products/hot', {
|
||||
params: { limit }
|
||||
})
|
||||
},
|
||||
|
||||
// 获取推荐商品
|
||||
getRecommended(limit: number = 8) {
|
||||
return request.get<any, Product[]>('/api/products/recommended', {
|
||||
params: { limit }
|
||||
})
|
||||
},
|
||||
|
||||
// 搜索商品
|
||||
search(keyword: string) {
|
||||
return request.get<any, Product[]>('/api/products/search', {
|
||||
params: { keyword }
|
||||
})
|
||||
},
|
||||
|
||||
// 按分类获取商品
|
||||
getByCategory(categoryId: number) {
|
||||
return request.get<any, Product[]>('/api/products/category', {
|
||||
params: { categoryId }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default productApi
|
||||
Reference in New Issue
Block a user