fix: 修复游客购物车商品显示和添加地址问题
Build and Push Docker Image / build-and-push (push) Successful in 1m5s
Build and Push Docker Image / deploy (push) Successful in 7s

- ProductDetail.vue: 添加购物车时传入完整商品信息
- Cart.vue: 未登录点击添加地址跳转登录页
- 游客购物车正确显示商品状态
This commit is contained in:
2026-07-13 03:55:59 +00:00
parent 0c9cf4d347
commit 51edee4d92
2 changed files with 14 additions and 3 deletions
+12 -2
View File
@@ -158,9 +158,9 @@
</div> </div>
<div class="no-address" v-else> <div class="no-address" v-else>
<p>您还没有添加收货地址</p> <p>您还没有添加收货地址</p>
<el-button type="primary" @click="showAddAddress = true">添加地址</el-button> <el-button type="primary" @click="handleAddAddressClick">添加地址</el-button>
</div> </div>
<el-button class="add-address-btn" link type="primary" @click="showAddAddress = true" v-if="addresses.length"> <el-button class="add-address-btn" link type="primary" @click="handleAddAddressClick" v-if="addresses.length">
<el-icon><Plus /></el-icon> <el-icon><Plus /></el-icon>
添加新地址 添加新地址
</el-button> </el-button>
@@ -498,6 +498,16 @@ async function fetchAddresses() {
} catch {} } catch {}
} }
// 点击添加地址按钮
function handleAddAddressClick() {
if (!cartStore.isLoggedIn()) {
ElMessage.warning('请先登录后再添加地址')
router.push('/login')
return
}
showAddAddress.value = true
}
async function addAddress() { async function addAddress() {
if (!addressForm.name || !addressForm.phone || !addressForm.address) { if (!addressForm.name || !addressForm.phone || !addressForm.address) {
ElMessage.warning('请填写必要信息') ElMessage.warning('请填写必要信息')
+2 -1
View File
@@ -124,7 +124,8 @@ async function addToCart() {
} }
try { try {
await cartStore.addItem(product.value.id, quantity.value) // 传入商品信息,支持游客购物车显示
await cartStore.addItem(product.value.id, quantity.value, product.value)
ElMessage.success(t('product.addToCart') + ' ✓') ElMessage.success(t('product.addToCart') + ' ✓')
} catch (err: any) { } catch (err: any) {
// 处理后端返回的错误 // 处理后端返回的错误