From 95cb69b9f79893d7cd1319d754064c93e3fa4e2f Mon Sep 17 00:00:00 2001 From: seatonwan9 Date: 星期二, 19 八月 2025 18:15:56 +0800 Subject: [PATCH] 提交源码 --- src/api/orderApi.ts | 26 +++++++++++++ src/api/cartApi.ts | 63 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-) diff --git a/src/api/cartApi.ts b/src/api/cartApi.ts new file mode 100644 index 0000000..2d46ee8 --- /dev/null +++ b/src/api/cartApi.ts @@ -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 diff --git a/src/api/orderApi.ts b/src/api/orderApi.ts new file mode 100644 index 0000000..835ef2b --- /dev/null +++ b/src/api/orderApi.ts @@ -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 -- Gitblit v1.8.0