From 51edee4d92db95f77af6d284441096bdb3d2f465 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 13 Jul 2026 03:55:59 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B8=B8=E5=AE=A2?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=95=86=E5=93=81=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E5=9C=B0=E5=9D=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ProductDetail.vue: 添加购物车时传入完整商品信息 - Cart.vue: 未登录点击添加地址跳转登录页 - 游客购物车正确显示商品状态 --- frontend/src/views/user/Cart.vue | 14 ++++++++++++-- frontend/src/views/user/ProductDetail.vue | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/user/Cart.vue b/frontend/src/views/user/Cart.vue index ab6f6e1..38cd938 100644 --- a/frontend/src/views/user/Cart.vue +++ b/frontend/src/views/user/Cart.vue @@ -158,9 +158,9 @@

您还没有添加收货地址

- 添加地址 + 添加地址
- + 添加新地址 @@ -498,6 +498,16 @@ async function fetchAddresses() { } catch {} } +// 点击添加地址按钮 +function handleAddAddressClick() { + if (!cartStore.isLoggedIn()) { + ElMessage.warning('请先登录后再添加地址') + router.push('/login') + return + } + showAddAddress.value = true +} + async function addAddress() { if (!addressForm.name || !addressForm.phone || !addressForm.address) { ElMessage.warning('请填写必要信息') diff --git a/frontend/src/views/user/ProductDetail.vue b/frontend/src/views/user/ProductDetail.vue index 9b527e3..4ef4ada 100644 --- a/frontend/src/views/user/ProductDetail.vue +++ b/frontend/src/views/user/ProductDetail.vue @@ -124,7 +124,8 @@ async function addToCart() { } try { - await cartStore.addItem(product.value.id, quantity.value) + // 传入商品信息,支持游客购物车显示 + await cartStore.addItem(product.value.id, quantity.value, product.value) ElMessage.success(t('product.addToCart') + ' ✓') } catch (err: any) { // 处理后端返回的错误