From 029b9312a9970e65222a946ae41878a265aa00e4 Mon Sep 17 00:00:00 2001 From: TowCents <616275696@qq.com> Date: Fri, 25 Apr 2025 15:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Web/src/utils/sysInfo.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/src/utils/sysInfo.ts | 162 +++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/Web/src/utils/sysInfo.ts b/Web/src/utils/sysInfo.ts index b3da2ff1..623134be 100644 --- a/Web/src/utils/sysInfo.ts +++ b/Web/src/utils/sysInfo.ts @@ -1,81 +1,81 @@ -import { Local } from '/@/utils/storage'; -import { storeToRefs } from 'pinia'; -import { useThemeConfig } from '/@/stores/themeConfig'; -import logoImg from '/@/assets/logo.png'; - -import { SysTenantApi } from '/@/api-services'; -import { feature, getAPI } from '/@/utils/axios-utils'; -import { updateIdleTimeout } from '/@/utils/idleTimeout'; - -const storesThemeConfig = useThemeConfig(); -const { themeConfig } = storeToRefs(storesThemeConfig); - -// 加载系统信息 -export async function loadSysInfo(tenantid: number) { - const [err, res] = await feature(getAPI(SysTenantApi).apiSysTenantSysInfoTenantIdGet(Number(tenantid))); - if (err) { - // 默认 logo 地址 - themeConfig.value.logoUrl = logoImg; - // 保存配置 - Local.remove('themeConfig'); - Local.set('themeConfig', storesThemeConfig.themeConfig); - return; - } else { - if (res.data.type != 'success' || res.data.result == null) return; - - const data = res.data.result; - // 系统logo - themeConfig.value.logoUrl = data.logo; - // 主标题 - themeConfig.value.globalTitle = data.title; - // 副标题 - themeConfig.value.globalViceTitle = data.viceTitle; - // 系统说明 - themeConfig.value.globalViceTitleMsg = data.viceDesc; - // Icp备案信息 - themeConfig.value.icp = data.icp; - themeConfig.value.icpUrl = data.icpUrl; - // 水印 - themeConfig.value.isWatermark = data.watermark != null; - themeConfig.value.watermarkText = data.watermark; - // 版权说明 - themeConfig.value.copyright = data.copyright; - // 版本号 - themeConfig.value.version = data.version; - // 全局主题 - themeConfig.value.primary = data.themeColor; - // 布局切换 - themeConfig.value.layout = data.layout; - // 面切动画 - themeConfig.value.animation = data.animation; - // 登录验证 - themeConfig.value.secondVer = data.secondVer; - themeConfig.value.captcha = data.captcha; - // 开启强制修改密码 - themeConfig.value.forceChangePassword = data.forceChangePassword; - // 是否验证密码有效期 - themeConfig.value.passwordExpirationTime = data.passwordExpirationTime; - // 开启多语言切换 - themeConfig.value.i18NSwitch = data.i18NSwitch; - // 闲置超时时间 - themeConfig.value.idleTimeout = data.idleTimeout; - // 密码加解密公匙 - window.__env__.VITE_SM_PUBLIC_KEY = data.publicKey; - - // 更新 favicon - updateFavicon(data.logo); - - // 更新空闲超时时间 - updateIdleTimeout(themeConfig.value.idleTimeout ?? 0); - - // 保存配置 - Local.remove('themeConfig'); - Local.set('themeConfig', storesThemeConfig.themeConfig); - } -} - -// 更新 favicon -const updateFavicon = (url: string): void => { - const favicon = document.getElementById('favicon') as HTMLAnchorElement; - favicon!.href = url ? url : 'data:;base64,='; -}; +import { Local } from '/@/utils/storage'; +import { storeToRefs } from 'pinia'; +import { useThemeConfig } from '/@/stores/themeConfig'; +import logoImg from '/@/assets/logo.png'; + +import { SysTenantApi } from '/@/api-services'; +import { feature, getAPI } from '/@/utils/axios-utils'; +import { updateIdleTimeout } from '/@/utils/idleTimeout'; + +const storesThemeConfig = useThemeConfig(); +const { themeConfig } = storeToRefs(storesThemeConfig); + +// 加载系统信息 +export async function loadSysInfo(tenantid: number) { + const [err, res] = await feature(getAPI(SysTenantApi).apiSysTenantSysInfoTenantIdGet(Number(tenantid))); + if (err) { + // 默认 logo 地址 + themeConfig.value.logoUrl = logoImg; + // 保存配置 + Local.remove('themeConfig'); + Local.set('themeConfig', storesThemeConfig.themeConfig); + return; + } else { + if (res.data.type != 'success' || res.data.result == null) return; + + const data = res.data.result; + // 系统logo + themeConfig.value.logoUrl = data.logo; + // 主标题 + themeConfig.value.globalTitle = data.title; + // 副标题 + themeConfig.value.globalViceTitle = data.viceTitle; + // 系统说明 + themeConfig.value.globalViceTitleMsg = data.viceDesc; + // Icp备案信息 + themeConfig.value.icp = data.icp; + themeConfig.value.icpUrl = data.icpUrl; + // 水印 + themeConfig.value.isWatermark = data.watermark != null; + themeConfig.value.watermarkText = data.watermark; + // 版权说明 + themeConfig.value.copyright = data.copyright; + // 版本号 + themeConfig.value.version = data.version; + // 全局主题 + themeConfig.value.primary = data.themeColor; + // 布局切换 + themeConfig.value.layout = data.layout; + // 面切动画 + themeConfig.value.animation = data.animation; + // 登录验证 + themeConfig.value.secondVer = data.secondVer; + themeConfig.value.captcha = data.captcha; + // 开启强制修改密码 + themeConfig.value.forceChangePassword = data.forceChangePassword; + // 是否验证密码有效期 + themeConfig.value.passwordExpirationTime = data.passwordExpirationTime; + // 开启多语言切换 + themeConfig.value.i18NSwitch = data.i18NSwitch; + // 闲置超时时间 + themeConfig.value.idleTimeout = data.idleTimeout; + // 密码加解密公匙 + window.__env__.VITE_SM_PUBLIC_KEY = data.publicKey; + + // 更新 favicon + updateFavicon(data.logo); + + // 更新空闲超时时间 + updateIdleTimeout(themeConfig.value.idleTimeout ?? 0); + + // 保存配置 + Local.remove('themeConfig'); + Local.set('themeConfig', storesThemeConfig.themeConfig); + } +} + +// 更新 favicon +export const updateFavicon = (url: string): void => { + const favicon = document.getElementById('favicon') as HTMLAnchorElement; + favicon!.href = url ? url : 'data:;base64,='; +};