code format

This commit is contained in:
Edward Yang 2022-08-15 12:55:13 +08:00
parent acec51efdd
commit 1b8e643880
4 changed files with 26 additions and 35 deletions

View File

@ -21,8 +21,8 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Beike\Repositories\FooterRepo;
use Beike\Repositories\MenuRepo;
use Beike\Repositories\FooterRepo;
use Illuminate\Support\Facades\View;
use Beike\Repositories\CategoryRepo;
use Beike\Repositories\LanguageRepo;
@ -35,6 +35,9 @@ class ShareViewData
return $next($request);
}
/**
* @throws \Exception
*/
protected function loadShopShareViewData()
{
if (is_admin()) {

View File

@ -181,6 +181,25 @@ function type_label($type, $value, array $texts = []): string
}
/**
* 处理配置链接
*
* @param $link
* @return array
*/
function handle_link($link): array
{
$type = $link['type'] ?? '';
$value = $link['value'] ?? '';
$texts = $link['text'] ?? [];
$link['link'] = type_route($type, $value);
$link['text'] = type_label($type, $value, $texts);
return $link;
}
/**
* 是否访问的后端
* @return bool

View File

@ -31,20 +31,7 @@ class FooterRepo
foreach ($contentLinkKeys as $contentLinkKey) {
$links = $content[$contentLinkKey]['links'];
$links = collect($links)->map(function ($link) {
if ($link['type'] == 'custom') {
$link['link'] = $link['value'];
} elseif ($link['type'] == 'static') {
$link['link'] = shop_route($link['value']);
$link['text'] = trans('shop/' . $link['value']);
} elseif ($link['type'] == 'page') {
$pageId = $link['value'];
$page = Page::query()->find($pageId);
if ($page) {
$link['link'] = type_route('page', $link['value']);
$link['text'] = $page->description->title;
}
}
return $link;
return handle_link($link);
})->toArray();
$footerSetting['content'][$contentLinkKey]['links'] = $links;
}

View File

@ -38,7 +38,7 @@ class MenuRepo
$menus = $MenuSetting['menus'];
foreach ($menus as $index => $menu) {
$menus[$index]['link'] = self::handleLink($menu['link']);
$menus[$index]['link'] = handle_link($menu['link']);
$menus[$index]['name'] = $menu['name'][$locale] ?? '';
$menus[$index]['badge']['name'] = $menu['badge']['name'][$locale] ?? '';
@ -58,7 +58,7 @@ class MenuRepo
} else {
if ($childrenGroup['children']) {
foreach ($childrenGroup['children'] as $children_index => $children) {
$menus[$index]['childrenGroup'][$group_index]['children'][$children_index]['link'] = self::handleLink($children['link']);
$menus[$index]['childrenGroup'][$group_index]['children'][$children_index]['link'] = handle_link($children['link']);
}
}
}
@ -68,22 +68,4 @@ class MenuRepo
return $menus;
}
/**
* 处理链接
*
* @param $link
* @return array
*/
private static function handleLink($link): array
{
$type = $link['type'] ?? '';
$value = $link['value'] ?? '';
$texts = $link['text'] ?? [];
$link['link'] = type_route($type, $value);
$link['text'] = type_label($type, $value, $texts);
return $link;
}
}