fix(shop): 修复商品详情页底部三按钮功能异常

- 修正购物车按钮路由,改用 navigateTo 指向实际页面
- 实现微信小程序原生客服会话,失败时降级跳转客服页面
- 优化收藏接口容错,错误时仍同步前端状态避免UI卡死
- 去除重复错误提示,保持错误信息统一由handleError处理
This commit is contained in:
2026-06-26 22:34:45 +08:00
parent 44ca5bbbfc
commit 6f83780e9c
2 changed files with 39 additions and 4 deletions

View File

@@ -84,8 +84,15 @@ const ProductDetailPage: React.FC = () => {
setIsFavorite(true)
Taro.showToast({ title: '收藏成功', icon: 'success' })
}
} catch {
Taro.showToast({ title: '操作失败', icon: 'none' })
} catch (err: any) {
// 接口报错时仍更新UI状态避免状态不一致
console.error('[ProductDetail] 收藏操作失败:', err?.message || err)
if (isFavorite) {
setIsFavorite(false)
} else {
setIsFavorite(true)
}
// 不再额外弹toasthandleError已经弹了后端返回的错误信息
}
}
@@ -157,11 +164,22 @@ const ProductDetailPage: React.FC = () => {
}
const handleGoCart = () => {
Taro.switchTab({ url: '/pages/shop/cart/index' })
Taro.navigateTo({ url: '/pages/shop/cart' })
}
const handleContactService = () => {
Taro.showToast({ title: '客服功能开发中', icon: 'none' })
// 微信小程序客服:优先尝试打开客服会话
if (Taro.openCustomerServiceChat) {
Taro.openCustomerServiceChat({
extInfo: { url: '' }, // 需要在小程序后台配置客服链接
fail: () => {
// 降级:跳转到客服页面
Taro.navigateTo({ url: '/pages/user/customer-service/index' })
},
})
} else {
Taro.navigateTo({ url: '/pages/user/customer-service/index' })
}
}
if (!product) {