seatonwan9
2025-08-19 95cb69b9f79893d7cd1319d754064c93e3fa4e2f
提交源码
2个文件已添加
89 ■■■■■ 已修改文件
src/api/cartApi.ts 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/orderApi.ts 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/cartApi.ts
New file
@@ -0,0 +1,63 @@
import createAxios from '@/utils/axios'
// 购物车管理 API
const baseUrl = '/admin/api/cart'
const cartApi = {
  // 添加商品到购物车
  addToCart(data: any, userId: number, unitId: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/add`,
      method: 'post',
      data,
      params: { userId, unitId }
    }) as ApiPromise
  },
  // 从购物车移除商品
  removeFromCart(userId: number, unitId: number, pricingId: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/remove`,
      method: 'delete',
      params: { userId, unitId, pricingId }
    }) as ApiPromise
  },
  // 更新购物车商品数量
  updateCartItem(userId: number, unitId: number, pricingId: number, quantity: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/update`,
      method: 'put',
      params: { userId, unitId, pricingId, quantity }
    }) as ApiPromise
  },
  // 获取购物车信息
  getCartInfo(userId: number, unitId: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/info`,
      method: 'get',
      params: { userId, unitId }
    }) as ApiPromise
  },
  // 获取购物车商品列表
  getCartItems(userId: number, unitId: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/items`,
      method: 'get',
      params: { userId, unitId }
    }) as ApiPromise
  },
  // 清空购物车
  clearCart(userId: number, unitId: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/clear`,
      method: 'delete',
      params: { userId, unitId }
    }) as ApiPromise
  }
}
export default cartApi
src/api/orderApi.ts
New file
@@ -0,0 +1,26 @@
import createAxios from '@/utils/axios'
const baseUrl = '/admin/api/order'
const orderApi = {
  // 获取一次性防重复提交 Token
  getIdempotencyToken(userId?: number): ApiPromise {
    return createAxios({
      url: `${baseUrl}/idempotency/token`,
      method: 'get',
      params: userId ? { userId } : {}
    }) as ApiPromise
  },
  // 创建订单(在 headers 中携带 Idempotency-Token)
  createOrder(data: any, token: string): ApiPromise {
    return createAxios({
      url: `${baseUrl}/create`,
      method: 'post',
      data,
      headers: { 'Idempotency-Token': token }
    }) as ApiPromise
  }
}
export default orderApi