mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-11 03:36:37 +08:00
feat(frontend): improve favicon loading with fallback to config API
- Add synchronous config API call in index.html when localStorage cache is empty - Prevents favicon flash on login page during first load - Enhance getCachedConfigs() to fetch public configs as fallback - Preserve existing siteConfig values when config keys are missing
This commit is contained in:
@@ -22,6 +22,35 @@
|
||||
cachedFavicon = '';
|
||||
}
|
||||
|
||||
// 无缓存时,尝试通过公开配置接口同步读取,避免登录页闪烁
|
||||
if (!cachedFavicon.trim()) {
|
||||
try {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/api/v1/config/get', false);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify({ name: 'app_favicon' }));
|
||||
|
||||
if (xhr.status === 200) {
|
||||
const resp = JSON.parse(xhr.responseText || '{}');
|
||||
const value =
|
||||
resp &&
|
||||
typeof resp === 'object' &&
|
||||
resp.code === 0 &&
|
||||
resp.data &&
|
||||
typeof resp.data.value === 'string'
|
||||
? resp.data.value.trim()
|
||||
: '';
|
||||
|
||||
if (value) {
|
||||
cachedFavicon = value;
|
||||
try {
|
||||
localStorage.setItem('vite_config_app_favicon', value);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
const faviconHref = cachedFavicon.trim() || defaultFavicon;
|
||||
let faviconLink = document.head.querySelector('link#app-favicon');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user