Files
Artveris/apps/client/src/views/Trace.vue
T

1469 lines
41 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="app-shell">
<!-- 顶栏 -->
<header class="topbar">
<img class="topbar-icon" :src="appIconUrl" alt="" />
<span class="topbar-name text-ellipsis">{{ topbarTitle }}</span>
<theme-switch />
<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>
<!-- 加载 -->
<div v-if="loading" class="state">
<div class="spinner" />
<p class="muted">{{ t('state.loading') }}</p>
</div>
<!-- 异常状态 -->
<div v-else-if="data && data.status !== 'OK'" class="state">
<div class="state-badge warn">!</div>
<h2>{{ t(`state.${stateKey}Title`) }}</h2>
<p class="muted">{{ t(`state.${stateKey}Desc`) }}</p>
</div>
<!-- 正常溯源 -->
<template v-else-if="data">
<!-- 图片 / 视频轮播:单张居中、两侧露出相邻媒体边界、定时切换、克隆实现无缝循环 -->
<div
v-if="data.artwork.images?.length"
ref="carouselEl"
class="carousel"
:class="{ 'no-anim': noAnim }"
@pointerdown="onDragStart"
@pointermove="onDragMove"
@pointerup="onDragEnd"
@pointercancel="onDragEnd"
@mouseenter="pauseAuto"
@mouseleave="resumeAuto"
>
<div class="carousel-track" :style="trackStyle" @transitionend="onTransitionEnd">
<div
v-for="(s, i) in loopSlides"
:key="i"
class="carousel-slide"
:class="{ current: i === pos }"
@click="onSlideClick(i, s)"
>
<video
v-if="isVideo(s.media)"
:src="s.media.url"
class="carousel-media"
muted
playsinline
preload="metadata"
/>
<img v-else :src="s.media.url" :alt="s.media.name" class="carousel-media" loading="lazy" />
<div v-if="isVideo(s.media)" class="play-overlay">
<svg viewBox="0 0 64 64" width="56" height="56" aria-hidden="true">
<circle cx="32" cy="32" r="30" fill="rgba(0,0,0,0.42)" />
<polygon points="26,21 46,32 26,43" fill="#fff" />
</svg>
</div>
</div>
</div>
<!-- 左右切换箭头(PC 悬停显示,移动端常驻) -->
<button
v-if="data.artwork.images.length > 1"
type="button"
class="carousel-nav prev"
:aria-label="t('viewer.prev')"
@pointerdown.stop
@click.stop="go(pos - 1)"
>
‹
</button>
<button
v-if="data.artwork.images.length > 1"
type="button"
class="carousel-nav next"
:aria-label="t('viewer.next')"
@pointerdown.stop
@click.stop="go(pos + 1)"
>
›
</button>
</div>
<!-- 媒体计数 + 当前位置指示 -->
<div v-if="data.artwork.images?.length > 1" class="carousel-ind">
<div class="carousel-dots">
<button
v-for="(m, i) in data.artwork.images"
:key="i"
type="button"
class="dot"
:class="{ active: i === carouselIndex }"
:aria-label="String(i + 1)"
@click="goToReal(i)"
/>
</div>
<div class="carousel-count">
<span v-if="isVideo(data.artwork.images[carouselIndex])" class="carousel-count-ico">▶</span>
{{ carouselIndex + 1 }} / {{ data.artwork.images.length }}
</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>
<div v-if="data.artwork.artist" class="art-artist">{{ t('artist') }}:{{ data.artwork.artist }}</div>
<div class="fields">
<div v-for="(f, i) in data.artwork.fields" :key="i" class="field">
<span class="field-label">{{ f.label }}</span>
<span class="field-value">
<img
v-if="f.type === 'IMAGE' && f.value"
:src="f.value"
class="field-img"
loading="lazy"
@click="openViewer([{ url: f.value, type: 'image', name: f.label }], 0)"
/>
<a v-else-if="(f.type === 'LINK' || f.type === 'FILE') && safeUrl(f.value)" :href="safeUrl(f.value)" target="_blank" rel="noopener" class="field-link">
{{ f.type === 'FILE' ? t('field.viewFile') : f.value }}
</a>
<template v-else>{{ f.value }}</template>
</span>
</div>
</div>
</section>
<!-- 溯源时间轴 -->
<section v-if="data.timeline?.length" class="card">
<h2 class="section-title">{{ t('section.timeline') }}</h2>
<div class="timeline">
<div v-for="(n, i) in data.timeline" :key="i" class="tl-item">
<div class="tl-dot" />
<div class="tl-body">
<div class="tl-title">{{ n.title }}</div>
<div class="tl-meta muted">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
<div v-if="n.description" class="tl-desc">{{ n.description }}</div>
<template v-if="n.media?.length">
<button class="tl-toggle" @click="toggleNode(i)">
<span class="tl-toggle-ico" :class="{ open: expanded.has(i) }">▸</span>
{{ expanded.has(i) ? t('timeline.collapse') : t('timeline.expandMedia', { n: n.media.length }) }}
</button>
<div v-if="expanded.has(i)" class="tl-media">
<div v-for="(m, j) in n.media" :key="j" class="tl-media-item" @click="openViewer(n.media, j)">
<div class="tl-media-thumb">
<video v-if="isVideo(m)" :src="m.url" muted playsinline preload="metadata" />
<img v-else :src="m.url" loading="lazy" />
<div v-if="isVideo(m)" class="tl-play">▶</div>
</div>
<div v-if="m.name" class="tl-cap text-ellipsis">{{ m.name }}</div>
</div>
</div>
</template>
</div>
</div>
</div>
</section>
<!-- 认证文件 -->
<section v-if="data.certificates?.length" class="card">
<h2 class="section-title">{{ t('section.cert') }}</h2>
<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">{{ currentCert.name }}</span>
<span v-if="currentCert.type" class="cert-type">{{ t(`cert.type.${currentCert.type}`) }}</span>
</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>
<!-- 数字身份与区块链存证 -->
<section class="card">
<h2 class="section-title">{{ t('section.chain') }}</h2>
<div v-if="data.artwork.archiveNo" class="chain-row">
<span class="chain-k">{{ t('chain.archiveNo') }}</span>
<span class="chain-v mono">{{ data.artwork.archiveNo }}</span>
</div>
<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="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="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>
<span class="chain-v">{{ data.blockchain.blockHeight ?? '-' }}</span>
</div>
<div class="chain-row">
<span class="chain-k">{{ t('chain.onchainAt') }}</span>
<span class="chain-v">{{ fmt(data.blockchain.onchainAt) }}</span>
</div>
<a v-if="data.blockchain.explorerUrl" class="chain-link" :href="data.blockchain.explorerUrl" target="_blank">
{{ t('chain.explorer') }} →
</a>
</template>
<div v-else class="chain-empty muted">{{ t('chain.notOnchain') }}</div>
</section>
<footer class="footer muted">
<span>{{ appName }}</span>
<span v-if="filingInfo">{{ filingInfo }}</span>
</footer>
</template>
<!-- 轻提示 -->
<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>
<script setup lang="ts">
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
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';
import ThemeSwitch from '@/components/ThemeSwitch.vue';
const route = useRoute();
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('');
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());
function toggleNode(i: number) {
const s = new Set(expanded.value);
s.has(i) ? s.delete(i) : s.add(i);
expanded.value = s;
}
const stateKey = computed(() => {
const s = data.value?.status;
if (s === 'DISABLED') return 'disabled';
if (s === 'ABNORMAL') return 'abnormal';
return 'invalid';
});
function fmt(d?: string | null) {
return d ? dayjs(d).format('YYYY-MM-DD HH:mm') : '';
}
function fmtDate(d?: string | null) {
return d ? dayjs(d).format('YYYY-MM-DD') : '';
}
function ellipsis(s?: string) {
if (!s) return '-';
return s.length > 16 ? `${s.slice(0, 8)}…${s.slice(-6)}` : s;
}
function isVideo(m: { type?: string; url?: string }) {
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || '');
}
// 仅允许 http(s) 或站内相对路径作为外链,过滤 javascript:/data: 等危险协议
function safeUrl(v?: string): string {
if (!v) return '';
return /^(https?:\/\/|\/)/i.test(v) ? v : '';
}
function openViewer(items: any[], index: number) {
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;
}
// 顶部媒体轮播:单张居中、两侧露出相邻媒体边界、定时切换并带切换动画。
// 通过在首尾各复制一张「克隆」实现无缝循环:滑到克隆张后,动画结束瞬间无动画跳回真实张,
// 因此无论手动还是自动,永远不会出现“最后一张直接跳回第一张”的违和回跳。
// 后台设置 carouselInterval = 单张停留秒数(支持小数),0 表示不自动切换(仍可手动循环)。
const carouselEl = ref<HTMLElement | null>(null);
const carouselInterval = ref(3); // 秒/张,来自 /settings/public
const pos = ref(0); // 当前在 loopSlides 中的下标
const viewW = ref(0); // 容器宽度
const slideW = ref(0); // 单张布局宽度
const stride = ref(0); // 相邻两张中心间距(含间隙)
const dragDelta = ref(0); // 拖动中的临时位移
const dragging = ref(false);
const noAnim = ref(true); // true 时禁用过渡(用于克隆瞬移、初始化、resize、拖动)
let autoTimer: ReturnType<typeof setTimeout> | undefined;
let ro: ResizeObserver | undefined;
let startX = 0;
let startY = 0;
let axisLocked = false;
let moved = false;
const carouselCount = computed(() => data.value?.artwork?.images?.length || 0);
// 首尾各加一张克隆:[克隆(末), 真0..真N-1, 克隆(首)]
const loopSlides = computed<{ media: any; real: number }[]>(() => {
const imgs = data.value?.artwork?.images || [];
if (imgs.length <= 1) return imgs.map((m: any, idx: number) => ({ media: m, real: idx }));
const arr: { media: any; real: number }[] = [];
arr.push({ media: imgs[imgs.length - 1], real: imgs.length - 1 });
imgs.forEach((m: any, idx: number) => arr.push({ media: m, real: idx }));
arr.push({ media: imgs[0], real: 0 });
return arr;
});
// 当前真实下标(用于计数 / 圆点高亮)
const carouselIndex = computed(() => {
const n = carouselCount.value;
if (n <= 1) return 0;
return ((pos.value - 1) % n + n) % n;
});
const intervalMs = computed(() => Math.round(carouselInterval.value * 1000));
const autoEnabled = computed(() => intervalMs.value > 0 && carouselCount.value > 1);
// 轨道位移:把第 pos 张居中;拖动时叠加 dragDelta
const baseTrackX = computed(() => (viewW.value - slideW.value) / 2 - pos.value * stride.value);
const trackStyle = computed(() => ({
transform: `translateX(${baseTrackX.value + dragDelta.value}px)`,
transitionDuration: noAnim.value || dragging.value ? '0ms' : '450ms',
}));
function measureCarousel() {
const el = carouselEl.value;
if (!el) return;
viewW.value = el.clientWidth;
const track = el.querySelector('.carousel-track') as HTMLElement | null;
const slides = track?.children;
if (slides && slides.length) {
const a = slides[0] as HTMLElement;
slideW.value = a.offsetWidth; // offset* 取布局尺寸,不受 CSS transform 缩放影响
stride.value =
slides.length > 1 ? (slides[1] as HTMLElement).offsetLeft - a.offsetLeft : a.offsetWidth;
}
}
function clearAuto() {
if (autoTimer) {
clearTimeout(autoTimer);
autoTimer = undefined;
}
}
function scheduleAuto() {
clearAuto();
if (!autoEnabled.value) return;
autoTimer = setTimeout(() => next(), intervalMs.value);
}
function pauseAuto() {
clearAuto();
}
function resumeAuto() {
scheduleAuto();
}
// 切换到 loopSlides 的第 p 张(带动画),并重置自动计时
function go(p: number) {
pos.value = p;
scheduleAuto();
}
function next() {
go(pos.value + 1);
}
// 跳到真实第 i 张
function goToReal(i: number) {
go(i + 1);
}
// 动画结束后若停在克隆张,则无动画瞬移到对应真实张,实现无缝循环
async function onTransitionEnd(e: TransitionEvent) {
// 仅响应轨道自身的 transform 过渡;忽略子卡片缩放过渡的冒泡事件
if (e.target !== e.currentTarget || e.propertyName !== 'transform') return;
const n = carouselCount.value;
if (n <= 1) return;
let target = pos.value;
if (pos.value > n) target = pos.value - n; // 越过末尾克隆 → 回到真实首部
else if (pos.value < 1) target = pos.value + n; // 越过开头克隆 → 回到真实尾部
if (target === pos.value) return;
noAnim.value = true;
pos.value = target;
await nextTick();
requestAnimationFrame(() =>
requestAnimationFrame(() => {
noAnim.value = false;
}),
);
}
function onSlideClick(i: number, slide: { media: any; real: number }) {
if (moved) {
moved = false;
return; // 刚才是拖动,不触发点击
}
if (i === pos.value) {
openViewer(data.value?.artwork?.images || [], slide.real); // 点当前张 → 打开查看器
} else {
go(i); // 点两侧露出的相邻张 → 切到它
}
}
function onDragStart(e: PointerEvent) {
if (carouselCount.value <= 1) return;
dragging.value = true;
moved = false;
axisLocked = false;
startX = e.clientX;
startY = e.clientY;
dragDelta.value = 0;
pauseAuto();
// 注意:不在此处 setPointerCapture,否则会把后续 click 改派到容器,
// 导致 PC 上卡片的 @click 不触发、无法点击查看。仅在确认拖动后再捕获。
}
function onDragMove(e: PointerEvent) {
if (!dragging.value) return;
const dx = e.clientX - startX;
const dy = e.clientY - startY;
if (!axisLocked) {
if (Math.abs(dx) < 6 && Math.abs(dy) < 6) return;
axisLocked = true;
if (Math.abs(dy) > Math.abs(dx)) {
// 纵向手势 → 放弃拖动,交还页面滚动
dragging.value = false;
dragDelta.value = 0;
return;
}
// 确认为横向拖动后再捕获指针,保证拖出元素也能继续跟手
carouselEl.value?.setPointerCapture?.(e.pointerId);
}
moved = true;
dragDelta.value = dx;
}
function onDragEnd(e?: PointerEvent) {
if (!dragging.value) return;
dragging.value = false;
const dd = dragDelta.value;
dragDelta.value = 0;
if (e && carouselEl.value?.hasPointerCapture?.(e.pointerId)) {
carouselEl.value.releasePointerCapture(e.pointerId);
}
const threshold = Math.max(40, slideW.value * 0.18);
if (dd <= -threshold) go(pos.value + 1);
else if (dd >= threshold) go(pos.value - 1);
else scheduleAuto(); // 位移不够 → 回弹(pos 不变,过渡自动复位),恢复自动
}
function onCarouselResize() {
noAnim.value = true;
measureCarousel();
requestAnimationFrame(() =>
requestAnimationFrame(() => {
noAnim.value = false;
}),
);
}
// 数据 / 间隔变化时重置轮播
async function resetCarousel() {
clearAuto();
ro?.disconnect();
pos.value = carouselCount.value > 1 ? 1 : 0;
noAnim.value = true;
dragDelta.value = 0;
await nextTick();
measureCarousel();
if (carouselEl.value) {
ro = new ResizeObserver(onCarouselResize);
ro.observe(carouselEl.value);
}
requestAnimationFrame(() =>
requestAnimationFrame(() => {
noAnim.value = false;
scheduleAuto();
}),
);
}
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;
try {
await navigator.clipboard.writeText(text);
} catch {
const ta = document.createElement('textarea');
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
}
toast.value = t('chain.copied');
setTimeout(() => (toast.value = ''), 1500);
}
async function load(code: string) {
loading.value = true;
data.value = null;
expanded.value = new Set();
try {
data.value = await fetchTrace(code);
} catch {
data.value = { status: 'INVALID' };
} finally {
loading.value = false;
}
}
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);
});
// 数据或间隔变化时重置轮播
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) => {
document.title = title;
},
{ immediate: true },
);
onUnmounted(() => {
clearAuto();
ro?.disconnect();
document.removeEventListener('click', closeLangMenu);
});
watch(
() => route.params.code,
(code) => {
if (code) load(String(code));
},
{ immediate: true },
);
</script>
<style scoped>
.topbar {
position: sticky;
top: 0;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
height: 48px;
padding: 0 14px;
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: var(--soft-bg);
border: 1px solid rgba(46, 84, 150, 0.12);
flex-shrink: 0;
}
.lang-wrap {
position: relative;
}
.lang {
display: flex;
align-items: center;
justify-content: center;
width: 34px;
height: 34px;
border: none;
background: transparent;
color: #17324d;
border-radius: 50%;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.lang:active,
.lang:hover {
background: rgba(46, 84, 150, 0.08);
}
.lang-menu {
position: absolute;
top: calc(100% + 6px);
right: 0;
min-width: 132px;
margin: 0;
padding: 6px;
list-style: none;
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;
}
.lang-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 12px;
border-radius: 7px;
font-size: 14px;
color: var(--text);
cursor: pointer;
}
.lang-item:active {
background: var(--soft-bg);
}
.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;
text-overflow: ellipsis;
white-space: nowrap;
}
.state {
padding: 80px 32px;
text-align: center;
}
.state-badge {
width: 64px;
height: 64px;
border-radius: 50%;
margin: 0 auto 16px;
display: flex;
align-items: center;
justify-content: center;
font-size: 34px;
color: #fff;
background: #c0392b;
}
.spinner {
width: 36px;
height: 36px;
margin: 0 auto 14px;
border: 3px solid #d6deea;
border-top-color: #2e5496;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.anti {
display: flex;
gap: 12px;
align-items: flex-start;
margin: 12px;
padding: 16px;
border-radius: 14px;
background: linear-gradient(135deg, #0f7b63, #138a72);
color: #fff;
}
.anti-badge {
width: 40px;
height: 40px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.2);
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
flex-shrink: 0;
}
.anti-title {
font-size: 17px;
font-weight: 700;
}
.anti-desc {
font-size: 13px;
opacity: 0.92;
margin: 4px 0;
}
.anti-meta {
font-size: 12px;
opacity: 0.85;
}
.anti-code {
font-size: 12px;
opacity: 0.85;
margin-top: 2px;
word-break: break-all;
}
.code-copy {
display: none;
}
.carousel {
position: relative;
overflow: hidden;
touch-action: pan-y; /* 纵向交还页面滚动,横向手势由 JS 处理 */
user-select: none;
}
.carousel-track {
display: flex;
gap: 12px;
align-items: center;
transition-property: transform;
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%;
max-width: 420px;
height: 240px;
border-radius: 14px;
background: #e7ecf3;
overflow: hidden;
cursor: pointer;
/* 非当前张略缩小并降低不透明度,突出居中张 */
transform: scale(0.9);
opacity: 0.55;
transition:
transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1),
opacity 0.45s ease;
}
.carousel-slide.current {
transform: scale(1);
opacity: 1;
}
/* 左右切换箭头 */
.carousel-nav {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 36px;
height: 56px;
border: none;
border-radius: 10px;
background: rgba(15, 123, 99, 0.42);
color: #fff;
font-size: 26px;
line-height: 1;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
opacity: 0;
transition: opacity 0.2s ease;
-webkit-tap-highlight-color: transparent;
}
.carousel:hover .carousel-nav {
opacity: 1;
}
.carousel-nav.prev {
left: 14px;
}
.carousel-nav.next {
right: 14px;
}
.carousel-nav:active {
background: rgba(15, 123, 99, 0.7);
}
/* 触摸设备(手机)隐藏箭头,仅靠滑动切换;箭头只在 PC 显示 */
@media (hover: none) {
.carousel-nav {
display: none;
}
}
/* 媒体计数 + 当前位置指示 */
.carousel-ind {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
margin-top: 10px;
}
.carousel-dots {
display: flex;
align-items: center;
gap: 6px;
}
.carousel-dots .dot {
width: 7px;
height: 7px;
padding: 0;
border: none;
border-radius: 50%;
background: #cfd8e3;
cursor: pointer;
transition:
width 0.25s ease,
background 0.25s ease;
}
.carousel-dots .dot.active {
width: 18px;
border-radius: 4px;
background: #0f7b63;
}
.carousel-count {
display: inline-flex;
align-items: center;
gap: 3px;
font-size: 12px;
color: #6b7785;
font-variant-numeric: tabular-nums;
}
.carousel-count-ico {
font-size: 10px;
color: #0f7b63;
}
.carousel-media {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
background: #000;
}
.play-overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
}
.art-title {
font-size: 20px;
margin: 0 0 4px;
}
.art-artist {
color: var(--muted);
font-size: 14px;
margin-bottom: 10px;
}
.fields {
display: flex;
flex-direction: column;
gap: 8px;
}
.field {
display: flex;
font-size: 14px;
border-bottom: 1px dashed #eef1f5;
padding-bottom: 8px;
}
.field-label {
width: 90px;
color: var(--muted);
flex-shrink: 0;
}
.field-value {
flex: 1;
color: var(--text);
}
.field-img {
width: 96px;
height: 96px;
object-fit: cover;
border-radius: 8px;
cursor: pointer;
background: #e7ecf3;
}
.field-link {
color: var(--brand-2);
word-break: break-all;
}
.timeline {
position: relative;
}
.tl-item {
display: flex;
gap: 12px;
position: relative;
}
.tl-item:not(:last-child) .tl-body {
border-left: 2px solid #e7ecf3;
margin-left: 5px;
padding-left: 18px;
padding-bottom: 18px;
}
.tl-item:last-child .tl-body {
margin-left: 5px;
padding-left: 18px;
}
.tl-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: #2e5496;
margin-top: 4px;
position: absolute;
left: 0;
z-index: 1;
}
.tl-title {
font-weight: 600;
}
.tl-meta {
font-size: 12px;
margin: 2px 0;
}
.tl-desc {
font-size: 13px;
color: #374151;
}
.tl-toggle {
margin-top: 8px;
display: inline-flex;
align-items: center;
gap: 6px;
border: 1px solid #d0d7e2;
background: #f4f7fc;
color: var(--brand-2);
border-radius: 999px;
padding: 4px 12px;
font-size: 12px;
cursor: pointer;
}
.tl-toggle-ico {
display: inline-block;
transition: transform 0.18s ease;
}
.tl-toggle-ico.open {
transform: rotate(90deg);
}
.tl-media {
display: flex;
gap: 10px;
margin-top: 10px;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
padding-bottom: 4px;
}
.tl-media-item {
flex-shrink: 0;
width: 92px;
cursor: pointer;
}
.tl-media-thumb {
position: relative;
width: 92px;
height: 92px;
border-radius: 8px;
overflow: hidden;
background: #e7ecf3;
}
.tl-media-thumb img,
.tl-media-thumb video {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.tl-play {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 22px;
background: rgba(0, 0, 0, 0.3);
}
.tl-cap {
font-size: 12px;
color: var(--muted);
margin-top: 4px;
text-align: center;
}
.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: 170px;
object-fit: cover;
border-radius: 10px;
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;
max-width: 190px;
}
.cert-type {
font-size: 11px;
color: var(--brand-2);
background: rgba(19, 138, 114, 0.12);
border-radius: 4px;
padding: 1px 6px;
flex-shrink: 0;
}
.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;
gap: 8px;
font-size: 13px;
padding: 8px 0;
border-bottom: 1px dashed #eef1f5;
}
.chain-k {
width: 78px;
color: var(--muted);
flex-shrink: 0;
}
.chain-v {
flex: 1;
word-break: break-all;
}
.mono {
font-family: 'SFMono-Regular', Consolas, monospace;
}
.icon-copy {
width: 28px;
height: 28px;
border: 1px solid var(--border);
background: var(--card-bg);
border-radius: 50%;
color: var(--brand);
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;
margin-top: 10px;
color: var(--brand-2);
font-size: 14px;
text-decoration: none;
}
.chain-empty {
font-size: 13px;
padding: 8px 0;
}
.footer {
display: flex;
flex-direction: column;
gap: 6px;
text-align: center;
font-size: 12px;
padding: 24px 0 32px;
}
.toast {
position: fixed;
bottom: 60px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.8);
color: #fff;
padding: 8px 18px;
border-radius: 999px;
font-size: 13px;
z-index: 60;
}
.toast-enter-active,
.toast-leave-active {
transition: opacity 0.3s;
}
.toast-enter-from,
.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);
}
}
:global(html[data-theme='light']) .topbar {
background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 249, 252, 0.96));
color: #17324d;
border-bottom-color: rgba(46, 84, 150, 0.12);
box-shadow: 0 6px 18px rgba(31, 56, 100, 0.06);
}
:global(html[data-theme='light']) .lang {
color: #17324d;
}
:global(html[data-theme='light']) .lang:active,
:global(html[data-theme='light']) .lang:hover {
background: rgba(46, 84, 150, 0.08);
}
:global(html[data-theme='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);
}
:global(html[data-theme='dark']) .lang {
color: var(--text);
}
:global(html[data-theme='dark']) .lang:active,
:global(html[data-theme='dark']) .lang:hover {
background: rgba(148, 163, 184, 0.14);
}
</style>