feat: 实现 C 端移动溯源页(响应式 H5 + 中英 i18n)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,487 @@
|
||||
<template>
|
||||
<div class="app-shell">
|
||||
<!-- 顶栏 -->
|
||||
<header class="topbar">
|
||||
<span class="topbar-name text-ellipsis">{{ appName }}</span>
|
||||
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
<!-- 图片轮播 -->
|
||||
<div v-if="data.artwork.images?.length" class="carousel">
|
||||
<img
|
||||
v-for="(img, i) in data.artwork.images"
|
||||
:key="i"
|
||||
:src="img.url"
|
||||
class="carousel-img"
|
||||
@click="openLightbox(img.url)"
|
||||
/>
|
||||
</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">{{ f.value }}</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>
|
||||
<div v-if="n.media?.length" class="tl-media">
|
||||
<img v-for="(m, j) in n.media" :key="j" :src="m.url" @click="openLightbox(m.url)" />
|
||||
</div>
|
||||
</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" @click="openLightbox(c.url)" />
|
||||
<div class="cert-name text-ellipsis">{{ c.name }}</div>
|
||||
<div v-if="c.issuer" class="muted cert-issuer text-ellipsis">{{ c.issuer }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 区块链存证 -->
|
||||
<section v-if="data.blockchain" class="card">
|
||||
<h2 class="section-title">{{ t('section.chain') }}</h2>
|
||||
<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 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>
|
||||
</section>
|
||||
|
||||
<footer class="footer muted">{{ appName }}</footer>
|
||||
</template>
|
||||
|
||||
<!-- 大图预览 -->
|
||||
<div v-if="lightbox" class="lightbox" @click="lightbox = ''">
|
||||
<img :src="lightbox" />
|
||||
</div>
|
||||
|
||||
<!-- 轻提示 -->
|
||||
<transition name="toast">
|
||||
<div v-if="toast" class="toast">{{ toast }}</div>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchTrace, fetchAppInfo } from '@/api';
|
||||
import { setLocale } from '@/locales';
|
||||
|
||||
const route = useRoute();
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const loading = ref(true);
|
||||
const data = ref<any>(null);
|
||||
const appName = ref('');
|
||||
const lightbox = ref('');
|
||||
const toast = ref('');
|
||||
|
||||
const otherLangLabel = computed(() => (locale.value === 'zh-CN' ? 'EN' : '中文'));
|
||||
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 openLightbox(url: string) {
|
||||
lightbox.value = url;
|
||||
}
|
||||
function toggleLang() {
|
||||
setLocale(locale.value === 'zh-CN' ? 'en-US' : 'zh-CN');
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const info = await fetchAppInfo();
|
||||
appName.value = info?.appName || t('app.name');
|
||||
} catch {
|
||||
appName.value = t('app.name');
|
||||
}
|
||||
try {
|
||||
data.value = await fetchTrace(String(route.params.code));
|
||||
} catch {
|
||||
data.value = { status: 'INVALID' };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
</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 {
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
background: transparent;
|
||||
color: #fff;
|
||||
border-radius: 999px;
|
||||
padding: 3px 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
.carousel {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 0 12px;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
.carousel-img {
|
||||
width: 86%;
|
||||
height: 240px;
|
||||
object-fit: cover;
|
||||
border-radius: 14px;
|
||||
scroll-snap-align: center;
|
||||
flex-shrink: 0;
|
||||
background: #e7ecf3;
|
||||
}
|
||||
.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);
|
||||
}
|
||||
.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-media {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.tl-media img {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.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-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
.footer {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
padding: 24px 0 32px;
|
||||
}
|
||||
.lightbox {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.92);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 50;
|
||||
}
|
||||
.lightbox img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
.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>
|
||||
Reference in New Issue
Block a user