From 10a70d5e28964a5de8c001cc4524672074dd3da7 Mon Sep 17 00:00:00 2001 From: pushuo <229102104@qq.com> Date: Fri, 12 Aug 2022 18:32:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=94=B6=E8=97=8F=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Repositories/CustomerRepo.php | 4 +- .../Account/WishlistController.php | 10 +- public/build/beike/admin/js/app.js | 262 ++++++++++-------- public/build/beike/shop/default/js/app.js | 38 ++- resources/beike/admin/js/app.js | 2 +- resources/beike/admin/js/autocomplete.js | 127 +++++++++ resources/beike/admin/js/common.js | 126 +-------- resources/beike/shop/default/js/common.js | 23 ++ themes/default/product.blade.php | 12 +- themes/default/shared/product.blade.php | 5 +- 10 files changed, 337 insertions(+), 272 deletions(-) create mode 100644 resources/beike/admin/js/autocomplete.js diff --git a/beike/Repositories/CustomerRepo.php b/beike/Repositories/CustomerRepo.php index e760baba..c49dadc8 100644 --- a/beike/Repositories/CustomerRepo.php +++ b/beike/Repositories/CustomerRepo.php @@ -139,10 +139,10 @@ class CustomerRepo } if (!$customer->wishlists()->where('product_id', $productId)->first()) { - $customer->wishlists()->save(new CustomerWishlist(['product_id' => $productId])); + $wishlist = $customer->wishlists()->save(new CustomerWishlist(['product_id' => $productId])); } - return $customer; + return $wishlist; } /** diff --git a/beike/Shop/Http/Controllers/Account/WishlistController.php b/beike/Shop/Http/Controllers/Account/WishlistController.php index c0ca4435..c15d411f 100644 --- a/beike/Shop/Http/Controllers/Account/WishlistController.php +++ b/beike/Shop/Http/Controllers/Account/WishlistController.php @@ -31,11 +31,9 @@ class WishlistController extends Controller public function add(Request $request): array { $productId = $request->get('product_id'); - CustomerRepo::addToWishlist(current_customer(), $productId); + $wishlist = CustomerRepo::addToWishlist(current_customer(), $productId); - $wishlists = CustomerRepo::wishlists(current_customer()); - - return json_success('加入收藏成功', $wishlists); + return json_success('加入收藏成功', $wishlist); } public function remove(Request $request): array @@ -43,9 +41,7 @@ class WishlistController extends Controller $id = $request->id; CustomerRepo::removeFromWishlist(current_customer(), $id); - $wishlists = CustomerRepo::wishlists(current_customer()); - - return json_success('移除收藏成功', $wishlists); + return json_success('移除收藏成功'); } } diff --git a/public/build/beike/admin/js/app.js b/public/build/beike/admin/js/app.js index 40e01bd5..ab69c5ed 100644 --- a/public/build/beike/admin/js/app.js +++ b/public/build/beike/admin/js/app.js @@ -2064,13 +2064,15 @@ module.exports = { __webpack_require__.r(__webpack_exports__); /* harmony import */ var _js_http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../js/http */ "./resources/js/http.js"); /* harmony import */ var _common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./common */ "./resources/beike/admin/js/common.js"); +/* harmony import */ var _autocomplete__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./autocomplete */ "./resources/beike/admin/js/autocomplete.js"); +/* harmony import */ var _autocomplete__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_autocomplete__WEBPACK_IMPORTED_MODULE_2__); var _document$querySelect; window.$http = _js_http__WEBPACK_IMPORTED_MODULE_0__["default"]; window.bk = _common__WEBPACK_IMPORTED_MODULE_1__["default"]; -_common__WEBPACK_IMPORTED_MODULE_1__["default"].autocomplete(); + var base = document.querySelector('base').href; var asset = document.querySelector('meta[name="asset"]').content; var editor_language = ((_document$querySelect = document.querySelector('meta[name="editor_language"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.content) || 'zh_cn'; @@ -2164,6 +2166,133 @@ var tinymceInit = function tinymceInit() { /***/ }), +/***/ "./resources/beike/admin/js/autocomplete.js": +/*!**************************************************!*\ + !*** ./resources/beike/admin/js/autocomplete.js ***! + \**************************************************/ +/***/ (() => { + +$(function () { + $.fn.autocomplete = function (option) { + return this.each(function () { + this.timer = null; + this.items = new Array(); + $.extend(this, option); + $(this).attr('autocomplete', 'off'); // Focus + + $(this).on('focus', function () { + this.request(); + }); // Blur + + $(this).on('blur', function () { + setTimeout(function (object) { + object.hide(); + }, 200, this); + }); // Keydown + + $(this).on('keydown', function (event) { + switch (event.keyCode) { + case 27: + // escape + this.hide(); + break; + + default: + this.request(); + break; + } + }); // Click + + this.click = function (event) { + event.preventDefault(); + var value = $(event.target).parent().attr('data-value'); + + if (value && this.items[value]) { + this.select(this.items[value]); + } + }; // Show + + + this.show = function () { + var pos = $(this).position(); + $(this).siblings('ul.dropdown-menu').css({ + top: pos.top + $(this).outerHeight(), + left: pos.left + }); + $(this).siblings('ul.dropdown-menu').show(); + }; // Hide + + + this.hide = function () { + $(this).siblings('ul.dropdown-menu').hide(); + }; // Request + + + this.request = function () { + clearTimeout(this.timer); + this.timer = setTimeout(function (object) { + object.source($(object).val(), $.proxy(object.response, object)); + }, 200, this); + }; // Response + + + this.response = function (json) { + var hasFocus = $(this).is(':focus'); + if (!hasFocus) return; + var html = ''; + + if (json.length) { + for (var i = 0; i < json.length; i++) { + this.items[json[i]['value']] = json[i]; + } + + for (var i = 0; i < json.length; i++) { + if (!json[i]['category']) { + html += '
  • ' + json[i]['label'] + '
  • '; + } + } // Get all the ones with a categories + + + var category = new Array(); + + for (var i = 0; i < json.length; i++) { + if (json[i]['category']) { + if (!category[json[i]['category']]) { + category[json[i]['category']] = new Array(); + category[json[i]['category']]['name'] = json[i]['category']; + category[json[i]['category']]['item'] = new Array(); + } + + category[json[i]['category']]['item'].push(json[i]); + } + } + + for (var i in category) { + html += ''; + + for (j = 0; j < category[i]['item'].length; j++) { + html += '
  •    ' + category[i]['item'][j]['label'] + '
  • '; + } + } + } + + if (html) { + this.show(); + } else { + this.hide(); + } + + $(this).siblings('ul.dropdown-menu').html(html); + }; + + $(this).after(''); + $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); + }); + }; +}); + +/***/ }), + /***/ "./resources/beike/admin/js/common.js": /*!********************************************!*\ !*** ./resources/beike/admin/js/common.js ***! @@ -2211,124 +2340,7 @@ __webpack_require__.r(__webpack_exports__); }, delay); }; }, - autocomplete: function autocomplete() { - $.fn.autocomplete = function (option) { - return this.each(function () { - this.timer = null; - this.items = new Array(); - $.extend(this, option); - $(this).attr('autocomplete', 'off'); // Focus - - $(this).on('focus', function () { - this.request(); - }); // Blur - - $(this).on('blur', function () { - setTimeout(function (object) { - object.hide(); - }, 200, this); - }); // Keydown - - $(this).on('keydown', function (event) { - switch (event.keyCode) { - case 27: - // escape - this.hide(); - break; - - default: - this.request(); - break; - } - }); // Click - - this.click = function (event) { - event.preventDefault(); - var value = $(event.target).parent().attr('data-value'); - - if (value && this.items[value]) { - this.select(this.items[value]); - } - }; // Show - - - this.show = function () { - var pos = $(this).position(); - $(this).siblings('ul.dropdown-menu').css({ - top: pos.top + $(this).outerHeight(), - left: pos.left - }); - $(this).siblings('ul.dropdown-menu').show(); - }; // Hide - - - this.hide = function () { - $(this).siblings('ul.dropdown-menu').hide(); - }; // Request - - - this.request = function () { - clearTimeout(this.timer); - this.timer = setTimeout(function (object) { - object.source($(object).val(), $.proxy(object.response, object)); - }, 200, this); - }; // Response - - - this.response = function (json) { - var hasFocus = $(this).is(':focus'); - if (!hasFocus) return; - var html = ''; - - if (json.length) { - for (var i = 0; i < json.length; i++) { - this.items[json[i]['value']] = json[i]; - } - - for (var i = 0; i < json.length; i++) { - if (!json[i]['category']) { - html += '
  • ' + json[i]['label'] + '
  • '; - } - } // Get all the ones with a categories - - - var category = new Array(); - - for (var i = 0; i < json.length; i++) { - if (json[i]['category']) { - if (!category[json[i]['category']]) { - category[json[i]['category']] = new Array(); - category[json[i]['category']]['name'] = json[i]['category']; - category[json[i]['category']]['item'] = new Array(); - } - - category[json[i]['category']]['item'].push(json[i]); - } - } - - for (var i in category) { - html += ''; - - for (j = 0; j < category[i]['item'].length; j++) { - html += '
  •    ' + category[i]['item'][j]['label'] + '
  • '; - } - } - } - - if (html) { - this.show(); - } else { - this.hide(); - } - - $(this).siblings('ul.dropdown-menu').html(html); - }; - - $(this).after(''); - $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); - }); - }; - } + listDelete: function listDelete() {} }); /***/ }), @@ -2822,6 +2834,18 @@ module.exports = JSON.parse('{"name":"axios","version":"0.21.4","description":"P /******/ }; /******/ })(); /******/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports diff --git a/public/build/beike/shop/default/js/app.js b/public/build/beike/shop/default/js/app.js index 1468669a..a65dc9c6 100644 --- a/public/build/beike/shop/default/js/app.js +++ b/public/build/beike/shop/default/js/app.js @@ -2129,13 +2129,37 @@ __webpack_require__.r(__webpack_exports__); } }); }, - addWishlist: function addWishlist(id) { - var isWishlist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - $http.post('account/wishlist', { - product_id: id - }).then(function (res) { - layer.msg(res.message); - }); + addWishlist: function addWishlist(id, e) { + var $btn = $(e); + var isWishlist = $btn.attr('data-in-wishlist') * 1; + var btnHtml = $btn.html(); + var loadHtml = ''; + + if (isWishlist) { + $btn.html(loadHtml).prop('disabled', true); + $http["delete"]("account/wishlist/".concat(isWishlist), null, { + hload: true + }).then(function (res) { + layer.msg(res.message); + $btn.attr('data-in-wishlist', '0'); + $btn.find('i.bi').prop('class', 'bi bi-heart me-1'); + })["finally"](function () { + $btn.html(btnHtml).prop('disabled', false); + }); + } else { + $btn.html(loadHtml).prop('disabled', true); + $http.post('account/wishlist', { + product_id: id + }, { + hload: true + }).then(function (res) { + layer.msg(res.message); + $btn.attr('data-in-wishlist', res.data.id); + $btn.find('i.bi').prop('class', 'bi bi-heart-fill me-1'); + })["finally"](function () { + $btn.html(btnHtml).prop('disabled', false); + }); + } }, /** diff --git a/resources/beike/admin/js/app.js b/resources/beike/admin/js/app.js index 6a520789..a010d513 100644 --- a/resources/beike/admin/js/app.js +++ b/resources/beike/admin/js/app.js @@ -2,7 +2,7 @@ import http from "../../../js/http"; window.$http = http; import common from "./common"; window.bk = common; -common.autocomplete(); +import "./autocomplete"; const base = document.querySelector('base').href; const asset = document.querySelector('meta[name="asset"]').content; diff --git a/resources/beike/admin/js/autocomplete.js b/resources/beike/admin/js/autocomplete.js new file mode 100644 index 00000000..8e652de0 --- /dev/null +++ b/resources/beike/admin/js/autocomplete.js @@ -0,0 +1,127 @@ +$(function() { + $.fn.autocomplete = function(option) { + return this.each(function() { + this.timer = null; + this.items = new Array(); + + $.extend(this, option); + + $(this).attr('autocomplete', 'off'); + + // Focus + $(this).on('focus', function() { + this.request(); + }); + + // Blur + $(this).on('blur', function() { + setTimeout(function(object) { + object.hide(); + }, 200, this); + }); + + // Keydown + $(this).on('keydown', function(event) { + switch(event.keyCode) { + case 27: // escape + this.hide(); + break; + default: + this.request(); + break; + } + }); + + // Click + this.click = function(event) { + event.preventDefault(); + + let value = $(event.target).parent().attr('data-value'); + + if (value && this.items[value]) { + this.select(this.items[value]); + } + } + + // Show + this.show = function() { + var pos = $(this).position(); + + $(this).siblings('ul.dropdown-menu').css({ + top: pos.top + $(this).outerHeight(), + left: pos.left + }); + + $(this).siblings('ul.dropdown-menu').show(); + } + + // Hide + this.hide = function() { + $(this).siblings('ul.dropdown-menu').hide(); + } + + // Request + this.request = function() { + clearTimeout(this.timer); + + this.timer = setTimeout(function(object) { + object.source($(object).val(), $.proxy(object.response, object)); + }, 200, this); + } + + // Response + this.response = function(json) { + let hasFocus = $(this).is(':focus'); + if (!hasFocus) return; + + var html = ''; + + if (json.length) { + for (var i = 0; i < json.length; i++) { + this.items[json[i]['value']] = json[i]; + } + + for (var i = 0; i < json.length; i++) { + if (!json[i]['category']) { + html += '
  • ' + json[i]['label'] + '
  • '; + } + } + + // Get all the ones with a categories + var category = new Array(); + + for (var i = 0; i < json.length; i++) { + if (json[i]['category']) { + if (!category[json[i]['category']]) { + category[json[i]['category']] = new Array(); + category[json[i]['category']]['name'] = json[i]['category']; + category[json[i]['category']]['item'] = new Array(); + } + + category[json[i]['category']]['item'].push(json[i]); + } + } + + for (var i in category) { + html += ''; + + for (j = 0; j < category[i]['item'].length; j++) { + html += '
  •    ' + category[i]['item'][j]['label'] + '
  • '; + } + } + } + + if (html) { + this.show(); + } else { + this.hide(); + } + + $(this).siblings('ul.dropdown-menu').html(html); + } + + $(this).after(''); + $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); + }); + } +}); \ No newline at end of file diff --git a/resources/beike/admin/js/common.js b/resources/beike/admin/js/common.js index de11e6f0..f2d86804 100644 --- a/resources/beike/admin/js/common.js +++ b/resources/beike/admin/js/common.js @@ -33,131 +33,7 @@ export default { } }, - autocomplete() { - $.fn.autocomplete = function(option) { - return this.each(function() { - this.timer = null; - this.items = new Array(); + listDelete() { - $.extend(this, option); - - $(this).attr('autocomplete', 'off'); - - // Focus - $(this).on('focus', function() { - this.request(); - }); - - // Blur - $(this).on('blur', function() { - setTimeout(function(object) { - object.hide(); - }, 200, this); - }); - - // Keydown - $(this).on('keydown', function(event) { - switch(event.keyCode) { - case 27: // escape - this.hide(); - break; - default: - this.request(); - break; - } - }); - - // Click - this.click = function(event) { - event.preventDefault(); - - let value = $(event.target).parent().attr('data-value'); - - if (value && this.items[value]) { - this.select(this.items[value]); - } - } - - // Show - this.show = function() { - var pos = $(this).position(); - - $(this).siblings('ul.dropdown-menu').css({ - top: pos.top + $(this).outerHeight(), - left: pos.left - }); - - $(this).siblings('ul.dropdown-menu').show(); - } - - // Hide - this.hide = function() { - $(this).siblings('ul.dropdown-menu').hide(); - } - - // Request - this.request = function() { - clearTimeout(this.timer); - - this.timer = setTimeout(function(object) { - object.source($(object).val(), $.proxy(object.response, object)); - }, 200, this); - } - - // Response - this.response = function(json) { - let hasFocus = $(this).is(':focus'); - if (!hasFocus) return; - - var html = ''; - - if (json.length) { - for (var i = 0; i < json.length; i++) { - this.items[json[i]['value']] = json[i]; - } - - for (var i = 0; i < json.length; i++) { - if (!json[i]['category']) { - html += '
  • ' + json[i]['label'] + '
  • '; - } - } - - // Get all the ones with a categories - var category = new Array(); - - for (var i = 0; i < json.length; i++) { - if (json[i]['category']) { - if (!category[json[i]['category']]) { - category[json[i]['category']] = new Array(); - category[json[i]['category']]['name'] = json[i]['category']; - category[json[i]['category']]['item'] = new Array(); - } - - category[json[i]['category']]['item'].push(json[i]); - } - } - - for (var i in category) { - html += ''; - - for (j = 0; j < category[i]['item'].length; j++) { - html += '
  •    ' + category[i]['item'][j]['label'] + '
  • '; - } - } - } - - if (html) { - this.show(); - } else { - this.hide(); - } - - $(this).siblings('ul.dropdown-menu').html(html); - } - - $(this).after(''); - $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); - }); - } }, } \ No newline at end of file diff --git a/resources/beike/shop/default/js/common.js b/resources/beike/shop/default/js/common.js index 9e16cc0d..54d270c3 100644 --- a/resources/beike/shop/default/js/common.js +++ b/resources/beike/shop/default/js/common.js @@ -54,6 +54,29 @@ export default { }) }, + addWishlist(id, e) { + const $btn = $(e); + let isWishlist = $btn.attr('data-in-wishlist') * 1; + const btnHtml = $btn.html(); + const loadHtml = ''; + + if (isWishlist) { + $btn.html(loadHtml).prop('disabled', true); + $http.delete(`account/wishlist/${isWishlist}`, null, {hload: true}).then((res) => { + layer.msg(res.message) + $btn.attr('data-in-wishlist', '0'); + $btn.find('i.bi').prop('class', 'bi bi-heart me-1') + }).finally(() => {$btn.html(btnHtml).prop('disabled', false)}) + } else { + $btn.html(loadHtml).prop('disabled', true); + $http.post('account/wishlist', {product_id: id}, {hload: true}).then((res) => { + layer.msg(res.message) + $btn.attr('data-in-wishlist', res.data.id); + $btn.find('i.bi').prop('class', 'bi bi-heart-fill me-1') + }).finally(() => {$btn.html(btnHtml).prop('disabled', false)}) + } + }, + /** * @description: 滑动固定顶部 * @return {*} diff --git a/themes/default/product.blade.php b/themes/default/product.blade.php index 50213f54..e8387688 100644 --- a/themes/default/product.blade.php +++ b/themes/default/product.blade.php @@ -12,7 +12,6 @@ @endpush @section('content') -
    {{ Diglactic\Breadcrumbs\Breadcrumbs::render('product', $product) }} @@ -40,7 +39,6 @@
    -
    @@ -104,7 +102,9 @@
    - +
    @@ -241,12 +241,6 @@ }) }); }, - - addWishlist() { - $http.post('account/wishlist', {product_id: '{{ $product['id'] }}'}).then((res) => { - layer.msg(res.message) - }) - }, } }); diff --git a/themes/default/shared/product.blade.php b/themes/default/shared/product.blade.php index 3c377fda..92ab991b 100644 --- a/themes/default/shared/product.blade.php +++ b/themes/default/shared/product.blade.php @@ -9,8 +9,9 @@
    -