feat: 支持配置系统图标

This commit is contained in:
Nixevol
2026-07-05 00:27:44 +08:00
parent c56ca91edd
commit accc8a7d6f
20 changed files with 182 additions and 36 deletions
+1
View File
@@ -6,6 +6,7 @@
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<link rel="icon" type="image/svg+xml" href="/app-icon.svg" />
<title>艺术品溯源平台</title>
</head>
<body>
+16
View File
@@ -0,0 +1,16 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<defs>
<linearGradient id="bg" x1="12" y1="8" x2="52" y2="56" gradientUnits="userSpaceOnUse">
<stop stop-color="#1f3864"/>
<stop offset="1" stop-color="#2f6b5e"/>
</linearGradient>
<linearGradient id="seal" x1="20" y1="16" x2="44" y2="48" gradientUnits="userSpaceOnUse">
<stop stop-color="#f7d77a"/>
<stop offset="1" stop-color="#c89b3c"/>
</linearGradient>
</defs>
<rect width="64" height="64" rx="14" fill="url(#bg)"/>
<path d="M32 12 47 20v13c0 9.5-5.8 16.5-15 19-9.2-2.5-15-9.5-15-19V20l15-8Z" fill="rgba(255,255,255,.12)" stroke="rgba(255,255,255,.42)" stroke-width="2"/>
<circle cx="32" cy="31" r="12" fill="none" stroke="url(#seal)" stroke-width="3"/>
<path d="M24 33c5.3-1.2 8.9-5.1 10.3-11.5 3.2 3.3 4.9 7.1 5.1 11.5-3.7-1.7-7-1.3-9.9 1.2-1.7 1.5-3.5 2.2-5.5 2.2V33Z" fill="url(#seal)"/>
</svg>

After

Width:  |  Height:  |  Size: 917 B

+19
View File
@@ -0,0 +1,19 @@
export const DEFAULT_APP_ICON_URL = '/app-icon.svg';
export function resolveAppIcon(url?: string | null): string {
const value = String(url || '').trim();
return value || DEFAULT_APP_ICON_URL;
}
export function setFavicon(url?: string | null): void {
const href = resolveAppIcon(url);
const selectors = ['link[rel="icon"]', 'link[rel="shortcut icon"]'];
let link = document.head.querySelector<HTMLLinkElement>(selectors.join(','));
if (!link) {
link = document.createElement('link');
link.rel = 'icon';
document.head.appendChild(link);
}
link.type = href.endsWith('.svg') ? 'image/svg+xml' : '';
link.href = href;
}
+8 -8
View File
@@ -1,6 +1,6 @@
<template>
<div class="app-shell home">
<div class="logo">艺</div>
<img class="logo" :src="appIconUrl" alt="" />
<h1>{{ t('home.title') }}</h1>
<p class="muted">{{ t('home.hint') }}</p>
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
@@ -16,9 +16,11 @@ import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { fetchAppInfo } from '@/api';
import { setLocale } from '@/locales';
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
const { t, locale } = useI18n();
const appName = ref('');
const appIconUrl = ref(resolveAppIcon());
const filingInfo = ref('');
const otherLangLabel = computed(() => (locale.value === 'zh-CN' ? 'EN' : '中文'));
function toggleLang() {
@@ -28,9 +30,12 @@ onMounted(async () => {
try {
const info = await fetchAppInfo();
appName.value = info?.appName || t('app.name');
appIconUrl.value = resolveAppIcon(info?.appIconUrl);
setFavicon(appIconUrl.value);
filingInfo.value = info?.filingInfo || '';
} catch {
appName.value = t('app.name');
setFavicon(appIconUrl.value);
filingInfo.value = '';
}
});
@@ -50,13 +55,8 @@ onMounted(async () => {
width: 72px;
height: 72px;
border-radius: 18px;
background: linear-gradient(135deg, #1f3864, #2e5496);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
font-weight: 700;
object-fit: cover;
background: #f6f8fb;
}
h1 {
font-size: 22px;
+14
View File
@@ -2,6 +2,7 @@
<div class="app-shell">
<!-- 顶栏 -->
<header class="topbar">
<img class="topbar-icon" :src="appIconUrl" alt="" />
<span class="topbar-name text-ellipsis">{{ appName }}</span>
<div class="lang-wrap">
<button class="lang" :aria-label="t('lang.switch')" :title="t('lang.switch')" @click.stop="langOpen = !langOpen">
@@ -289,6 +290,7 @@ import dayjs from 'dayjs';
import { fetchTrace, fetchAppInfo } from '@/api';
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
import { openMediaViewer } from '@/composables/openMediaViewer';
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
const route = useRoute();
const { t, locale } = useI18n();
@@ -296,6 +298,7 @@ const { t, locale } = useI18n();
const loading = ref(true);
const data = ref<any>(null);
const appName = ref('');
const appIconUrl = ref(resolveAppIcon());
const filingInfo = ref('');
const toast = ref('');
@@ -578,11 +581,14 @@ onMounted(async () => {
try {
const info = await fetchAppInfo();
appName.value = info?.appName || t('app.name');
appIconUrl.value = resolveAppIcon(info?.appIconUrl);
setFavicon(appIconUrl.value);
filingInfo.value = info?.filingInfo || '';
const iv = Number(info?.carouselInterval);
if (Number.isFinite(iv) && iv >= 0) carouselInterval.value = iv;
} catch {
appName.value = t('app.name');
setFavicon(appIconUrl.value);
filingInfo.value = '';
}
document.addEventListener('click', closeLangMenu);
@@ -626,6 +632,14 @@ watch(
font-weight: 600;
font-size: 15px;
}
.topbar-icon {
width: 28px;
height: 28px;
border-radius: 7px;
object-fit: cover;
background: rgba(255, 255, 255, 0.18);
flex-shrink: 0;
}
.lang-wrap {
position: relative;
}