From ebbf6c123723000ad6dcd4ae9cc51549eead4039 Mon Sep 17 00:00:00 2001 From: make Date: Sun, 11 Jan 2026 15:59:24 +0800 Subject: [PATCH] debug --- code/app/common/helper/SiteStyle.php | 104 +++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 13 deletions(-) diff --git a/code/app/common/helper/SiteStyle.php b/code/app/common/helper/SiteStyle.php index c91c9f2..55eafcf 100644 --- a/code/app/common/helper/SiteStyle.php +++ b/code/app/common/helper/SiteStyle.php @@ -2619,16 +2619,31 @@ class SiteStyle */ private static function buildFavicon(array $TpStyle): string { - $domain = $_SERVER['HTTP_HOST'] ?? 'cli'; $safe = preg_replace('/[^a-z0-9\.\-]/i', '_', $domain); - // ===== 下面开始“只执行一次”的生成逻辑 ===== $seed = (int)($TpStyle['meta']['seed'] ?? crc32($domain)); - $bg = (string)($TpStyle['theme']['theme_color'] ?? '#263238'); - $fg = '#ffffff'; - $strSvgRoute = '/static/favicon/generated/' . $seed . '/'; + // favicon:透明背景 + 鲜艳前景(与 UI 解耦) + $bg = 'none'; + + $iconColors = [ + '#E53935', + '#D81B60', + '#8E24AA', + '#3949AB', + '#1E88E5', + '#039BE5', + '#00897B', + '#43A047', + '#FDD835', + '#FB8C00', + '#F4511E', + '#6D4C41', + ]; + $fg = $iconColors[$seed % count($iconColors)]; + + $strSvgRoute = '/static/favicon/generated/' . $seed . '/'; $strSvgGenDir = root_path() . 'public/' . $strSvgRoute; $strTmpSvgDir = $strSvgRoute . 'favicon.svg'; @@ -2639,19 +2654,16 @@ class SiteStyle @mkdir($strSvgGenDir, 0755, true); } - // 已生成过,直接复用(冻结) - if (is_file($icoFile) && is_file($svgFile)) { + if (is_file($svgFile)) { return $strTmpSvgDir; } $svgBasePath = root_path() . self::$faviconBaseDir; $bases = glob($svgBasePath . '*.svg'); if (!$bases) { - // 兜底,不影响上线 - return '/favicon.ico'; + return '/favicon.svg'; } - // 用 dom_prefix + layout 决定母型(稳定、可回放) $layout = (string)($TpStyle['global']['theme']['layout'] ?? 'A'); $dom = (string)($TpStyle['meta']['dom_prefix'] ?? ''); @@ -2660,13 +2672,11 @@ class SiteStyle $svg = file_get_contents($baseSvg); if ($svg === false) { - return '/favicon.ico'; + return '/favicon.svg'; } - // 注入主题色 $svg = str_replace(['VAR_BG', 'VAR_FG'], [$bg, $fg], $svg); - // 持久化 svg(便于排查、也便于后续升级) @file_put_contents($svgFile, $svg); // 转 ico(16 / 32)目前不使用ico @@ -2684,4 +2694,72 @@ class SiteStyle return $strTmpSvgDir; } + + // private static function buildFavicon(array $TpStyle): string + // { + + // $domain = $_SERVER['HTTP_HOST'] ?? 'cli'; + // $safe = preg_replace('/[^a-z0-9\.\-]/i', '_', $domain); + + // // ===== 下面开始“只执行一次”的生成逻辑 ===== + // $seed = (int)($TpStyle['meta']['seed'] ?? crc32($domain)); + // $bg = (string)($TpStyle['theme']['theme_color'] ?? '#263238'); + // $fg = '#ffffff'; + + // $strSvgRoute = '/static/favicon/generated/' . $seed . '/'; + // $strSvgGenDir = root_path() . 'public/' . $strSvgRoute; + // $strTmpSvgDir = $strSvgRoute . 'favicon.svg'; + + // $svgFile = $strSvgGenDir . 'favicon.svg'; + // $icoFile = $strSvgGenDir . 'favicon.ico'; + + // if (!is_dir($strSvgGenDir)) { + // @mkdir($strSvgGenDir, 0755, true); + // } + + // // 已生成过,直接复用(冻结) + // if (is_file($icoFile) && is_file($svgFile)) { + // return $strTmpSvgDir; + // } + + // $svgBasePath = root_path() . self::$faviconBaseDir; + // $bases = glob($svgBasePath . '*.svg'); + // if (!$bases) { + // // 兜底,不影响上线 + // return '/favicon.ico'; + // } + + // // 用 dom_prefix + layout 决定母型(稳定、可回放) + // $layout = (string)($TpStyle['global']['theme']['layout'] ?? 'A'); + // $dom = (string)($TpStyle['meta']['dom_prefix'] ?? ''); + + // $idx = abs(crc32($layout . '|' . $dom . '|' . $seed)) % count($bases); + // $baseSvg = $bases[$idx]; + + // $svg = file_get_contents($baseSvg); + // if ($svg === false) { + // return '/favicon.ico'; + // } + + // // 注入主题色 + // $svg = str_replace(['VAR_BG', 'VAR_FG'], [$bg, $fg], $svg); + + // // 持久化 svg(便于排查、也便于后续升级) + // @file_put_contents($svgFile, $svg); + + // // 转 ico(16 / 32)目前不使用ico + // // $bin = 'magick'; + // // if (!shell_exec('which magick')) { + // // $bin = 'convert'; + // // } + // // $cmd = sprintf( + // // '%s %s -background none -define icon:auto-resize=16,32 %s', + // // $bin, + // // escapeshellarg($svgFile), + // // escapeshellarg($icoFile) + // // ); + // // @exec($cmd); + + // return $strTmpSvgDir; + // } }