修复订单详情页面包屑

This commit is contained in:
Edward Yang 2022-08-18 20:20:55 +08:00
parent a350b867cd
commit b512f6260d
3 changed files with 49 additions and 13 deletions

View File

@ -82,7 +82,7 @@ function load_settings()
* @param mixed $params * @param mixed $params
* @return string * @return string
*/ */
function admin_route($route, $params = []): string function admin_route($route, array $params = []): string
{ {
$adminName = admin_name(); $adminName = admin_name();
return route("{$adminName}.{$route}", $params); return route("{$adminName}.{$route}", $params);
@ -95,7 +95,7 @@ function admin_route($route, $params = []): string
* @param mixed $params * @param mixed $params
* @return string * @return string
*/ */
function shop_route($route, $params = []): string function shop_route($route, array $params = []): string
{ {
return route('shop.' . $route, $params); return route('shop.' . $route, $params);
} }
@ -107,7 +107,7 @@ function shop_route($route, $params = []): string
* @param mixed $params * @param mixed $params
* @return string * @return string
*/ */
function plugin_route($route, $params = []): string function plugin_route($route, array $params = []): string
{ {
return route('plugin.' . $route, $params); return route('plugin.' . $route, $params);
} }
@ -122,7 +122,7 @@ function plugin_route($route, $params = []): string
*/ */
function type_route($type, $value): string function type_route($type, $value): string
{ {
$types = ['category', 'product', 'brand', 'page', 'static', 'custom']; $types = ['category', 'product', 'brand', 'page', 'order', 'static', 'custom'];
if (empty($type) || empty($value) || !in_array($type, $types)) { if (empty($type) || empty($value) || !in_array($type, $types)) {
return ''; return '';
} }
@ -138,6 +138,8 @@ function type_route($type, $value): string
return shop_route('brands.show', [$value]); return shop_route('brands.show', [$value]);
} elseif ($type == 'page') { } elseif ($type == 'page') {
return shop_route('pages.show', ['page' => $value]); return shop_route('pages.show', ['page' => $value]);
} elseif ($type == 'order') {
return shop_route('account.order.show', ['number' => $value]);
} elseif ($type == 'static') { } elseif ($type == 'static') {
return shop_route($value); return shop_route($value);
} elseif ($type == 'custom') { } elseif ($type == 'custom') {
@ -190,6 +192,7 @@ function type_label($type, $value, array $texts = []): string
* *
* @param $link * @param $link
* @return array * @return array
* @throws Exception
*/ */
function handle_link($link): array function handle_link($link): array
{ {

View File

@ -25,6 +25,7 @@ class Breadcrumb extends Component
* Create a new component instance. * Create a new component instance.
* *
* @return void * @return void
* @throws \Exception
*/ */
public function __construct($type, $value, array $text = []) public function __construct($type, $value, array $text = [])
{ {
@ -37,6 +38,8 @@ class Breadcrumb extends Component
$breadcrumbs = array_merge($breadcrumbs, $this->handleCategoryLinks($value)); $breadcrumbs = array_merge($breadcrumbs, $this->handleCategoryLinks($value));
} elseif ($type == 'product') { } elseif ($type == 'product') {
$breadcrumbs = array_merge($breadcrumbs, $this->handleProductLinks($value)); $breadcrumbs = array_merge($breadcrumbs, $this->handleProductLinks($value));
} elseif ($type == 'order') {
$breadcrumbs = array_merge($breadcrumbs, $this->handleOrderLinks($value));
} elseif (Str::startsWith($value, 'account')) { } elseif (Str::startsWith($value, 'account')) {
$breadcrumbs = array_merge($breadcrumbs, $this->handleAccountLinks($value)); $breadcrumbs = array_merge($breadcrumbs, $this->handleAccountLinks($value));
} else { } else {
@ -62,6 +65,7 @@ class Breadcrumb extends Component
* *
* @param $value * @param $value
* @return array * @return array
* @throws \Exception
*/ */
private function handleCategoryLinks($value): array private function handleCategoryLinks($value): array
{ {
@ -79,6 +83,7 @@ class Breadcrumb extends Component
* *
* @param $value * @param $value
* @return array * @return array
* @throws \Exception
*/ */
private function handleProductLinks($value): array private function handleProductLinks($value): array
{ {
@ -103,11 +108,45 @@ class Breadcrumb extends Component
} }
/**
* 获取订单详情页面包屑
*
* @param $value
* @return array
* @throws \Exception
*/
private function handleOrderLinks($value): array
{
$links = [];
$link = handle_link(['type' => 'static', 'value' => 'account.index']);
$links[] = [
'title' => $link['text'],
'url' => $link['link'],
];
$link = handle_link(['type' => 'static', 'value' => 'account.order.index']);
$links[] = [
'title' => $link['text'],
'url' => $link['link'],
];
$link = handle_link(['type' => 'order', 'value' => $value]);
$links[] = [
'title' => $value,
'url' => $link['link'],
];
return $links;
}
/** /**
* 处理个人中心面包屑 * 处理个人中心面包屑
* *
* @param $value * @param $value
* @return array[] * @return array[]
* @throws \Exception
*/ */
private function handleAccountLinks($value): array private function handleAccountLinks($value): array
{ {
@ -138,6 +177,7 @@ class Breadcrumb extends Component
* @param $value * @param $value
* @param array $text * @param array $text
* @return array * @return array
* @throws \Exception
*/ */
private function handleLinks($type, $value, array $text = []): array private function handleLinks($type, $value, array $text = []): array
{ {

View File

@ -5,14 +5,7 @@
@section('content') @section('content')
<div class="container"> <div class="container">
<x-shop-breadcrumb type="static" value="account.order.index" /> <x-shop-breadcrumb type="order" value="{{ $order->number }}" />
{{-- <nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav> --}}
<div class="row"> <div class="row">
<x-shop-sidebar /> <x-shop-sidebar />