feat: 实现 C 端移动溯源页(响应式 H5 + 中英 i18n)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:58:04 +08:00
co-authored by Cursor
parent 5fa84f346b
commit 45c4b11938
17 changed files with 849 additions and 2 deletions
+1 -2
View File
@@ -43,8 +43,7 @@ export default (): AppConfig => {
adminOrigin: process.env.ADMIN_ORIGIN || 'http://localhost:5173',
h5Origin,
// 短链跳转到 C 端溯源页的地址模板,{code} 会被替换为短码
traceUrlTemplate:
process.env.TRACE_URL_TEMPLATE || `${h5Origin}/#/pages/trace/index?code={code}`,
traceUrlTemplate: process.env.TRACE_URL_TEMPLATE || `${h5Origin}/#/trace/{code}`,
jwt: {
secret: process.env.JWT_SECRET || 'artveris_dev_secret',
expiresIn: process.env.JWT_EXPIRES_IN || '7d',
+15
View File
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<title>艺术品溯源认证</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+25
View File
@@ -0,0 +1,25 @@
{
"name": "@artveris/h5",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"dev:h5": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "echo \"(h5) lint skipped\""
},
"dependencies": {
"axios": "^1.7.9",
"dayjs": "^1.11.13",
"vue": "^3.5.13",
"vue-i18n": "^9.14.2",
"vue-router": "^4.5.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
"typescript": "^5.6.3",
"vite": "^5.4.11"
}
}
+3
View File
@@ -0,0 +1,3 @@
<template>
<router-view />
</template>
+22
View File
@@ -0,0 +1,22 @@
import axios from 'axios';
const instance = axios.create({ baseURL: '/api', timeout: 20000 });
instance.interceptors.response.use(
(res) => {
const body = res.data;
if (body && typeof body === 'object' && 'code' in body) {
return body.code === 0 ? body.data : Promise.reject(body);
}
return body;
},
(err) => Promise.reject(err),
);
export function fetchTrace(shortCode: string): Promise<any> {
return instance.get(`/public/trace/${shortCode}`) as unknown as Promise<any>;
}
export function fetchAppInfo(): Promise<any> {
return instance.get('/settings/public') as unknown as Promise<any>;
}
+7
View File
@@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>;
export default component;
}
+38
View File
@@ -0,0 +1,38 @@
{
"app": { "name": "Artwork Traceability" },
"home": { "title": "Artwork Traceability & Authentication", "hint": "Scan the anti-counterfeit QR code on the artwork to view its provenance" },
"anti": {
"firstTitle": "Genuine · First Query",
"repeatTitle": "Authenticity Verified",
"firstDesc": "This is the first query of the code. The artwork is genuine.",
"repeatDesc": "This code has been activated. Please note the query count.",
"queryCount": "Queried {n} times",
"firstActivatedAt": "First activated: {t}"
},
"section": {
"basic": "Basic Info",
"timeline": "Provenance Timeline",
"cert": "Certificates",
"chain": "Blockchain Attestation"
},
"chain": {
"hash": "Tx Hash",
"dataHash": "Data Hash",
"blockHeight": "Block Height",
"onchainAt": "On-chain Time",
"explorer": "View Proof",
"copy": "Copy",
"copied": "Copied"
},
"state": {
"loading": "Loading…",
"invalidTitle": "Invalid Code",
"invalidDesc": "No artwork found for this code. Please verify carefully.",
"disabledTitle": "Code Disabled",
"disabledDesc": "This code has been disabled. Please verify carefully.",
"abnormalTitle": "Abnormal Status",
"abnormalDesc": "This code status is abnormal. Please verify carefully."
},
"artist": "Artist",
"lang": { "zh": "中文", "en": "EN" }
}
+23
View File
@@ -0,0 +1,23 @@
import { createI18n } from 'vue-i18n';
import zhCN from './zh-CN.json';
import enUS from './en-US.json';
const KEY = 'artveris_h5_locale';
export function getInitialLocale(): string {
const saved = localStorage.getItem(KEY);
if (saved) return saved;
return navigator.language.startsWith('en') ? 'en-US' : 'zh-CN';
}
export const i18n = createI18n({
legacy: false,
locale: getInitialLocale(),
fallbackLocale: 'zh-CN',
messages: { 'zh-CN': zhCN, 'en-US': enUS },
});
export function setLocale(l: string): void {
localStorage.setItem(KEY, l);
i18n.global.locale.value = l as 'zh-CN' | 'en-US';
}
+38
View File
@@ -0,0 +1,38 @@
{
"app": { "name": "艺术品可信溯源" },
"home": { "title": "艺术品可信溯源与认证", "hint": "请扫描艺术品上的防伪二维码以查看溯源信息" },
"anti": {
"firstTitle": "正品 · 首次查询",
"repeatTitle": "正品验证",
"firstDesc": "该防伪码为首次查询,本作品为正品。",
"repeatDesc": "该防伪码已激活,请留意查询次数是否异常。",
"queryCount": "累计查询 {n} 次",
"firstActivatedAt": "首次激活:{t}"
},
"section": {
"basic": "基础信息",
"timeline": "溯源时间轴",
"cert": "认证文件",
"chain": "区块链存证"
},
"chain": {
"hash": "交易哈希",
"dataHash": "数据哈希",
"blockHeight": "区块高度",
"onchainAt": "上链时间",
"explorer": "查看存证",
"copy": "复制",
"copied": "已复制"
},
"state": {
"loading": "正在查询…",
"invalidTitle": "无效的防伪码",
"invalidDesc": "未查询到该防伪码对应的作品,请谨慎核验。",
"disabledTitle": "防伪码已停用",
"disabledDesc": "该防伪码已停用,请谨慎核验。",
"abnormalTitle": "防伪码状态异常",
"abnormalDesc": "该防伪码状态异常,请谨慎核验。"
},
"artist": "艺术家",
"lang": { "zh": "中文", "en": "EN" }
}
+7
View File
@@ -0,0 +1,7 @@
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import { i18n } from './locales';
import './styles.css';
createApp(App).use(router).use(i18n).mount('#app');
+10
View File
@@ -0,0 +1,10 @@
import { createRouter, createWebHashHistory } from 'vue-router';
export default createRouter({
history: createWebHashHistory(),
routes: [
{ path: '/', component: () => import('@/views/Home.vue') },
{ path: '/trace/:code', component: () => import('@/views/Trace.vue') },
{ path: '/:pathMatch(.*)*', redirect: '/' },
],
});
+51
View File
@@ -0,0 +1,51 @@
:root {
--brand: #1f3864;
--brand-2: #2e5496;
--bg: #f3f5f9;
--text: #1f2937;
--muted: #6b7280;
}
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body,
#app {
margin: 0;
padding: 0;
min-height: 100%;
font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
color: var(--text);
background: var(--bg);
}
/* 移动优先;PC 居中为手机宽度容器 */
.app-shell {
max-width: 560px;
margin: 0 auto;
min-height: 100vh;
background: var(--bg);
position: relative;
box-shadow: 0 0 24px rgba(0, 0, 0, 0.04);
}
.card {
background: #fff;
border-radius: 14px;
margin: 12px;
padding: 16px;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
}
.section-title {
font-size: 16px;
font-weight: 700;
margin: 0 0 12px;
padding-left: 10px;
border-left: 4px solid var(--brand-2);
line-height: 1.2;
}
.muted {
color: var(--muted);
}
button {
font-family: inherit;
}
+56
View File
@@ -0,0 +1,56 @@
<template>
<div class="app-shell home">
<div class="logo">艺</div>
<h1>{{ t('home.title') }}</h1>
<p class="muted">{{ t('home.hint') }}</p>
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { setLocale } from '@/locales';
const { t, locale } = useI18n();
const otherLangLabel = computed(() => (locale.value === 'zh-CN' ? 'EN' : '中文'));
function toggleLang() {
setLocale(locale.value === 'zh-CN' ? 'en-US' : 'zh-CN');
}
</script>
<style scoped>
.home {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
padding: 40px 28px;
gap: 14px;
}
.logo {
width: 72px;
height: 72px;
border-radius: 18px;
background: linear-gradient(135deg, #1f3864, #2e5496);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
font-weight: 700;
}
h1 {
font-size: 22px;
margin: 8px 0 0;
}
.lang {
margin-top: 16px;
border: 1px solid #d0d7e2;
background: #fff;
border-radius: 999px;
padding: 6px 18px;
color: var(--brand);
}
</style>
+487
View File
@@ -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>
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2021",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"jsx": "preserve",
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"lib": ["ES2021", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"baseUrl": ".",
"paths": { "@/*": ["src/*"] }
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue", "vite.config.ts"]
}
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { fileURLToPath, URL } from 'node:url';
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
port: 5174,
host: true,
proxy: {
'/api': { target: 'http://localhost:3000', changeOrigin: true },
},
},
});
+28
View File
@@ -178,6 +178,34 @@ importers:
specifier: ^5.6.3
version: 5.9.3
apps/h5:
dependencies:
axios:
specifier: ^1.7.9
version: 1.18.1
dayjs:
specifier: ^1.11.13
version: 1.11.21
vue:
specifier: ^3.5.13
version: 3.5.39(typescript@5.9.3)
vue-i18n:
specifier: ^9.14.2
version: 9.14.5(vue@3.5.39(typescript@5.9.3))
vue-router:
specifier: ^4.5.0
version: 4.6.4(vue@3.5.39(typescript@5.9.3))
devDependencies:
'@vitejs/plugin-vue':
specifier: ^5.2.1
version: 5.2.4(vite@5.4.21(@types/node@22.20.0)(terser@5.48.0))(vue@3.5.39(typescript@5.9.3))
typescript:
specifier: ^5.6.3
version: 5.9.3
vite:
specifier: ^5.4.11
version: 5.4.21(@types/node@22.20.0)(terser@5.48.0)
packages/shared:
devDependencies:
typescript: