diff --git a/public/build/beike/shop/default/js/app.js b/public/build/beike/shop/default/js/app.js index 4d33a1c2..002c655d 100644 --- a/public/build/beike/shop/default/js/app.js +++ b/public/build/beike/shop/default/js/app.js @@ -2469,7 +2469,9 @@ var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _js_http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../js/http */ "./resources/js/http.js"); -window.$http = _js_http__WEBPACK_IMPORTED_MODULE_0__["default"]; +window.$http = _js_http__WEBPACK_IMPORTED_MODULE_0__["default"]; // 基于 window 顶层 创建 bk 对象,先判断是否存在,如果存在,就不创建 + +window.bk = window.bk || {}; $(document).ready(function ($) { $.ajaxSetup({ headers: { @@ -2484,30 +2486,7 @@ $(document).ready(function ($) { layer.closeAll('loading'); } }); - $http.get('carts/mini', null, { - hload: true - }).then(function (res) { - $('.offcanvas-right-cart-amount').html(res.data.amount_format); - - if (res.data.carts.length) { - $('.navbar-icon-link-badge').html(res.data.carts.length > 99 ? '99+' : res.data.carts.length).show(); - $('.offcanvas-right-cart-count').html(res.data.carts.length); - var html = ''; - res.data.carts.forEach(function (e) { - html += '
'; - html += "
"); - html += '
'; - html += "
".concat(e.name, "
"); - html += '
'; - html += "
".concat(e.price_format, "
"); - html += " \u5220\u9664"); - html += '
'; - html += '
'; - html += '
'; - }); - $('.offcanvas-right-products').html(html); - } - }); + bk.getCarts(); $(document).on('click', '.offcanvas-products-delete', function (event) { var $this = $(this); var cartId = $(this).data('id'); @@ -2577,7 +2556,35 @@ $(document).ready(function ($) { }); })(window.jQuery); -}); +}); // 封装一个方法, 把上面这个 http.get('carts/mini', null, {hload: true}).then((res) => { 放里面 +// 把封装的方法放在 bk 对象里面 + +bk.getCarts = function () { + $http.get('carts/mini', null, { + hload: true + }).then(function (res) { + $('.offcanvas-right-cart-amount').html(res.data.amount_format); + + if (res.data.carts.length) { + $('.navbar-icon-link-badge').html(res.data.carts.length > 99 ? '99+' : res.data.carts.length).show(); + $('.offcanvas-right-cart-count').html(res.data.carts.length); + var html = ''; + res.data.carts.forEach(function (e) { + html += '
'; + html += "
"); + html += '
'; + html += "
".concat(e.name, "
"); + html += '
'; + html += "
".concat(e.price_format, "
"); + html += " \u5220\u9664"); + html += '
'; + html += '
'; + html += '
'; + }); + $('.offcanvas-right-products').html(html); + } + }); +}; })(); /******/ })() diff --git a/resources/beike/shop/default/js/app.js b/resources/beike/shop/default/js/app.js index 6b6f1ca5..3fe46fc3 100644 --- a/resources/beike/shop/default/js/app.js +++ b/resources/beike/shop/default/js/app.js @@ -1,6 +1,9 @@ import http from "../../../../js/http"; window.$http = http; +// 基于 window 顶层 创建 bk 对象,先判断是否存在,如果存在,就不创建 +window.bk = window.bk || {}; + $(document).ready(function ($) { $.ajaxSetup({ headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, @@ -8,30 +11,7 @@ $(document).ready(function ($) { complete: function() { layer.closeAll('loading'); }, }); - $http.get('carts/mini', null, {hload: true}).then((res) => { - $('.offcanvas-right-cart-amount').html(res.data.amount_format); - - if (res.data.carts.length) { - $('.navbar-icon-link-badge').html(res.data.carts.length > 99 ? '99+' : res.data.carts.length).show(); - $('.offcanvas-right-cart-count').html(res.data.carts.length); - - let html = ''; - res.data.carts.forEach(e => { - html += '
'; - html += `
`; - html += '
'; - html += `
${e.name}
`; - html += '
'; - html += `
${e.price_format}
`; - html += ` 删除`; - html += '
'; - html += '
'; - html += '
'; - }) - - $('.offcanvas-right-products').html(html) - } - }) + bk.getCarts(); $(document).on('click', '.offcanvas-products-delete', function(event) { const $this = $(this) @@ -98,3 +78,32 @@ $(document).ready(function ($) { }) })(window.jQuery); }); + +// 封装一个方法, 把上面这个 http.get('carts/mini', null, {hload: true}).then((res) => { 放里面 +// 把封装的方法放在 bk 对象里面 +bk.getCarts = function () { + $http.get('carts/mini', null, {hload: true}).then((res) => { + $('.offcanvas-right-cart-amount').html(res.data.amount_format); + + if (res.data.carts.length) { + $('.navbar-icon-link-badge').html(res.data.carts.length > 99 ? '99+' : res.data.carts.length).show(); + $('.offcanvas-right-cart-count').html(res.data.carts.length); + + let html = ''; + res.data.carts.forEach(e => { + html += '
'; + html += `
`; + html += '
'; + html += `
${e.name}
`; + html += '
'; + html += `
${e.price_format}
`; + html += ` 删除`; + html += '
'; + html += '
'; + html += '
'; + }) + + $('.offcanvas-right-products').html(html) + } + }) +} \ No newline at end of file diff --git a/themes/default/account/account.blade.php b/themes/default/account/account.blade.php index 1fede392..77e9ac77 100644 --- a/themes/default/account/account.blade.php +++ b/themes/default/account/account.blade.php @@ -24,7 +24,7 @@
个人中心
- 修改休息 + 修改信息
diff --git a/themes/default/product.blade.php b/themes/default/product.blade.php index ad5ce288..f8c7774e 100644 --- a/themes/default/product.blade.php +++ b/themes/default/product.blade.php @@ -203,6 +203,7 @@ addCart(isBuyNow = false) { $http.post('/carts', {sku_id: this.product.id, quantity: this.quantity}).then((res) => { + bk.getCarts(); layer.msg(res.message) if (isBuyNow) { location.href = '{{ shop_route("checkout.index") }}'