Add support for dynamic change favicon and title (#44)

This commit is contained in:
AceDataCloud committed 2024-01-08 15:48:27 +00:00
1 parent 85fc9bc9f3
commit 945d3c3ddf
8 files changed
+78 -25

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

+31 -1
View File
@@ -2,7 +2,32 @@ export default {
/**
* The global configuration.
*/
global: {},
global: {
/**
* Title of the app.
* You can change it by your own.
*/
title: '知数云 - 数字化服务的智慧之选',
/**
* Logo url of the app.
* If provided which starts with http/https prefix, will be used.
* If not provided, will by default use @/assets/images/logo.svg as instead, you can replace it.
*/
logoUrl: undefined,
/**
* Favicon url of the app.
* If provided which starts with http/https prefix, will be used.
* If not provided, will by default use @/assets/images/favicon.ico as instead, you can replace it.
*/
faviconUrl: undefined,
/**
* The default language of the app, enum as 'zh-cn', 'en'.
*/
language: 'zh-cn'
},
/**
* The left navigation configuration.
@@ -64,6 +89,11 @@ export default {
* The auth configuration.
*/
auth: {
/**
* The default auth provider, enum as 'wechat', 'email', 'phone'.
*/
defaultProvider: 'wechat',
/**
* The auth provider configuration.
*/
+3 -1
View File
@@ -12,10 +12,12 @@ import { vLoading } from 'element-plus';
import hl from 'highlight.js';
import 'highlight.js/styles/night-owl.css';
import copyToClipboard from 'copy-to-clipboard';
import { initializeCookies } from './utils/initializer';
import { initializeCookies, initializeFavicon, initializeTitle } from './utils/initializer';
import config from './plugins/config';
initializeCookies();
initializeTitle();
initializeFavicon();
const app = createApp(App);
+36
View File
@@ -1,5 +1,10 @@
import { setCookie } from 'typescript-cookie';
import config from '@/config';
import favicon from '@/assets/images/favicon.ico';
/**
* Initialize cookies.
*/
export const initializeCookies = () => {
// parse the query string and set to cookies
const query = new URLSearchParams(window.location.search);
@@ -15,3 +20,34 @@ export const initializeCookies = () => {
});
}
};
/**
* Initialize title.
*/
export const initializeTitle = () => {
// set the title from config.global.title
const title = config.global.title;
// find the title element or insert a new one
let titleElement = document.querySelector('title');
if (!titleElement) {
titleElement = document.createElement('title');
document.head.appendChild(titleElement);
}
titleElement.innerHTML = title;
};
/**
* Initialize favicon.
*/
export const initializeFavicon = () => {
// by default use favicon which imported
// if faviconUrl is set in config, use it instead
const favIconUrl = config.global.faviconUrl;
let faviconElement = document.querySelector('link[rel="icon"]') as HTMLLinkElement;
if (!faviconElement) {
faviconElement = document.createElement('link');
faviconElement.rel = 'icon';
document.head.appendChild(faviconElement);
}
faviconElement.href = favIconUrl || favicon;
};