From 3720fbe4a01f3fc21ced571db327221c160d79e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E5=B0=8F=E5=A4=A9?= <1638245306@qq.com> Date: Wed, 22 May 2024 21:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96:=201.?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E5=B0=8F=E5=9B=BE=E6=A0=87;=202.=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9=E7=BD=91=E7=AB=99=E6=A0=87?= =?UTF-8?q?=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/fixtures/init_systemconfig.json | 28 ++++++++++++++ web/src/App.vue | 1 + web/src/utils/other.ts | 37 +++++++++++++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/backend/dvadmin/system/fixtures/init_systemconfig.json b/backend/dvadmin/system/fixtures/init_systemconfig.json index 543b83c..98c95cd 100644 --- a/backend/dvadmin/system/fixtures/init_systemconfig.json +++ b/backend/dvadmin/system/fixtures/init_systemconfig.json @@ -12,6 +12,34 @@ "placeholder": null, "setting": null, "children": [ + { + "parent": 10, + "title": "网页标题", + "key": "web_title", + "value": "DVAdmin", + "sort": 1, + "status": true, + "data_options": null, + "form_item_type": 0, + "rule": [], + "placeholder": "请输入网站标题", + "setting": null, + "children": [] + }, + { + "parent": 10, + "title": "网站小图标", + "key": "web_favicon", + "value": "", + "sort": 1, + "status": true, + "data_options": null, + "form_item_type": 0, + "rule": [], + "placeholder": "请输入网站小图标", + "setting": null, + "children": [] + }, { "parent": 10, "title": "开启验证码", diff --git a/web/src/App.vue b/web/src/App.vue index caa36ca..0de8738 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -87,6 +87,7 @@ watch( () => route.path, () => { other.useTitle(); + other.useFavicon(); if (!websocket.websocket) { //websockt 模块 try { diff --git a/web/src/utils/other.ts b/web/src/utils/other.ts index 08dd477..6e1033e 100644 --- a/web/src/utils/other.ts +++ b/web/src/utils/other.ts @@ -8,6 +8,7 @@ import { useThemeConfig } from '/@/stores/themeConfig'; import { i18n } from '/@/i18n/index'; import { Local } from '/@/utils/storage'; import { verifyUrl } from '/@/utils/toolsValidate'; +import {SystemConfigStore} from "/@/stores/systemConfig"; // 引入组件 const SvgIcon = defineAsyncComponent(() => import('/@/components/svgIcon/index.vue')); @@ -30,18 +31,43 @@ export function elSvg(app: App) { * @method const title = useTitle(); ==> title() */ export function useTitle() { - const stores = useThemeConfig(pinia); - const { themeConfig } = storeToRefs(stores); + const stores = SystemConfigStore(pinia); + const { systemConfig } = storeToRefs(stores); nextTick(() => { let webTitle = ''; - let globalTitle: string = themeConfig.value.globalTitle; + let globalTitle: string = systemConfig['base.web_title']; const { path, meta } = router.currentRoute.value; if (path === '/login') { webTitle = meta.title; } else { webTitle = setTagsViewNameI18n(router.currentRoute.value); } - document.title = `${webTitle} - ${globalTitle}` || globalTitle; + document.title = `${webTitle} - ${globalTitle}` || "DVAdmin"; + }); +} + +/*** + * 设置网站favicon图标 + */ +export function useFavicon() { + const stores = SystemConfigStore(pinia); + const { systemConfig } = storeToRefs(stores); + nextTick(() => { + const iconUrl = systemConfig.value['base.web_favicon'] + if(iconUrl){ + // 动态设置 favicon,这里假设 favicon 的 URL 是动态获取的或从变量中来 + const faviconUrl = `${iconUrl}?t=${new Date().getTime()}`; + const link = document.querySelector("link[rel~='icon']") as HTMLLinkElement; + if (!link) { + const newLink = document.createElement('link') as HTMLLinkElement; + newLink.rel = 'shortcut icon'; + newLink.href = faviconUrl; + document.head.appendChild(newLink); + } else { + link.href = faviconUrl; + } + } + }); } @@ -191,6 +217,9 @@ const other = { useTitle: () => { useTitle(); }, + useFavicon:()=>{ + useFavicon() + }, setTagsViewNameI18n(route: RouteToFrom) { return setTagsViewNameI18n(route); },