1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
@@ -8,6 +8,26 @@
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
|
||||
<title>民众智创</title>
|
||||
<script>
|
||||
(function() {
|
||||
var cached = localStorage.getItem('siteInfo');
|
||||
if (cached) {
|
||||
try {
|
||||
var info = JSON.parse(cached);
|
||||
if (info.siteName) {
|
||||
document.title = info.siteName;
|
||||
}
|
||||
if (info.siteLogo) {
|
||||
var link = document.querySelector('link[rel="icon"]');
|
||||
if (link) {
|
||||
link.href = info.siteLogo;
|
||||
link.type = 'image/png';
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -141,11 +141,24 @@ const AppLayout: React.FC = () => {
|
||||
const [unreadCount, setUnreadCount] = useState(0);
|
||||
const [siteName, setSiteName] = useState(() => {
|
||||
const cached = localStorage.getItem('siteInfo');
|
||||
return cached ? JSON.parse(cached).siteName || '' : '';
|
||||
const name = cached ? JSON.parse(cached).siteName || '' : '';
|
||||
if (name) document.title = name;
|
||||
return name;
|
||||
});
|
||||
const [siteLogo, setSiteLogo] = useState(() => {
|
||||
const cached = localStorage.getItem('siteInfo');
|
||||
return cached ? JSON.parse(cached).siteLogo || '' : '';
|
||||
const logo = cached ? JSON.parse(cached).siteLogo || '' : '';
|
||||
if (logo) {
|
||||
let faviconLink = document.querySelector('link[rel="icon"]') as HTMLLinkElement;
|
||||
if (!faviconLink) {
|
||||
faviconLink = document.createElement('link');
|
||||
faviconLink.rel = 'icon';
|
||||
document.head.appendChild(faviconLink);
|
||||
}
|
||||
faviconLink.href = logo;
|
||||
faviconLink.type = 'image/png';
|
||||
}
|
||||
return logo;
|
||||
});
|
||||
const [siteInfoLoading, setSiteInfoLoading] = useState(!localStorage.getItem('siteInfo'));
|
||||
const [qrCodeModalOpen, setQrCodeModalOpen] = useState(false);
|
||||
@@ -171,29 +184,29 @@ const AppLayout: React.FC = () => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const cached = localStorage.getItem('siteInfo');
|
||||
if (!cached) {
|
||||
setSiteName('民众智创');
|
||||
setSiteLogo('');
|
||||
document.title = '民众智创';
|
||||
}
|
||||
|
||||
getSiteInfo().then(info => {
|
||||
const siteName = info.siteName || '民众智创';
|
||||
const siteLogo = info.siteLogo || '';
|
||||
setSiteName(siteName);
|
||||
setSiteLogo(siteLogo);
|
||||
document.title = siteName;
|
||||
localStorage.setItem('siteInfo', JSON.stringify({ siteName, siteLogo }));
|
||||
}).catch(() => {
|
||||
// 如果没有缓存且请求失败,使用默认值
|
||||
if (!cached) {
|
||||
setSiteName('民众智创');
|
||||
document.title = '民众智创';
|
||||
const name = info.siteName || '民众智创';
|
||||
const logo = info.siteLogo || '';
|
||||
|
||||
if (name !== siteName) {
|
||||
setSiteName(name);
|
||||
document.title = name;
|
||||
}
|
||||
}).finally(() => {
|
||||
setSiteInfoLoading(false);
|
||||
});
|
||||
|
||||
if (logo && logo !== siteLogo) {
|
||||
setSiteLogo(logo);
|
||||
let faviconLink = document.querySelector('link[rel="icon"]') as HTMLLinkElement;
|
||||
if (!faviconLink) {
|
||||
faviconLink = document.createElement('link');
|
||||
faviconLink.rel = 'icon';
|
||||
document.head.appendChild(faviconLink);
|
||||
}
|
||||
faviconLink.href = logo;
|
||||
faviconLink.type = 'image/png';
|
||||
}
|
||||
|
||||
localStorage.setItem('siteInfo', JSON.stringify({ siteName: name, siteLogo: logo }));
|
||||
}).catch(() => {});
|
||||
}, []);
|
||||
|
||||
const loadUnreadCount = () => {
|
||||
|
||||
Reference in New Issue
Block a user