diff --git a/app/admin/controller/Post.php b/app/admin/controller/Post.php index 26c0d3a..af7bc81 100644 --- a/app/admin/controller/Post.php +++ b/app/admin/controller/Post.php @@ -380,6 +380,8 @@ class Post extends Common View::assign('layoutContentHtml', $layoutContentHtml); View::assign('layoutConfig', $layoutConfig); View::assign('lastOutputId', $postOutput ? $postOutput->id : 0); + View::assign('siteName', \app\common\tools\Site::name() ?? ''); + View::assign('siteLogo', \app\common\tools\Site::logo() ?? ''); return View::fetch(); } diff --git a/public/static/js/phone-image.js b/public/static/js/phone-image.js index e017690..7f07701 100644 --- a/public/static/js/phone-image.js +++ b/public/static/js/phone-image.js @@ -112,6 +112,8 @@ var PhoneImageEngine = (function () { content_html: '', poster: '', author_name: '', + site_name: '', + site_logo: '', create_time: '', category_name: '' }; @@ -148,11 +150,14 @@ var PhoneImageEngine = (function () { postData.author_name = options.authorName || ''; postData.create_time = options.createTime || ''; postData.category_name = options.categoryName || ''; + postData.site_name = options.siteName || ''; + postData.site_logo = options.siteLogo || ''; if (userConfig) { $.extend(config, userConfig); } applyFontScale(); + preloadBrandLogo(); } /** @@ -196,6 +201,8 @@ var PhoneImageEngine = (function () { var sizeConfig = config.sizes[config.size] || config.sizes.xiaohongshu; var pageHeight = sizeConfig.height; var contentAreaHeight = pageHeight - (config.contentPadding * 2); + var brandHeaderOffset = (postData.site_name || postData.site_logo) ? BRAND_HEADER_HEIGHT : 0; + contentAreaHeight -= brandHeaderOffset; // 从预览区读取已预处理的内容 syncPreview(); @@ -827,6 +834,50 @@ var PhoneImageEngine = (function () { return true; } + // ===== 品牌头部 ===== + var BRAND_HEADER_HEIGHT = 36; + var brandLogoBase64 = null; + + function generateBrandHeader() { + if (!postData.site_name && !postData.site_logo) return ''; + + var html = '
'; + + if (postData.site_logo) { + var logoSrc = brandLogoBase64 || postData.site_logo; + html += ''; + } + + if (postData.site_name) { + html += '' + escapeHtml(postData.site_name) + ''; + } + + html += '
'; + return html; + } + + function preloadBrandLogo() { + if (!postData.site_logo) return; + if (postData.site_logo.indexOf('avatar.png') !== -1) { + postData.site_logo = ''; + return; + } + try { + var img = new Image(); + img.crossOrigin = 'anonymous'; + img.onload = function() { + var canvas = document.createElement('canvas'); + canvas.width = img.naturalWidth; + canvas.height = img.naturalHeight; + canvas.getContext('2d').drawImage(img, 0, 0); + brandLogoBase64 = canvas.toDataURL('image/png'); + }; + img.src = postData.site_logo; + } catch(e) { + // base64 conversion failed, use original URL + } + } + /** * 生成封面页HTML */ @@ -839,6 +890,7 @@ var PhoneImageEngine = (function () { html += ' no-cover-image'; } html += '" style="width:' + sizeConfig.width + 'px;height:' + sizeConfig.height + 'px;">'; + html += generateBrandHeader(); if (hasCover) { html += ''; @@ -914,6 +966,7 @@ var PhoneImageEngine = (function () { var html = '
'; + html += generateBrandHeader(); // 页头(仅第一页内容页显示标题) if (pageNum === 1) { @@ -955,6 +1008,7 @@ var PhoneImageEngine = (function () { function generateSummaryPage(sizeConfig, totalPages) { var html = '
'; + html += generateBrandHeader(); html += '
感谢阅读
'; html += '
' + escapeHtml(postData.title) + '
'; diff --git a/view/admin/post/phone_image.html b/view/admin/post/phone_image.html index 1e5d263..5cddb85 100644 --- a/view/admin/post/phone_image.html +++ b/view/admin/post/phone_image.html @@ -307,6 +307,8 @@ contentHtml: $('#post-content-html').html(), poster: poster ?? ''); ?>, authorName: author_name ?? ''); ?>, + siteName: , + siteLogo: , createTime: create_time_text ?? ''); ?>, categoryName: '' };