购物车和订单中心以及优惠券相关功能初版
This commit is contained in:
@@ -17,12 +17,15 @@ const adminApi = axios.create({
|
||||
|
||||
adminApi.interceptors.request.use(
|
||||
config => {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
// 登录请求不需要携带Token
|
||||
if (!config.url?.includes('/auth/login')) {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
|
||||
@@ -44,6 +44,10 @@ export const authApi = {
|
||||
return api.post<LoginResponse>('/user/login', data)
|
||||
},
|
||||
|
||||
adminLogin: (data: LoginRequest) => {
|
||||
return api.post<LoginResponse>('/admin/api/auth/login', data)
|
||||
},
|
||||
|
||||
register: (data: RegisterRequest) => {
|
||||
return api.post('/user/register', data)
|
||||
},
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import api from './index'
|
||||
|
||||
interface CartItem {
|
||||
productId: number
|
||||
quantity: number
|
||||
}
|
||||
|
||||
export const cartApi = {
|
||||
// 添加商品到购物车
|
||||
addToCart: (item: CartItem) => {
|
||||
return api.post('/cart/add', item)
|
||||
},
|
||||
|
||||
// 从购物车移除商品
|
||||
removeFromCart: (productId: number) => {
|
||||
return api.delete(`/cart/remove/${productId}`)
|
||||
},
|
||||
|
||||
// 更新购物车商品数量
|
||||
updateCartQuantity: (item: CartItem) => {
|
||||
return api.put('/cart/update', item)
|
||||
},
|
||||
|
||||
// 获取购物车列表
|
||||
getCartList: () => {
|
||||
return api.get('/cart/list')
|
||||
},
|
||||
|
||||
// 清空购物车
|
||||
clearCart: () => {
|
||||
return api.delete('/cart/clear')
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,8 @@ api.interceptors.response.use(
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/shop/list/simple')
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import api from './index'
|
||||
|
||||
interface CreateOrderRequest {
|
||||
couponId?: number
|
||||
}
|
||||
|
||||
export const orderApi = {
|
||||
// 创建订单
|
||||
createOrder: (data: CreateOrderRequest) => {
|
||||
return api.post('/order/create', data)
|
||||
},
|
||||
|
||||
// 获取订单列表
|
||||
getOrderList: () => {
|
||||
return api.get('/order/list')
|
||||
},
|
||||
|
||||
// 获取订单详情
|
||||
getOrderDetail: (orderId: number) => {
|
||||
return api.get(`/order/detail/${orderId}`)
|
||||
},
|
||||
|
||||
// 取消订单
|
||||
cancelOrder: (orderId: number) => {
|
||||
return api.put(`/order/cancel/${orderId}`)
|
||||
},
|
||||
|
||||
// 后台获取所有订单
|
||||
getAllOrders: () => {
|
||||
return api.get('/order/admin/list')
|
||||
},
|
||||
|
||||
// 后台处理订单
|
||||
processOrder: (orderId: number, status: number) => {
|
||||
return api.put(`/order/admin/process/${orderId}`, {}, {
|
||||
params: { status }
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user