feat: 优化客户端溯源页和后台顶部工具栏

This commit is contained in:
Nixevol
2026-07-05 02:20:35 +08:00
parent 76bdf4fa3f
commit 82ee9be014
4 changed files with 342 additions and 75 deletions
+325 -73
View File
@@ -3,7 +3,7 @@
<!-- 顶栏 -->
<header class="topbar">
<img class="topbar-icon" :src="appIconUrl" alt="" />
<span class="topbar-name text-ellipsis">{{ appName }}</span>
<span class="topbar-name text-ellipsis">{{ topbarTitle }}</span>
<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">
@@ -57,36 +57,12 @@
<!-- 正常溯源 -->
<template v-else-if="data">
<!-- 防伪横幅 -->
<div class="anti">
<div class="anti-badge">✓</div>
<div class="anti-main">
<div class="anti-title">{{ data.antiCounterfeit.firstQuery ? t('anti.firstTitle') : t('anti.repeatTitle') }}</div>
<div class="anti-desc">{{ data.antiCounterfeit.firstQuery ? t('anti.firstDesc') : t('anti.repeatDesc') }}</div>
<div class="anti-meta">
<span>{{ t('anti.queryCount', { n: data.antiCounterfeit.queryCount }) }}</span>
<span v-if="data.antiCounterfeit.firstActivatedAt">
· {{ t('anti.firstActivatedAt', { t: fmt(data.antiCounterfeit.firstActivatedAt) }) }}
</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>
<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>
<!-- 图片 / 视频轮播:单张居中、两侧露出相邻媒体边界、定时切换、克隆实现无缝循环 -->
<div
v-if="data.artwork.images?.length"
ref="carouselEl"
class="carousel"
:class="{ 'no-anim': noAnim }"
@pointerdown="onDragStart"
@pointermove="onDragMove"
@pointerup="onDragEnd"
@@ -161,6 +137,31 @@
</div>
</div>
<!-- 防伪横幅 -->
<div class="anti">
<div class="anti-badge">✓</div>
<div class="anti-main">
<div class="anti-title">{{ data.antiCounterfeit.firstQuery ? t('anti.firstTitle') : t('anti.repeatTitle') }}</div>
<div class="anti-desc">{{ data.antiCounterfeit.firstQuery ? t('anti.firstDesc') : t('anti.repeatDesc') }}</div>
<div class="anti-meta">
<span>{{ t('anti.queryCount', { n: data.antiCounterfeit.queryCount }) }}</span>
<span v-if="data.antiCounterfeit.firstActivatedAt">
· {{ t('anti.firstActivatedAt', { t: fmt(data.antiCounterfeit.firstActivatedAt) }) }}
</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>
<button class="icon-copy anti-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>
<!-- 基础信息 -->
<section class="card">
<h1 class="art-title">{{ data.artwork.title }}</h1>
@@ -219,16 +220,51 @@
<!-- 认证文件 -->
<section v-if="data.certificates?.length" class="card">
<h2 class="section-title">{{ t('section.cert') }}</h2>
<div class="cert-grid">
<div v-for="(c, i) in data.certificates" :key="i" class="cert">
<img v-if="c.url" :src="c.url" loading="lazy" @click="openViewer([{ url: c.url, name: c.name, type: 'image' }], 0)" />
<div class="cert-carousel">
<button
v-if="data.certificates.length > 1"
type="button"
class="cert-nav prev"
:aria-label="t('viewer.prev')"
@click="switchCert(-1)"
>
‹
</button>
<div v-if="currentCert" class="cert">
<img
v-if="currentCert.url"
:src="currentCert.url"
loading="lazy"
@click="openViewer(data.certificates.map((c) => ({ url: c.url, name: c.name, type: 'image' })), certIndex)"
/>
<div v-else class="cert-placeholder">{{ currentCert.name }}</div>
<div class="cert-head">
<span class="cert-name text-ellipsis">{{ c.name }}</span>
<span v-if="c.type" class="cert-type">{{ t(`cert.type.${c.type}`) }}</span>
<span class="cert-name text-ellipsis">{{ currentCert.name }}</span>
<span v-if="currentCert.type" class="cert-type">{{ t(`cert.type.${currentCert.type}`) }}</span>
</div>
<div v-if="c.issuer" class="muted cert-issuer text-ellipsis">{{ c.issuer }}</div>
<div v-if="c.issuedAt" class="muted cert-issuer">{{ fmtDate(c.issuedAt) }}</div>
<div v-if="currentCert.issuer" class="muted cert-issuer text-ellipsis">{{ currentCert.issuer }}</div>
<div v-if="currentCert.issuedAt" class="muted cert-issuer">{{ fmtDate(currentCert.issuedAt) }}</div>
</div>
<button
v-if="data.certificates.length > 1"
type="button"
class="cert-nav next"
:aria-label="t('viewer.next')"
@click="switchCert(1)"
>
›
</button>
</div>
<div v-if="data.certificates.length > 1" class="cert-dots">
<button
v-for="(_, i) in data.certificates"
:key="i"
type="button"
class="dot"
:class="{ active: i === certIndex }"
:aria-label="String(i + 1)"
@click="certIndex = i"
/>
</div>
</section>
@@ -242,17 +278,33 @@
<div class="chain-row">
<span class="chain-k">{{ t('chain.code') }}</span>
<span class="chain-v mono">{{ data.code || '-' }}</span>
<button v-if="data.code" class="icon-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.code)">
<svg viewBox="0 0 24 24" width="15" height="15" 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>
<template v-if="data.blockchain">
<div class="chain-row">
<span class="chain-k">{{ t('chain.hash') }}</span>
<span class="chain-v mono">{{ ellipsis(data.blockchain.txHash) }}</span>
<button class="copy" @click="copy(data.blockchain.txHash)">{{ t('chain.copy') }}</button>
<button class="icon-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.blockchain.txHash)">
<svg viewBox="0 0 24 24" width="15" height="15" 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 v-if="data.blockchain.dataHash" class="chain-row">
<span class="chain-k">{{ t('chain.dataHash') }}</span>
<span class="chain-v mono">{{ ellipsis(data.blockchain.dataHash) }}</span>
<button class="copy" @click="copy(data.blockchain.dataHash)">{{ t('chain.copy') }}</button>
<button class="icon-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.blockchain.dataHash)">
<svg viewBox="0 0 24 24" width="15" height="15" 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 class="chain-row">
<span class="chain-k">{{ t('chain.blockHeight') }}</span>
@@ -279,6 +331,39 @@
<transition name="toast">
<div v-if="toast" class="toast">{{ toast }}</div>
</transition>
<transition name="anti-modal">
<div v-if="antiModalOpen" class="anti-modal-mask" @click.self="antiModalOpen = false">
<div class="anti-modal">
<button class="anti-modal-close" :aria-label="t('viewer.close')" :title="t('viewer.close')" @click="antiModalOpen = false">
×
</button>
<div class="anti anti-modal-card">
<div class="anti-badge">✓</div>
<div class="anti-main">
<div class="anti-title">{{ t('anti.firstTitle') }}</div>
<div class="anti-desc">{{ t('anti.firstDesc') }}</div>
<div class="anti-meta">
<span>{{ t('anti.queryCount', { n: data?.antiCounterfeit?.queryCount ?? 0 }) }}</span>
<span v-if="data?.antiCounterfeit?.firstActivatedAt">
· {{ t('anti.firstActivatedAt', { t: fmt(data.antiCounterfeit.firstActivatedAt) }) }}
</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>
<button class="icon-copy anti-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>
</div>
</div>
</transition>
</div>
</template>
@@ -305,6 +390,13 @@ const browserTitle = computed(() => {
const archiveNo = data.value?.status === 'OK' ? data.value?.artwork?.archiveNo : '';
return archiveNo || appName.value || t('app.name');
});
const topbarTitle = computed(() => {
const archiveNo = data.value?.status === 'OK' ? data.value?.artwork?.archiveNo : '';
return archiveNo || appName.value || t('app.name');
});
const antiModalOpen = ref(false);
const certIndex = ref(0);
const currentCert = computed(() => data.value?.certificates?.[certIndex.value] || null);
// 节点图片默认收缩,避免页面过长;点击展开
const expanded = ref<Set<number>>(new Set());
@@ -340,7 +432,12 @@ function safeUrl(v?: string): string {
return /^(https?:\/\/|\/)/i.test(v) ? v : '';
}
function openViewer(items: any[], index: number) {
openMediaViewer(items, index);
openMediaViewer(items.filter((item) => item?.url), index);
}
function switchCert(step: number) {
const total = data.value?.certificates?.length || 0;
if (!total) return;
certIndex.value = (certIndex.value + step + total) % total;
}
// 顶部媒体轮播:单张居中、两侧露出相邻媒体边界、定时切换并带切换动画。
@@ -603,6 +700,14 @@ watch([() => data.value?.artwork?.images, carouselInterval], () => {
resetCarousel();
});
watch(
() => data.value,
(value) => {
certIndex.value = 0;
antiModalOpen.value = value?.status === 'OK' && value?.antiCounterfeit?.firstQuery === true;
},
);
watch(
browserTitle,
(title) => {
@@ -636,20 +741,25 @@ watch(
gap: 8px;
height: 48px;
padding: 0 14px;
background: linear-gradient(135deg, #1f3864, #2e5496);
color: #fff;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 249, 252, 0.96));
color: #17324d;
border-bottom: 1px solid rgba(46, 84, 150, 0.12);
box-shadow: 0 6px 18px rgba(31, 56, 100, 0.06);
backdrop-filter: blur(12px);
}
.topbar-name {
flex: 1;
font-weight: 600;
font-size: 15px;
letter-spacing: 0;
}
.topbar-icon {
width: 28px;
height: 28px;
border-radius: 7px;
object-fit: cover;
background: rgba(255, 255, 255, 0.18);
background: var(--soft-bg);
border: 1px solid rgba(46, 84, 150, 0.12);
flex-shrink: 0;
}
.lang-wrap {
@@ -663,13 +773,14 @@ watch(
height: 34px;
border: none;
background: transparent;
color: #fff;
color: #17324d;
border-radius: 50%;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.lang:active {
background: rgba(255, 255, 255, 0.18);
.lang:active,
.lang:hover {
background: rgba(46, 84, 150, 0.08);
}
.lang-menu {
position: absolute;
@@ -679,7 +790,8 @@ watch(
margin: 0;
padding: 6px;
list-style: none;
background: #fff;
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 10px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
z-index: 10;
@@ -692,11 +804,11 @@ watch(
padding: 9px 12px;
border-radius: 7px;
font-size: 14px;
color: #333;
color: var(--text);
cursor: pointer;
}
.lang-item:active {
background: #f0f3f8;
background: var(--soft-bg);
}
.lang-item.active {
color: var(--brand);
@@ -793,21 +905,7 @@ watch(
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;
display: none;
}
.carousel {
position: relative;
@@ -823,6 +921,10 @@ watch(
transition-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
will-change: transform;
}
.carousel.no-anim .carousel-track,
.carousel.no-anim .carousel-slide {
transition: none !important;
}
.carousel-slide {
position: relative;
flex: 0 0 80%;
@@ -1084,28 +1186,49 @@ watch(
margin-top: 4px;
text-align: center;
}
.cert-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
.cert-carousel {
position: relative;
display: flex;
align-items: center;
justify-content: center;
min-height: 238px;
padding: 0 38px;
}
.cert {
width: min(100%, 300px);
text-align: center;
}
.cert img {
width: 100%;
height: 150px;
height: 170px;
object-fit: cover;
border-radius: 10px;
background: #e7ecf3;
background: var(--soft-bg);
cursor: zoom-in;
}
.cert-placeholder {
height: 170px;
border-radius: 10px;
background: var(--soft-bg);
color: var(--muted);
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
text-align: center;
}
.cert-head {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
margin-top: 6px;
min-width: 0;
}
.cert-name {
font-size: 13px;
font-weight: 600;
flex: 1;
max-width: 190px;
}
.cert-type {
font-size: 11px;
@@ -1118,6 +1241,52 @@ watch(
.cert-issuer {
font-size: 12px;
}
.cert-nav {
position: absolute;
top: 82px;
width: 32px;
height: 44px;
border: 1px solid var(--border);
border-radius: 10px;
background: var(--card-bg);
color: var(--brand);
font-size: 24px;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.cert-nav.prev {
left: 0;
}
.cert-nav.next {
right: 0;
}
.cert-nav:active {
background: var(--soft-bg);
}
.cert-dots {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
margin-top: 10px;
}
.cert-dots .dot {
width: 7px;
height: 7px;
padding: 0;
border: none;
border-radius: 50%;
background: #cfd8e3;
cursor: pointer;
}
.cert-dots .dot.active {
width: 18px;
border-radius: 4px;
background: var(--brand-2);
}
.chain-row {
display: flex;
align-items: center;
@@ -1138,13 +1307,30 @@ watch(
.mono {
font-family: 'SFMono-Regular', Consolas, monospace;
}
.copy {
border: 1px solid #d0d7e2;
background: #f4f7fc;
border-radius: 6px;
padding: 2px 10px;
.icon-copy {
width: 28px;
height: 28px;
border: 1px solid var(--border);
background: var(--card-bg);
border-radius: 50%;
color: var(--brand);
font-size: 12px;
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
cursor: pointer;
}
.icon-copy:active {
background: var(--soft-bg);
}
.anti-copy {
width: 24px;
height: 24px;
margin-left: 6px;
border-color: rgba(255, 255, 255, 0.38);
background: rgba(255, 255, 255, 0.12);
color: #fff;
vertical-align: middle;
}
.chain-link {
display: inline-block;
@@ -1185,4 +1371,70 @@ watch(
.toast-leave-to {
opacity: 0;
}
.anti-modal-mask {
position: fixed;
inset: 0;
z-index: 50;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
background: rgba(15, 23, 42, 0.42);
backdrop-filter: blur(4px);
}
.anti-modal {
position: relative;
width: min(100%, 420px);
}
.anti-modal-card {
margin: 0;
box-shadow: 0 18px 48px rgba(15, 23, 42, 0.24);
}
.anti-modal-close {
position: absolute;
top: -12px;
right: -12px;
z-index: 2;
width: 32px;
height: 32px;
border: 1px solid rgba(15, 23, 42, 0.08);
border-radius: 50%;
background: var(--card-bg);
color: var(--text);
font-size: 22px;
line-height: 1;
cursor: pointer;
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
}
.anti-modal-enter-active,
.anti-modal-leave-active {
transition: opacity 0.18s ease;
}
.anti-modal-enter-active .anti-modal,
.anti-modal-leave-active .anti-modal {
transition: transform 0.18s ease;
}
.anti-modal-enter-from,
.anti-modal-leave-to {
opacity: 0;
}
.anti-modal-enter-from .anti-modal,
.anti-modal-leave-to .anti-modal {
transform: translateY(8px) scale(0.98);
}
@media (prefers-color-scheme: dark) {
.topbar {
background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.96));
color: var(--text);
border-bottom-color: rgba(148, 163, 184, 0.18);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.lang {
color: var(--text);
}
.lang:active,
.lang:hover {
background: rgba(148, 163, 184, 0.14);
}
}
</style>