feat: 优化C端语言切换和追溯码复制

This commit is contained in:
Nixevol
2026-06-30 20:22:53 +08:00
parent 5db963cb6f
commit be68e951f7
4 changed files with 147 additions and 23 deletions
+1 -1
View File
@@ -64,5 +64,5 @@
"next": "Next"
},
"artist": "Artist",
"lang": { "zh": "中文", "en": "EN" }
"lang": { "zh": "中文", "en": "EN", "switch": "Switch language" }
}
+11 -2
View File
@@ -4,10 +4,19 @@ import enUS from './en-US.json';
const KEY = 'artveris_h5_locale';
// 支持的语言列表(后续新增语言只需在此追加)
export const SUPPORTED_LOCALES = [
{ value: 'zh-CN', label: '中文' },
{ value: 'en-US', label: 'English' },
];
export function getInitialLocale(): string {
const saved = localStorage.getItem(KEY);
if (saved) return saved;
return navigator.language.startsWith('en') ? 'en-US' : 'zh-CN';
if (saved && SUPPORTED_LOCALES.some((l) => l.value === saved)) return saved;
// 无保存值时自动跟随浏览器/系统语言
const sys = (navigator.languages?.[0] || navigator.language || '').toLowerCase();
const matched = SUPPORTED_LOCALES.find((l) => sys.startsWith(l.value.slice(0, 2)));
return matched?.value || 'zh-CN';
}
export const i18n = createI18n({
+1 -1
View File
@@ -64,5 +64,5 @@
"next": "下一个"
},
"artist": "艺术家",
"lang": { "zh": "中文", "en": "EN" }
"lang": { "zh": "中文", "en": "EN", "switch": "切换语言" }
}
+134 -19
View File
@@ -3,7 +3,42 @@
<!-- 顶栏 -->
<header class="topbar">
<span class="topbar-name text-ellipsis">{{ appName }}</span>
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
<div class="lang-wrap">
<button class="lang" :aria-label="t('lang.switch')" :title="t('lang.switch')" @click.stop="langOpen = !langOpen">
<svg viewBox="0 0 512 512" width="22" height="22" aria-hidden="true">
<path
d="M48 112h288M192 64v48M272 448l96-224 96 224M301.5 384h133M281.3 112S257 206 199 277 80 384 80 384"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="32"
/>
<path
d="M256 336s-35-27-72-75-56-85-56-85"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="32"
/>
</svg>
</button>
<transition name="lang-menu">
<ul v-if="langOpen" class="lang-menu" @click.stop>
<li
v-for="l in supportedLocales"
:key="l.value"
class="lang-item"
:class="{ active: l.value === locale }"
@click="chooseLang(l.value)"
>
<span>{{ l.label }}</span>
<span v-if="l.value === locale" class="lang-check">✓</span>
</li>
</ul>
</transition>
</div>
</header>
<!-- 加载 -->
@@ -34,7 +69,15 @@
</span>
</div>
<div v-if="data.queriedAt" class="anti-meta">{{ t('anti.queriedAt', { t: fmt(data.queriedAt) }) }}</div>
<div v-if="data.code" class="anti-code">{{ t('anti.code') }}:<span class="mono">{{ data.code }}</span></div>
<div v-if="data.code" class="anti-code">
{{ t('anti.code') }}:<span class="mono">{{ data.code }}</span>
<button class="code-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.code)">
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true">
<rect x="9" y="9" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.7" />
<path d="M5 15V5a2 2 0 0 1 2-2h8" fill="none" stroke="currentColor" stroke-width="1.7" />
</svg>
</button>
</div>
</div>
</div>
@@ -225,9 +268,6 @@
<div v-else class="chain-empty muted">{{ t('chain.notOnchain') }}</div>
</section>
<!-- 隐私说明 -->
<p class="privacy muted">{{ t('privacy.note') }}</p>
<footer class="footer muted">{{ appName }}</footer>
</template>
@@ -244,7 +284,7 @@ import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import dayjs from 'dayjs';
import { fetchTrace, fetchAppInfo } from '@/api';
import { setLocale } from '@/locales';
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
import { openMediaViewer } from '@/composables/openMediaViewer';
const route = useRoute();
@@ -263,7 +303,6 @@ function toggleNode(i: number) {
expanded.value = s;
}
const otherLangLabel = computed(() => (locale.value === 'zh-CN' ? 'EN' : '中文'));
const stateKey = computed(() => {
const s = data.value?.status;
if (s === 'DISABLED') return 'disabled';
@@ -493,8 +532,14 @@ async function resetCarousel() {
}),
);
}
function toggleLang() {
setLocale(locale.value === 'zh-CN' ? 'en-US' : 'zh-CN');
const supportedLocales = SUPPORTED_LOCALES;
const langOpen = ref(false);
function chooseLang(l: string) {
setLocale(l);
langOpen.value = false;
}
function closeLangMenu() {
langOpen.value = false;
}
async function copy(text?: string) {
if (!text) return;
@@ -534,6 +579,7 @@ onMounted(async () => {
} catch {
appName.value = t('app.name');
}
document.addEventListener('click', closeLangMenu);
});
// 数据或间隔变化时重置轮播
@@ -544,6 +590,7 @@ watch([() => data.value?.artwork?.images, carouselInterval], () => {
onUnmounted(() => {
clearAuto();
ro?.disconnect();
document.removeEventListener('click', closeLangMenu);
});
watch(
@@ -573,13 +620,70 @@ watch(
font-weight: 600;
font-size: 15px;
}
.lang-wrap {
position: relative;
}
.lang {
border: 1px solid rgba(255, 255, 255, 0.5);
display: flex;
align-items: center;
justify-content: center;
width: 34px;
height: 34px;
border: none;
background: transparent;
color: #fff;
border-radius: 999px;
padding: 3px 12px;
font-size: 12px;
border-radius: 50%;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.lang:active {
background: rgba(255, 255, 255, 0.18);
}
.lang-menu {
position: absolute;
top: calc(100% + 6px);
right: 0;
min-width: 132px;
margin: 0;
padding: 6px;
list-style: none;
background: #fff;
border-radius: 10px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
z-index: 10;
}
.lang-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 12px;
border-radius: 7px;
font-size: 14px;
color: #333;
cursor: pointer;
}
.lang-item:active {
background: #f0f3f8;
}
.lang-item.active {
color: var(--brand);
font-weight: 600;
}
.lang-check {
color: var(--brand);
}
.lang-menu-enter-active,
.lang-menu-leave-active {
transition:
opacity 0.16s ease,
transform 0.16s ease;
transform-origin: top right;
}
.lang-menu-enter-from,
.lang-menu-leave-to {
opacity: 0;
transform: scale(0.92) translateY(-4px);
}
.text-ellipsis {
overflow: hidden;
@@ -656,6 +760,23 @@ watch(
margin-top: 2px;
word-break: break-all;
}
.code-copy {
display: inline-flex;
align-items: center;
justify-content: center;
vertical-align: middle;
margin-left: 6px;
padding: 2px;
border: none;
background: transparent;
color: #fff;
opacity: 0.9;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.code-copy:active {
opacity: 0.6;
}
.carousel {
position: relative;
overflow: hidden;
@@ -1004,12 +1125,6 @@ watch(
font-size: 13px;
padding: 8px 0;
}
.privacy {
font-size: 12px;
line-height: 1.6;
padding: 0 16px;
margin: 16px 0 0;
}
.footer {
text-align: center;
font-size: 12px;