From a6a0b4cfbc6fe70f6c51c3ea6e05403ae7f4ecaa Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 17 Aug 2022 23:58:03 +0800 Subject: [PATCH] fixed account breadcrumb --- beike/Shop/View/Components/Breadcrumb.php | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/beike/Shop/View/Components/Breadcrumb.php b/beike/Shop/View/Components/Breadcrumb.php index 8b869888..7b9f05a3 100644 --- a/beike/Shop/View/Components/Breadcrumb.php +++ b/beike/Shop/View/Components/Breadcrumb.php @@ -14,6 +14,7 @@ namespace Beike\Shop\View\Components; use Beike\Models\Product; use Illuminate\Contracts\View\View; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Illuminate\View\Component; class Breadcrumb extends Component @@ -36,6 +37,8 @@ class Breadcrumb extends Component $breadcrumbs = array_merge($breadcrumbs, $this->handleCategoryLinks($value)); } elseif ($type == 'product') { $breadcrumbs = array_merge($breadcrumbs, $this->handleProductLinks($value)); + } elseif (Str::startsWith($value, 'account')) { + $breadcrumbs = array_merge($breadcrumbs, $this->handleAccountLinks($value)); } else { $breadcrumbs = array_merge($breadcrumbs, $this->handleLinks($type, $value, $text)); } @@ -99,6 +102,35 @@ class Breadcrumb extends Component return $links; } + + /** + * 处理个人中心面包屑 + * + * @param $value + * @return array[] + */ + private function handleAccountLinks($value): array + { + $links = []; + $values = explode('.', $value); + + if (count($values) == 3) { + $link = handle_link(['type' => 'static', 'value' => 'account.index']); + $links[] = [ + 'title' => $link['text'], + 'url' => $link['link'], + ]; + } + + $link = handle_link(['type' => 'static', 'value' => $value]); + $links[] = [ + 'title' => $link['text'], + 'url' => $link['link'], + ]; + + return $links; + } + /** * 获取普通链接 *