// 获取 `keywords` 标签
|
const keywordsTag = document.querySelector("head>meta[name='keywords']");
|
// 获取 `description` 标签
|
const descriptionTag = document.querySelector("head>meta[name='description']");
|
// 获取 `title` 标签
|
const title = document.querySelector('head>title');
|
// 获取 `favicon` 标签
|
const faviconIcon = document.querySelector("head>link[rel='icon']");
|
|
const briefCorpName = window.globalConfig.SoftWareInfo.globalTitle;
|
const sysName = window.globalConfig.SoftWareInfo.globalViceTitle;
|
const icon = window.globalConfig.SoftWareInfo.favicon;
|
|
keywordsTag.content = `${briefCorpName},${sysName}`;
|
descriptionTag.content = `${briefCorpName},${sysName}`;
|
title.innerText = sysName;
|
faviconIcon.href = icon + `?v=1`;
|
|
//#region ====================== LCP Promise ======================
|
const loadBaseLCP = new Promise((resolve, reject) => {
|
try {
|
// 检查是否支持 PerformanceObserver 和 LCP 指标
|
if ('PerformanceObserver' in window && PerformanceObserver.supportedEntryTypes.includes('largest-contentful-paint')) {
|
const observer = new PerformanceObserver((list) => {
|
window.list = list.getEntries();
|
for (const entry of list.getEntries()) {
|
resolve(entry);
|
observer.disconnect(); // 完成后断开观察者
|
}
|
});
|
observer.observe({ type: 'largest-contentful-paint', buffered: true });
|
} else {
|
// 不支持时 使用onLoad 加载
|
window.addEventListener('load', () => {
|
resolve(true);
|
});
|
}
|
} catch (error) {
|
reject(error);
|
}
|
});
|
//#endregion
|
|
//#region ====================== 加载script ======================
|
|
function loadScript(src, callback) {
|
const script = document.createElement('script');
|
script.setAttribute('type', 'text/javascript');
|
script.setAttribute('src', src);
|
script.async = true;
|
script.onload = () => callback();
|
script.onerror = () => callback(new Error(`Failed to load ${src}`));
|
document.head.appendChild(script);
|
}
|
window.eventList = {};
|
|
loadBaseLCP.then(() => {
|
window.eventList.amisSdkJsPromise = new Promise((resolve, reject) => {
|
loadScript('/static/amis/sdk/sdk.js', (error) => {
|
if (error) {
|
reject(error);
|
return;
|
}
|
resolve();
|
});
|
});
|
});
|
|
//#endregion
|
|
//#region ====================== 加载样式 ======================
|
function loadStyles(styles) {
|
for (const path of styles) {
|
const style = document.createElement('link');
|
style.setAttribute('rel', 'stylesheet');
|
style.setAttribute('type', 'text/css');
|
style.setAttribute('href', path);
|
// 设置 print 可以避免阻塞页面渲染
|
style.setAttribute('media', 'print');
|
style.onload = () => {
|
style.setAttribute('media', 'all');
|
};
|
document.head.appendChild(style);
|
}
|
}
|
|
loadBaseLCP.then(() => {
|
loadStyles(['/static/amis/sdk/sdk.css', '/static/amis/sdk/helper.css', '/static/amis/sdk/iconfont.css']);
|
|
});
|
|
//#endregion
|