fix(menu): 购物车莫名其妙消失

This commit is contained in:
Kroytz committed 2026-07-24 14:08:19 +08:00
1 parent b9246f3e97
commit 140afd88a1
1 file changed
+9 -4
+9 -4
View File
@@ -137,7 +137,7 @@
<image src="/static/images/menu/cart.png" class="cart-img" @tap="openCartPopup"></image> <image src="/static/images/menu/cart.png" class="cart-img" @tap="openCartPopup"></image>
<view class="tag" v-show="getCartGoodsNumber">{{ getCartGoodsNumber }}</view> <view class="tag" v-show="getCartGoodsNumber">{{ getCartGoodsNumber }}</view>
</view> </view>
<view class="price" @tap="openCartShow"> <view class="price" @tap="openCartPopup">
<view class="price__amount">¥{{ getCartGoodsPrice }}</view> <view class="price__amount">¥{{ getCartGoodsPrice }}</view>
<view v-if="deliveryTipText" class="price__tip">{{ deliveryTipText }}</view> <view v-if="deliveryTipText" class="price__tip">{{ deliveryTipText }}</view>
</view> </view>
@@ -462,14 +462,12 @@ onHide(() => {
}) })
onShow(() => { onShow(() => {
//init(); //init();
isCartShow.value = true
refreshCart() refreshCart()
shopAd.value = uni.getStorageSync('shopAd') shopAd.value = uni.getStorageSync('shopAd')
loadAddressesForDelivery() loadAddressesForDelivery()
}) })
const openCartShow = () =>{
isCartShow.value = false
}
const in_array = (search, array) => { const in_array = (search, array) => {
for (var i in array) { for (var i in array) {
if (array[i] == search) { if (array[i] == search) {
@@ -751,6 +749,7 @@ const calcSize = () => {
sizeCalcState.value = true sizeCalcState.value = true
} }
const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车 const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
isCartShow.value = true
const valueStr = newGood.valueStr || '' const valueStr = newGood.valueStr || ''
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr) const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
if (index > -1) { if (index > -1) {
@@ -769,6 +768,7 @@ const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value))) uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
} }
const adjustSimpleGood = (cate, newGood, num) => { const adjustSimpleGood = (cate, newGood, num) => {
isCartShow.value = true
const valueStr = defaultSpec(newGood) const valueStr = defaultSpec(newGood)
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr) const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
if (num > 0) { if (num > 0) {
@@ -848,6 +848,8 @@ const handleAddToCartInModal = () => {
closeGoodDetailModal() closeGoodDetailModal()
} }
const openCartPopup = () => { //打开/关闭购物车列表popup const openCartPopup = () => { //打开/关闭购物车列表popup
isCartShow.value = true
if (!cart.value.length) return
popup.value.open() popup.value.open()
} }
const handleCartClear = () => { //清空购物车 const handleCartClear = () => { //清空购物车
@@ -866,10 +868,12 @@ const handleCartClear = () => { //清空购物车
}) })
} }
const handleCartItemAdd = (index) => { const handleCartItemAdd = (index) => {
isCartShow.value = true
cart.value[index].number += 1 cart.value[index].number += 1
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value))) uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
} }
const handleCartItemReduce = (index) => { const handleCartItemReduce = (index) => {
isCartShow.value = true
if (cart.value[index].number === 1) { if (cart.value[index].number === 1) {
cart.value.splice(index, 1) cart.value.splice(index, 1)
} else { } else {
@@ -877,6 +881,7 @@ const handleCartItemReduce = (index) => {
} }
if (!cart.value.length) { if (!cart.value.length) {
cartPopupVisible.value = false cartPopupVisible.value = false
popup.value?.close?.()
} }
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value))) uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
} }