From 4643926768c7dc61a0d9afeb8e18bce0fc5f4da9 Mon Sep 17 00:00:00 2001 From: pushuo <229102104@qq.com> Date: Mon, 29 Aug 2022 17:33:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Shop/Http/Controllers/CartController.php | 8 ++++++-- public/build/beike/shop/default/css/app.css | 14 ++++++++++++++ public/build/beike/shop/default/js/app.js | 16 +++++++++++++++- resources/beike/shop/default/css/header.scss | 15 +++++++++++++++ resources/beike/shop/default/js/app.js | 7 +++++++ resources/beike/shop/default/js/common.js | 7 ++++++- themes/default/layout/header.blade.php | 5 +++-- 7 files changed, 66 insertions(+), 6 deletions(-) diff --git a/beike/Shop/Http/Controllers/CartController.php b/beike/Shop/Http/Controllers/CartController.php index 88fb525c..438e2b57 100644 --- a/beike/Shop/Http/Controllers/CartController.php +++ b/beike/Shop/Http/Controllers/CartController.php @@ -105,7 +105,11 @@ class CartController extends Controller */ public function miniCart() { - $data = CartService::reloadData(); - return view('cart/mini', $data); + $reloadData = CartService::reloadData(); + + $data['html'] = view('cart/mini', $reloadData)->render(); + $data['quantity'] = $reloadData['quantity']; + + return json_success(trans('common.success'), $data); } } diff --git a/public/build/beike/shop/default/css/app.css b/public/build/beike/shop/default/css/app.css index 54d3b7cb..efad016d 100644 --- a/public/build/beike/shop/default/css/app.css +++ b/public/build/beike/shop/default/css/app.css @@ -600,6 +600,20 @@ header .header-content .right-btn .nav-link { header .header-content .right-btn .nav-link i { font-size: 1.1rem; } +header .header-content .right-btn .cart-badge-quantity { + position: absolute; + left: 21px; + top: -3px; + text-align: center; + font-size: 12px; + width: 23px; + zoom: 0.9; + height: 23px; + line-height: 24px; + background-color: #fd560f; + color: #fff; + border-radius: 50%; +} header .header-mobile .mobile-content { padding: 10px 15px; display: flex; diff --git a/public/build/beike/shop/default/js/app.js b/public/build/beike/shop/default/js/app.js index 47f0553c..37e3f173 100644 --- a/public/build/beike/shop/default/js/app.js +++ b/public/build/beike/shop/default/js/app.js @@ -2105,7 +2105,13 @@ __webpack_require__.r(__webpack_exports__); $http.get('carts/mini', null, { hload: true }).then(function (res) { - $('#offcanvas-right-cart').html(res); + $('#offcanvas-right-cart').html(res.data.html); + + if (!res.data.quantity) { + $('.cart-badge-quantity').hide(); + } else { + $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); + } }); }, @@ -2742,6 +2748,14 @@ $(document).ready(function ($) { var id = $(this).data('id'); $http["delete"]("carts/".concat(id)).then(function (res) { $(_this).parents('.product-list').remove(); + console.log(res.data.quantity); + + if (!res.data.quantity) { + $('.cart-badge-quantity').hide(); + } else { + $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); + } + $('.offcanvas-right-cart-count').text(res.data.quantity); $('.offcanvas-right-cart-amount').text(res.data.amount_format); }); diff --git a/resources/beike/shop/default/css/header.scss b/resources/beike/shop/default/css/header.scss index dd5e3f42..a6d99179 100644 --- a/resources/beike/shop/default/css/header.scss +++ b/resources/beike/shop/default/css/header.scss @@ -152,6 +152,21 @@ header { font-size: 1.1rem; } } + + .cart-badge-quantity { + position: absolute; + left: 21px; + top: -3px; + text-align: center; + font-size: 12px; + width: 23px; + zoom: 0.9; + height: 23px; + line-height: 24px; + background-color: #fd560f; + color: #fff; + border-radius: 50%; + } } } diff --git a/resources/beike/shop/default/js/app.js b/resources/beike/shop/default/js/app.js index ef280345..01e3cc14 100644 --- a/resources/beike/shop/default/js/app.js +++ b/resources/beike/shop/default/js/app.js @@ -16,6 +16,13 @@ $(document).ready(function ($) { $http.delete(`carts/${id}`).then((res) => { $(this).parents('.product-list').remove(); + console.log(res.data.quantity); + if (!res.data.quantity) { + $('.cart-badge-quantity').hide(); + } else { + $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); + } + $('.offcanvas-right-cart-count').text(res.data.quantity); $('.offcanvas-right-cart-amount').text(res.data.amount_format); }) diff --git a/resources/beike/shop/default/js/common.js b/resources/beike/shop/default/js/common.js index 50217974..8e659d35 100644 --- a/resources/beike/shop/default/js/common.js +++ b/resources/beike/shop/default/js/common.js @@ -12,7 +12,12 @@ export default { */ getCarts() { $http.get('carts/mini', null, {hload: true}).then((res) => { - $('#offcanvas-right-cart').html(res); + $('#offcanvas-right-cart').html(res.data.html); + if (!res.data.quantity) { + $('.cart-badge-quantity').hide(); + } else { + $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); + } }) }, diff --git a/themes/default/layout/header.blade.php b/themes/default/layout/header.blade.php index 7920db5d..69a5869a 100644 --- a/themes/default/layout/header.blade.php +++ b/themes/default/layout/header.blade.php @@ -154,10 +154,11 @@