优化渲染逻辑

This commit is contained in:
CN-JS-HuiBai
2026-04-06 18:20:29 +08:00
parent d958aa8d74
commit 41bdb38d51

View File

@@ -35,13 +35,38 @@
document.title = settings.page_name; document.title = settings.page_name;
} }
// Handle page name visibility // Advanced Anti-Flicker: Wait for header elements to appear
if (settings.show_page_name === 0) { const observer = new MutationObserver(function(mutations, me) {
document.addEventListener('DOMContentLoaded', function() { const logoText = document.getElementById('logoText');
const lt = document.getElementById('logoText'); const logoIcon = document.getElementById('logoIconContainer');
if (lt) lt.style.display = 'none'; const header = document.getElementById('header');
});
} if (logoText || logoIcon) {
// If we found either, apply what we have
if (logoText) {
const displayTitle = settings.title || settings.page_name || '数据可视化展示大屏';
logoText.textContent = displayTitle;
if (settings.show_page_name === 0) logoText.style.display = 'none';
}
if (logoIcon) {
const actualTheme = document.documentElement.classList.contains('light-theme') ? 'light' : 'dark';
const logoToUse = (actualTheme === 'dark' && settings.logo_url_dark) ? settings.logo_url_dark : (settings.logo_url || null);
if (logoToUse) {
logoIcon.innerHTML = '<img src="' + logoToUse + '" alt="Logo" class="logo-icon-img">';
} else {
// Only if we REALLY have no logo URL, we show the default SVG fallback
// (But since it's already in HTML, we just don't touch it or we show it if we hid it)
const svg = logoIcon.querySelector('svg');
if (svg) svg.style.visibility = 'visible';
}
}
// Once found everything or we are past header, we are done
if (logoText && logoIcon) me.disconnect();
}
});
observer.observe(document.documentElement, { childList: true, subtree: true });
})(); })();
</script> </script>
</head> </head>
@@ -60,7 +85,7 @@
<div class="header-left"> <div class="header-left">
<div class="logo"> <div class="logo">
<div id="logoIconContainer"> <div id="logoIconContainer">
<svg class="logo-icon" id="logoSvg" viewBox="0 0 32 32" fill="none"> <svg class="logo-icon" id="logoSvg" viewBox="0 0 32 32" fill="none" style="visibility: hidden;">
<rect x="2" y="2" width="28" height="28" rx="8" stroke="url(#logoGrad)" stroke-width="2.5" /> <rect x="2" y="2" width="28" height="28" rx="8" stroke="url(#logoGrad)" stroke-width="2.5" />
<path d="M8 22 L12 14 L16 18 L20 10 L24 16" stroke="url(#logoGrad)" stroke-width="2" <path d="M8 22 L12 14 L16 18 L20 10 L24 16" stroke="url(#logoGrad)" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" fill="none" /> stroke-linecap="round" stroke-linejoin="round" fill="none" />
@@ -74,7 +99,7 @@
</defs> </defs>
</svg> </svg>
</div> </div>
<h1 class="logo-text" id="logoText">数据可视化展示大屏</h1> <h1 class="logo-text" id="logoText"></h1>
</div> </div>
</div> </div>
<div class="header-right"> <div class="header-right">