From 5c84e7e390c69f817c6f185cfb9a2a35b6cc88db Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Tue, 10 Jun 2025 14:46:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=B3=BB=E7=BB=9F=E5=85=B6?= =?UTF-8?q?=E4=BB=96urls=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/System.php | 262 ++++++++++++++++------------- 1 file changed, 147 insertions(+), 115 deletions(-) diff --git a/app/admin/controller/v1/System.php b/app/admin/controller/v1/System.php index 85e461ec..69c0e4ad 100644 --- a/app/admin/controller/v1/System.php +++ b/app/admin/controller/v1/System.php @@ -158,119 +158,7 @@ class System [ 'name' => '其他内页', 'link_to' => 'system_page', - 'data' => [ - [ - 'id' => 1, - 'name' => '首页', - 'url' => (string)url('/index/index/index') - ], - [ - 'id' => 2, - 'name' => '新品上市', - 'url' => (string)url('/index/product/newpro') - ], - [ - 'id' => 3, - 'name' => '附件下载', - 'url' => (string)url('/index/attachment/index') - ], - [ - 'id' => 4, - 'name' => '问答中心', - 'url' => (string)url('/index/faq/index') - ], - [ - 'id' => 5, - 'name' => '关于我们', - 'url' => '', - 'children' => [ - [ - 'id' => 51, - 'name' => '品牌介绍', - 'url' => (string)url('/index/aboutus/introduction') - ], - [ - 'id' => 52, - 'name' => '品牌故事', - 'url' => (string)url('/index/aboutus/story') - ], - [ - 'id' => 53, - 'name' => '品牌历程', - 'url' => (string)url('/index/aboutus/mileage') - ], - [ - 'id' => 54, - 'name' => '文化介绍', - 'url' => (string)url('/index/aboutus/culture') - ], - [ - 'id' => 55, - 'name' => '售后政策', - 'url' => (string)url('/index/aboutus/policy') - ] - ] - ], - [ - 'id' => 6, - 'name' => '联系我们', - 'url' => '', - 'children' => [ - [ - 'id' => 61, - 'name' => '联系我们', - 'url' => (string)url('/index/contactus/index') - ], - [ - 'id' => 62, - 'name' => '留言联系我们', - 'url' => (string)url('/index/contactus/message') - ], - [ - 'id' => 63, - 'name' => '留言成为分销商', - 'url' => (string)url('/index/contactus/distributor') - ], - [ - 'id' => 64, - 'name' => '留言批量购买', - 'url' => (string)url('/index/contactus/bulkbuy') - ] - ] - ], - [ - 'id' => 7, - 'name' => 'NAS专题', - 'url' => '', - 'children' => [ - [ - 'id' => 71, - 'name' => '首页', - 'url' => (string)url('/index/topic/nas/index') - ], - [ - 'id' => 72, - 'name' => '产品体验', - 'url' => (string)url('/index/topic/nas/product') - ], - [ - 'id' => 73, - 'name' => '客户合作', - 'url' => (string)url('/index/topic/nas/cooperation') - ], - [ - 'id' => 74, - 'name' => '帮助中心', - 'url' => (string)url('/index/topic/nas/help') - ], - [ - 'id' => 75, - 'name' => '软件下载', - 'url' => (string)url('/index/topic/nas/download') - ] - ] - ] - ], + 'data' => self::getSystemOtherPages() ] ]; @@ -336,6 +224,124 @@ class System return $data->toArray(); } + // 获取系统其他内页 + static private function getSystemOtherPages() + { + return [ + [ + 'id' => 1, + 'name' => '首页', + 'url' => (string)url('/index/index/index') + ], + [ + 'id' => 2, + 'name' => '新品上市', + 'url' => (string)url('/index/product/newpro') + ], + [ + 'id' => 3, + 'name' => '附件下载', + 'url' => (string)url('/index/attachment/index') + ], + [ + 'id' => 4, + 'name' => '问答中心', + 'url' => (string)url('/index/faq/index') + ], + [ + 'id' => 5, + 'name' => '关于我们', + 'url' => '', + 'children' => [ + [ + 'id' => 51, + 'name' => '品牌介绍', + 'url' => (string)url('/index/aboutus/introduction') + ], + [ + 'id' => 52, + 'name' => '品牌故事', + 'url' => (string)url('/index/aboutus/story') + ], + [ + 'id' => 53, + 'name' => '品牌历程', + 'url' => (string)url('/index/aboutus/mileage') + ], + [ + 'id' => 54, + 'name' => '文化介绍', + 'url' => (string)url('/index/aboutus/culture') + ], + [ + 'id' => 55, + 'name' => '售后政策', + 'url' => (string)url('/index/aboutus/policy') + ] + ] + ], + [ + 'id' => 6, + 'name' => '联系我们', + 'url' => '', + 'children' => [ + [ + 'id' => 61, + 'name' => '联系我们', + 'url' => (string)url('/index/contactus/index') + ], + [ + 'id' => 62, + 'name' => '留言联系我们', + 'url' => (string)url('/index/contactus/message') + ], + [ + 'id' => 63, + 'name' => '留言成为分销商', + 'url' => (string)url('/index/contactus/distributor') + ], + [ + 'id' => 64, + 'name' => '留言批量购买', + 'url' => (string)url('/index/contactus/bulkbuy') + ] + ] + ], + [ + 'id' => 7, + 'name' => 'NAS专题', + 'url' => '', + 'children' => [ + [ + 'id' => 71, + 'name' => '首页', + 'url' => (string)url('/index/topic/nas/index') + ], + [ + 'id' => 72, + 'name' => '产品体验', + 'url' => (string)url('/index/topic/nas/product') + ], + [ + 'id' => 73, + 'name' => '客户合作', + 'url' => (string)url('/index/topic/nas/cooperation') + ], + [ + 'id' => 74, + 'name' => '帮助中心', + 'url' => (string)url('/index/topic/nas/help') + ], + [ + 'id' => 75, + 'name' => '软件下载', + 'url' => (string)url('/index/topic/nas/download') + ] + ] + ] + ]; + } + // 根据系统页面url获取回显数据项 static public function getEchoDataBySystemPageUrl($link_to, $link) { @@ -351,21 +357,29 @@ class System parse_str($url, $params); } - if (empty($params['id'])) return []; - switch ($link_to) { case 'article_category': + if (empty($params['id'])) return []; $data = ArticleCategoryModel::field(['id', 'name'])->bypk($params['id'])->find(); break; case 'article': + if (empty($params['id'])) return []; $data = ArticleModel::field(['id', 'title' => 'name'])->bypk($params['id'])->find(); break; case 'product_category': + if (empty($params['id'])) return []; $data = ProductCategoryModel::field(['id', 'name'])->bypk($params['id'])->find(); break; case 'product': + if (empty($params['id'])) return []; $data = ProductModel::field(['id', 'name'])->bypk($params['id'])->find(); break; + case 'system_page': + $data = self::filterSystemOtherPage(self::getSystemOtherPages(), function($item) use ($params, $link) { + if (empty($params['id'])) return $item['url'] == $link; + return $item['id'] == $params['id']; + }); + break; default: return []; break; @@ -378,4 +392,22 @@ class System 'link' => $link ]; } + + // 根据条件过滤结果 + static private function filterSystemOtherPage(array $data, callable $callback): array + { + foreach ($data as $it) { + if ($callback($it)) { + return $it; + } + if (isset($it['children'])) { + $child = self::filterSystemOtherPage($it['children'], $callback); + if (!empty($child)) { + return $child; + } + } + } + + return []; + } } \ No newline at end of file