Browse Source

feat:header an footer

igb 4 months ago
parent
commit
0e72207ce2

+ 3 - 3
app/Helpers/SiteCache.php

@@ -165,15 +165,15 @@ class SiteCache
      * @param int $seconds 缓存时间(秒)
      * @return array
      */
-    public static function getMenu(string $domain, int $dist_id=0,int $seconds = 300): array
+    public static function getMenu(string $domain,int $menu_location=0, int $dist_id=0,int $seconds = 300): array
     {
         // 检查 URL 是否需要清除菜单缓存
         self::checkAndClearCache($domain, 'menu'); // 检查是否需要清缓存
 
         // 使用缓存存储和获取多级菜单
-        return  Cache::tags([$domain, 'menu'])->remember('menu', $seconds, function () use ($dist_id) {
+        return  Cache::tags([$domain, "menu_{$menu_location}"])->remember('menu', $seconds, function () use ($menu_location,$dist_id) {
             $menuService = new MenuService();
-            return $menuService->getMultiLevelMenu($dist_id);
+            return $menuService->getMultiLevelMenu($menu_location,$dist_id);
         });
     }
 

+ 4 - 2
app/Http/Middleware/LoadDistData.php

@@ -58,9 +58,11 @@ class LoadDistData
         // 将找到的 dist 数据添加到请求中,方便后续使用
         //$request->attributes->set('dist', $dist);
 
-        $menus=SiteCache::getMenu($domain,$dist->id);
-        app()->instance('menus', $menus);
+        $menus_header=SiteCache::getMenu($domain,0,$dist->id);
+        $menus_footer=SiteCache::getMenu($domain,1,$dist->id);
 
+        app()->instance('menus_header', $menus_header);// 头部菜单
+        app()->instance('menus_footer', $menus_footer);// 底部菜单
 
         return $next($request);
     }

+ 2 - 1
app/Services/LiquidRenderer.php

@@ -107,7 +107,8 @@ class LiquidRenderer
             'asset_base_url' =>config('liquid.asset_base_url'),
             'font_base_url' => config('liquid.font_base_url'),
             'dist' => app('dist'),
-            'menus'=>app('menus'),
+            'menus_header'=>app('menus_header'),
+            'menus_footer'=>app('menus_footer'),
         ];
     }
 }

+ 2 - 1
app/Services/MenuService.php

@@ -11,11 +11,12 @@ class MenuService
      *
      * @return array
      */
-    public function getMultiLevelMenu(int $dist_id = 0): array
+    public function getMultiLevelMenu(int $menu_location=0,int $dist_id = 0): array
     {
         // 一次性加载所有菜单项
         $menus = SiteMenu::where('show', 1) // 只显示状态为 1 的菜单
             ->where('dist_id', $dist_id)
+            ->where('menu_location', $menu_location)
         ->orderBy('order', 'asc')
             ->get();
 

+ 22 - 48
resources/views/liquid/1/TechVista/_footer.liquid

@@ -19,55 +19,29 @@
                         </div>
                     </div>
                 </div>
+                {% for menu in site.menus_footer %}
+                    {% if menu.show %}
+                        <div class="col-lg-2">
+                            <div class="col">
+                                <h4 class="heading heading-xs strong-600 text-uppercase mb-1">
+                                    {{ menu.title }}
+                                </h4>
 
-                <div class="col-lg-2">
-                    <div class="col">
-                        <h4 class="heading heading-xs strong-600 text-uppercase mb-1">
-                            Support
-                        </h4>
-
-                        <ul class="footer-links">
-                            <li><a href="/pages/faq" title="Jobs">FAQ</a></li>
-                            <li><a href="/pages/sales" title="Jobs">Sales</a></li>
-                        </ul>
-                    </div>
-                </div>
-
-                <div class="col-lg-2">
-                    <div class="col">
-                        <h4 class="heading heading-xs strong-600 text-uppercase mb-1">
-                            Company
-                        </h4>
-
-                        <ul class="footer-links">
-                            <li>
-                                <a href="/" title="Home">
-                                    Home
-                                </a>
-                            </li>
-                            <li>
-                                <a href="/pages/about-us" title="About us">
-                                    About us
-                                </a>
-                            </li>
-                            <li>
-                                <a href="/pages/service" title="Services">
-                                    Services
-                                </a>
-                            </li>
-                            <li>
-                                <a href="/collections/news" title="News">
-                                    News
-                                </a>
-                            </li>
-                            <li>
-                                <a href="/contact" title="Contact">
-                                    Contact
-                                </a>
-                            </li>
-                        </ul>
-                    </div>
-                </div>
+                                <ul class="footer-links">
+                                    {% for child in menu.children %}
+                                        {% if child.show %}
+                                            <li>
+                                                <a href="{{ child.uri }}" title="{{ child.title }}">
+                                                    {{ child.title }}
+                                                </a>
+                                            </li>
+                                        {% endif %}
+                                    {% endfor %}
+                                </ul>
+                            </div>
+                        </div>
+                    {% endif %}
+                {% endfor %}
 
                 <div class="col-lg-3">
                     <div class="col">

+ 1 - 1
resources/views/liquid/1/TechVista/_header.liquid

@@ -82,7 +82,7 @@
 
     <!-------------menus--------------->
                 <ul class="navbar-nav">
-                    {% for menu in site.menus %}
+                    {% for menu in site.menus_header %}
                         <li class="nav-item dropdown {% if menu.children and menu.children.size == 0 %}megamenu{% endif %}">
                             <a class="nav-link {% if menu.children and menu.children.size > 0 %}dropdown-toggle{% endif %}"
                                href="{% if menu.children and menu.children.size > 0 %}#{% else %}{{ menu.uri }}{% endif %}"