1
This commit is contained in:
@@ -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