1154 lines
31 KiB
Vue
1154 lines
31 KiB
Vue
<template>
|
||
<div class="app-shell">
|
||
<!-- 顶栏 -->
|
||
<header class="topbar">
|
||
<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">
|
||
<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 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"
|
||
@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>
|
||
|
||
<!-- 基础信息 -->
|
||
<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-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-head">
|
||
<span class="cert-name text-ellipsis">{{ c.name }}</span>
|
||
<span v-if="c.type" class="cert-type">{{ t(`cert.type.${c.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>
|
||
</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>
|
||
</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>
|
||
</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>
|
||
</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">{{ appName }}</footer>
|
||
</template>
|
||
|
||
<!-- 轻提示 -->
|
||
<transition name="toast">
|
||
<div v-if="toast" class="toast">{{ toast }}</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';
|
||
|
||
const route = useRoute();
|
||
const { t, locale } = useI18n();
|
||
|
||
const loading = ref(true);
|
||
const data = ref<any>(null);
|
||
const appName = ref('');
|
||
const toast = ref('');
|
||
|
||
// 节点图片默认收缩,避免页面过长;点击展开
|
||
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, index);
|
||
}
|
||
|
||
// 顶部媒体轮播:单张居中、两侧露出相邻媒体边界、定时切换并带切换动画。
|
||
// 通过在首尾各复制一张「克隆」实现无缝循环:滑到克隆张后,动画结束瞬间无动画跳回真实张,
|
||
// 因此无论手动还是自动,永远不会出现“最后一张直接跳回第一张”的违和回跳。
|
||
// 后台设置 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');
|
||
const iv = Number(info?.carouselInterval);
|
||
if (Number.isFinite(iv) && iv >= 0) carouselInterval.value = iv;
|
||
} catch {
|
||
appName.value = t('app.name');
|
||
}
|
||
document.addEventListener('click', closeLangMenu);
|
||
});
|
||
|
||
// 数据或间隔变化时重置轮播
|
||
watch([() => data.value?.artwork?.images, carouselInterval], () => {
|
||
resetCarousel();
|
||
});
|
||
|
||
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, #1f3864, #2e5496);
|
||
color: #fff;
|
||
}
|
||
.topbar-name {
|
||
flex: 1;
|
||
font-weight: 600;
|
||
font-size: 15px;
|
||
}
|
||
.lang-wrap {
|
||
position: relative;
|
||
}
|
||
.lang {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 34px;
|
||
height: 34px;
|
||
border: none;
|
||
background: transparent;
|
||
color: #fff;
|
||
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;
|
||
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: 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;
|
||
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-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-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, 1fr);
|
||
gap: 12px;
|
||
}
|
||
.cert img {
|
||
width: 100%;
|
||
height: 150px;
|
||
object-fit: cover;
|
||
border-radius: 10px;
|
||
background: #e7ecf3;
|
||
}
|
||
.cert-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
margin-top: 6px;
|
||
}
|
||
.cert-name {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
flex: 1;
|
||
}
|
||
.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;
|
||
}
|
||
.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;
|
||
}
|
||
.copy {
|
||
border: 1px solid #d0d7e2;
|
||
background: #f4f7fc;
|
||
border-radius: 6px;
|
||
padding: 2px 10px;
|
||
color: var(--brand);
|
||
font-size: 12px;
|
||
}
|
||
.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 {
|
||
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;
|
||
}
|
||
</style>
|