🪄 添加自定义 favicon 功能,支持在配置中设置网站图标

This commit is contained in:
hi2hi 2025-02-06 06:04:39 +00:00
parent 13d66010df
commit 2344200815
2 changed files with 18 additions and 0 deletions

View File

@ -44,4 +44,5 @@ window.$$nazhuaConfig = {
// v1DashboardUrl: '/dashboard', // v1版本控制台地址
// v1HideNezhaDashboardBtn: true, // v1版本导航栏控制台入口/登录按钮 在nezhaVersion为v1时有效
// routeMode: 'h5', // 路由模式
// customFavicon: '', // 自定义favicon, 填写完整的url地址
};

View File

@ -33,10 +33,27 @@ if (config.nazhua.nezhaVersion) {
config.init = true;
}
/**
* 替换网站图标
*/
function replaceFavicon() {
if (config.nazhua.customFavicon) {
const link = document.querySelector("link[rel*='icon']");
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = config.nazhua.customFavicon;
}
}
replaceFavicon();
/**
* 合并自定义配置
*/
export function mergeNazhuaConfig(customConfig) {
Object.keys(customConfig).forEach((key) => {
config.nazhua[key] = customConfig[key];
});
replaceFavicon();
}
// 暴露合并配置方法
window.$mergeNazhuaConfig = mergeNazhuaConfig;