diff --git a/common/common.js b/common/common.js index c13f444..bfa4570 100644 --- a/common/common.js +++ b/common/common.js @@ -106,279 +106,20 @@ $(function () { $(".no-login").attr("style", "display:block"); } }; - // 获取通用配置信息(先用系统 /console/v1/common,若有插件则再用插件数据覆盖部分字段) - const getCommentInfo = () => { - $.ajax({ - url: "/console/v1/common", - method: "get", - headers: { - Authorization: "Bearer" + " " + localStorage.jwt, - }, - success: function (res) { - if (!res || res.status !== 200 || !res.data) { - return; - } - var baseData = res.data || {}; - - // 再尝试从主题配置插件读取额外配置,用于覆盖旧数据 - $.ajax({ - url: "/console/v1/theme/config", - method: "get", - headers: { - Authorization: "Bearer" + " " + localStorage.jwt, - }, - success: function (pluginRes) { - if (pluginRes && pluginRes.status === 200 && pluginRes.data) { - var cfg = pluginRes.data || {}; - - // SEO:如配置了插件 SEO,则覆盖页面标题与 meta - if (cfg.seo) { - if (cfg.seo.title) { - document.title = cfg.seo.title; - } - if (cfg.seo.keywords) { - var $kw = $('meta[name="keywords"]'); - if ($kw.length) { - $kw.attr("content", cfg.seo.keywords); - } - } - if (cfg.seo.description) { - var $desc = $('meta[name="description"]'); - if ($desc.length) { - $desc.attr("content", cfg.seo.description); - } - } - } - - // 覆盖基础字段:企业信息 & ICP 等 - baseData.enterprise_name = - cfg.enterprise_name || baseData.enterprise_name; - baseData.enterprise_telephone = - cfg.enterprise_telephone || baseData.enterprise_telephone; - baseData.enterprise_mailbox = - cfg.enterprise_mailbox || baseData.enterprise_mailbox; - baseData.enterprise_qrcode = - cfg.enterprise_qrcode || baseData.enterprise_qrcode; - baseData.official_website_logo = - cfg.official_website_logo || baseData.official_website_logo; - baseData.online_customer_service_link = - cfg.online_customer_service_link || - baseData.online_customer_service_link; - baseData.icp_info = cfg.icp_info || baseData.icp_info; - baseData.icp_info_link = - cfg.icp_info_link || baseData.icp_info_link; - baseData.public_security_network_preparation = - cfg.public_security_network_preparation || - baseData.public_security_network_preparation; - baseData.public_security_network_preparation_link = - cfg.public_security_network_preparation_link || - baseData.public_security_network_preparation_link; - baseData.telecom_appreciation = - cfg.telecom_appreciation || baseData.telecom_appreciation; - baseData.copyright_info = - cfg.copyright_info || baseData.copyright_info; - baseData.cloud_product_link = - cfg.cloud_product_link || baseData.cloud_product_link; - baseData.dcim_product_link = - cfg.dcim_product_link || baseData.dcim_product_link; - baseData.terms_service_url = - cfg.terms_service_url || baseData.terms_service_url; - baseData.terms_privacy_url = - cfg.terms_privacy_url || baseData.terms_privacy_url; - - // 数组字段:优先使用插件配置 - if (cfg.friendly_link) { - baseData.friendly_link = cfg.friendly_link; - } - if (cfg.honor) { - baseData.honor = cfg.honor; - } - if (cfg.partner) { - baseData.partner = cfg.partner; - } - if (cfg.feedback_type) { - baseData.feedback_type = cfg.feedback_type; - } - if (cfg.header_nav) { - baseData.header_nav = cfg.header_nav; - } - if (cfg.footer_nav) { - baseData.footer_nav = cfg.footer_nav; - } - if (cfg.side_floating_window) { - baseData.side_floating_window = cfg.side_floating_window; - } - } - - sessionStorage.commentData = JSON.stringify(baseData); - setCommData(); - }, - error: function () { - // 插件不可用则直接使用系统默认配置 - sessionStorage.commentData = JSON.stringify(baseData); - setCommData(); - }, - }); - }, - }); - }; - // 根据插件配置重绘顶部导航(header_nav) - const renderHeaderNav = (commentObj) => { - var navData = commentObj && commentObj.header_nav; - if (!Array.isArray(navData) || navData.length === 0) { - return; - } - - // 更新 Logo 点击链接 - var home = navData[0] || {}; - if (home.file_address) { - $(".nav-icon a").attr("href", home.file_address); - } - - var $menu = $(".nav-menu"); - var $navContSection = $(".nav-cont .section-content"); - if (!$menu.length || !$navContSection.length) { - return; - } - - // 顶部一级导航 - $menu.empty(); - for (var i = 1; i < navData.length; i++) { - var item = navData[i] || {}; - var name = item.name || ""; - var file = item.file_address || ""; - var blank = Number(item.blank) === 1; - - if (!name) { - continue; - } - - if (file) { - var $a = $("") - .attr("href", file) - .attr("target", blank ? "_blank" : "_self"); - $a.append($("
").addClass("nav-item").text(name)); - $menu.append($a); - } else { - $menu.append($("
").addClass("nav-item").text(name)); - } - } - - // 下拉菜单 - $navContSection.empty(); - for (var j = 1; j < navData.length; j++) { - var parent = navData[j] || {}; - var children = Array.isArray(parent.children) ? parent.children : []; - if (!children.length) { - $navContSection.append( - $("
").addClass("nav-cont-menu nav-cont-empty") - ); - continue; - } - - var $menuWrap = $("
").addClass( - "nav-cont-menu animated slideInDown" - ); - var $content = $("
").addClass("nav-content"); - children.forEach(function (child) { - if (!child) return; - var cname = child.name || ""; - var curl = child.file_address || ""; - var cblank = Number(child.blank) === 1; - var cicon = child.icon || ""; - var cdesc = child.description || ""; - - if (!cname && !curl) return; - - var $link = $(""); - if (curl) { - $link.attr("href", curl).attr("target", cblank ? "_blank" : "_self"); - } else { - $link.attr("href", "javascript:;"); - } - - var $box = $("
").addClass("nav-item-box"); - if (cicon) { - $box.append($("").attr("src", cicon).attr("alt", "")); - } - var $titleWrap = $("
").addClass("item-box-title"); - $titleWrap.append($("
").addClass("title").text(cname)); - $titleWrap.append($("
").addClass("desc").text(cdesc)); - $box.append($titleWrap); - - $link.append($box); - $content.append($link); - }); - - $menuWrap.append($content); - $navContSection.append($menuWrap); - } - - // 重绑 hover 事件,避免新节点没有事件 - $(".nav-menu .nav-item").off("mouseenter mouseleave"); - $(".nav-cont").off("mouseenter mouseleave"); - initHeader(); - }; - - // 设置通用信息函数 + // 设置通用信息相关的点击跳转(云服务器/物理机 CTA 等),来源于 SSR 注入的 window.__themeCommon const setCommData = () => { - const commentObj = JSON.parse(sessionStorage.commentData); - $("#enterprise_name").text(commentObj.enterprise_name); - $(".com-contact-tel").text(commentObj.enterprise_telephone); - $("#enterprise_telephone").text( - `联系电话:${commentObj.enterprise_telephone}` - ); - $("#enterprise_mailbox").text(`联系邮箱:${commentObj.enterprise_mailbox}`); - $("#enterprise_qrcode").attr("src", commentObj.enterprise_qrcode); - $("#logo").attr("src", commentObj.official_website_logo); - if (commentObj.friendly_link.length > 0) { - $("#index #footerLink").attr("style", "display: block;"); - // 先清空,再填充,避免重复叠加 - $("#footerLink a").remove(); - commentObj.friendly_link.forEach((item) => { - $("#footerLink").append( - `${item.name}` - ); - }); - } else { - $("#footerLink").attr("style", "display: none;"); - } - - // 统一覆盖底部备案信息和版权 - $("#footerRecord").html(` -
- ${commentObj.icp_info} - ${commentObj.public_security_network_preparation} - ${commentObj.telecom_appreciation} -
- ${commentObj.copyright_info} - `); - $("#terms_service_url").click(function () { - location.href = commentObj.terms_service_url; - }); - $("#terms_privacy_url").click(function () { - location.href = commentObj.terms_privacy_url; - }); - - + const commentObj = window.__themeCommon || {}; $(".buy-cloud").click(function () { - location.href = commentObj.cloud_product_link; + if (commentObj.cloud_product_link) { + location.href = commentObj.cloud_product_link; + } }); $(".buy-dcim-btn").click(function () { - location.href = commentObj.dcim_product_link; + if (commentObj.dcim_product_link) { + location.href = commentObj.dcim_product_link; + } }); - - // 顶部导航改用插件 header_nav - renderHeaderNav(commentObj); }; - $(".line-server-btn").click(function () { - const commentObj = sessionStorage.commentData - ? JSON.parse(sessionStorage.commentData) - : null; - if (commentObj && commentObj.online_customer_service_link) { - window.open(commentObj.online_customer_service_link); - } - }); // 跳转函数 const goOtherPage = (url) => { sessionStorage.redirectUrl = location.href; @@ -482,8 +223,8 @@ $(function () { }); } function initFooter() { - // 始终从后端获取最新通用配置,避免缓存导致配置不生效 - getCommentInfo(); + // 主题配置已在服务端渲染阶段注入到 window.__themeCommon,这里只做少量点击事件绑定 + setCommData(); } // 首页渲染 // $("#header").load("/web/BlackFruit-web/public/header.html", function () { diff --git a/header.html b/header.html index 0d963f5..31fd13f 100644 --- a/header.html +++ b/header.html @@ -1,11 +1,86 @@ - - - {$title} - - + + {php} + // 在渲染阶段从主题配置插件读取配置,并覆盖 $data 与 SEO 变量,实现 SSR + if (class_exists('\\addon\\theme_configurator\\model\\ThemeConfigModel')) { + $cfgModel = new \addon\theme_configurator\model\ThemeConfigModel(); + $themeCfg = $cfgModel->getConfig(); + + if (is_array($themeCfg)) { + $site = isset($themeCfg['site_config']) && is_array($themeCfg['site_config']) + ? $themeCfg['site_config'] + : []; + + if (!isset($data) || !is_array($data)) { + $data = []; + } + + // 覆盖 / 补充首页相关结构数据 + if (isset($themeCfg['banner'])) { + $data['banner'] = $themeCfg['banner']; + } + if (isset($themeCfg['honor'])) { + $data['honor'] = $themeCfg['honor']; + } + if (isset($themeCfg['partner'])) { + $data['partner'] = $themeCfg['partner']; + } + if (isset($themeCfg['friendly_link'])) { + $data['friendly_link'] = $themeCfg['friendly_link']; + } + if (isset($themeCfg['header_nav'])) { + $data['header_nav'] = $themeCfg['header_nav']; + } + if (isset($themeCfg['footer_nav'])) { + $data['footer_nav'] = $themeCfg['footer_nav']; + } + if (isset($themeCfg['side'])) { + $data['side_floating_window'] = $themeCfg['side']; + } + + // 站点基础信息,供 header/footer 与其他模板直接使用 + $data['enterprise_name'] = $site['enterprise_name'] ?? ($data['enterprise_name'] ?? ''); + $data['enterprise_telephone'] = $site['enterprise_telephone'] ?? ($data['enterprise_telephone'] ?? ''); + $data['enterprise_mailbox'] = $site['enterprise_mailbox'] ?? ($data['enterprise_mailbox'] ?? ''); + $data['enterprise_qrcode'] = $site['enterprise_qrcode'] ?? ($data['enterprise_qrcode'] ?? ''); + $data['official_website_logo']= $site['official_website_logo']?? ($data['official_website_logo']?? ''); + $data['online_customer_service_link'] = + $site['online_customer_service_link'] ?? ($data['online_customer_service_link'] ?? ''); + $data['icp_info'] = $site['icp_info'] ?? ($data['icp_info'] ?? ''); + $data['icp_info_link'] = $site['icp_info_link'] ?? ($data['icp_info_link'] ?? ''); + $data['public_security_network_preparation'] = + $site['public_security_network_preparation'] ?? + ($data['public_security_network_preparation'] ?? ''); + $data['public_security_network_preparation_link'] = + $site['public_security_network_preparation_link'] ?? + ($data['public_security_network_preparation_link'] ?? ''); + $data['telecom_appreciation'] = $site['telecom_appreciation'] ?? ($data['telecom_appreciation'] ?? ''); + $data['copyright_info'] = $site['copyright_info'] ?? ($data['copyright_info'] ?? ''); + $data['terms_service_url'] = $site['terms_service_url'] ?? ($data['terms_service_url'] ?? ''); + $data['terms_privacy_url'] = $site['terms_privacy_url'] ?? ($data['terms_privacy_url'] ?? ''); + $data['cloud_product_link'] = $site['cloud_product_link'] ?? ($data['cloud_product_link'] ?? ''); + $data['dcim_product_link'] = $site['dcim_product_link'] ?? ($data['dcim_product_link'] ?? ''); + + // SEO:如插件配置了 SEO,则覆盖控制器传入的标题/关键词/描述 + if (!empty($themeCfg['seo']['title'])) { + $title = $themeCfg['seo']['title']; + } + if (!empty($themeCfg['seo']['keywords'])) { + $keywords = $themeCfg['seo']['keywords']; + } + if (!empty($themeCfg['seo']['description'])) { + $description = $themeCfg['seo']['description']; + } + } + } + {/php} + + + {$title} + + @@ -33,13 +108,22 @@ - + "upDate": "{$up_date}" + } + + diff --git a/index.html b/index.html index 45dd75a..4c2dd42 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,44 @@ - {if ( isset($data.friendly_link) ) } - - {else /} - - {/if} + {if ( isset($data.friendly_link) && !empty($data.friendly_link) ) } + + {else /} + + {/if} diff --git a/public/header.html b/public/header.html index 4ca2a42..fa3fd31 100644 --- a/public/header.html +++ b/public/header.html @@ -1,13 +1,31 @@ @@ -68,24 +113,24 @@ {/foreach} {else /}
- -
-
-
电话咨询
-

7*24h不间断服务

-

-
-
+ +
+
+
电话咨询
+

7*24h不间断服务

+

{$data.enterprise_telephone|default=''}

+
+
- -
-
-
在线客服
-

工作日 09:00-18:00

- -
立即查询
-
+ +
+
+
在线客服
+

工作日 09:00-18:00

+ +
立即查询
+