refactor: 重命名客户端工程
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
||||
import PhotoSwipe from 'photoswipe';
|
||||
import 'photoswipe/style.css';
|
||||
|
||||
export interface MediaItem {
|
||||
url?: string;
|
||||
name?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
function isVideo(m: MediaItem) {
|
||||
return !!m && (m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || ''));
|
||||
}
|
||||
|
||||
// 缓存图片真实尺寸,避免重复加载;PhotoSwipe 需要宽高才能正确缩放/居中
|
||||
const sizeCache = new Map<string, { w: number; h: number }>();
|
||||
function getImageSize(url: string): Promise<{ w: number; h: number }> {
|
||||
const cached = sizeCache.get(url);
|
||||
if (cached) return Promise.resolve(cached);
|
||||
return new Promise((resolve) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
const dim = { w: img.naturalWidth || 1600, h: img.naturalHeight || 1200 };
|
||||
sizeCache.set(url, dim);
|
||||
resolve(dim);
|
||||
};
|
||||
img.onerror = () => resolve({ w: 1600, h: 1200 });
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开图片 / 视频详情查看器(基于 PhotoSwipe v5)。
|
||||
* - 图片:支持双指/滚轮/双击缩放、拖动、左右滑动切换、下滑关闭。
|
||||
* - 视频:渲染为可控制的 <video> 播放,切到其它张或关闭时自动暂停。
|
||||
* - 循环:到最后一张的下一张回到第一张。
|
||||
*/
|
||||
export async function openMediaViewer(items: MediaItem[], index = 0) {
|
||||
const list = (items || []).filter((m) => m && m.url);
|
||||
if (!list.length) return;
|
||||
const start = Math.min(Math.max(0, index), list.length - 1);
|
||||
|
||||
const dataSource = await Promise.all(
|
||||
list.map(async (m) => {
|
||||
if (isVideo(m)) {
|
||||
return { type: 'video', src: m.url as string, title: m.name };
|
||||
}
|
||||
const { w, h } = await getImageSize(m.url as string);
|
||||
return { src: m.url as string, width: w, height: h, alt: m.name, title: m.name };
|
||||
}),
|
||||
);
|
||||
|
||||
const lightbox = new PhotoSwipeLightbox({
|
||||
dataSource,
|
||||
index: start,
|
||||
pswpModule: PhotoSwipe as any,
|
||||
loop: true,
|
||||
bgOpacity: 0.96,
|
||||
wheelToZoom: true,
|
||||
// 图片支持双击/双指/滚轮缩放;视频项无宽高,PhotoSwipe 会自动隐藏其缩放按钮
|
||||
});
|
||||
|
||||
// 视频项:用自定义 DOM 替换默认内容
|
||||
lightbox.on('contentLoad', (e: any) => {
|
||||
const { content } = e;
|
||||
if (content?.data?.type !== 'video') return;
|
||||
e.preventDefault();
|
||||
const wrap = document.createElement('div');
|
||||
wrap.className = 'pswp-video';
|
||||
wrap.style.cssText =
|
||||
'width:100%;height:100%;display:flex;align-items:center;justify-content:center;';
|
||||
const video = document.createElement('video');
|
||||
video.src = content.data.src;
|
||||
video.controls = true;
|
||||
video.playsInline = true;
|
||||
video.preload = 'metadata';
|
||||
video.style.cssText = 'max-width:100%;max-height:100%;background:#000;';
|
||||
wrap.appendChild(video);
|
||||
content.element = wrap;
|
||||
});
|
||||
|
||||
// 离开当前张时暂停其视频
|
||||
const pauseVideo = (e: any) => {
|
||||
const v = e?.content?.element?.querySelector?.('video') as HTMLVideoElement | null;
|
||||
if (v) v.pause();
|
||||
};
|
||||
lightbox.on('contentDeactivate', pauseVideo);
|
||||
lightbox.on('close', () => {
|
||||
const v = document.querySelector('.pswp .pswp-video video') as HTMLVideoElement | null;
|
||||
if (v) v.pause();
|
||||
});
|
||||
// 关闭后销毁实例,释放键盘/尺寸监听
|
||||
lightbox.on('destroy', () => {
|
||||
/* PhotoSwipe 自行清理 */
|
||||
});
|
||||
|
||||
lightbox.init();
|
||||
lightbox.loadAndOpen(start);
|
||||
}
|
||||
Vendored
+7
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"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}",
|
||||
"queriedAt": "This query: {t}",
|
||||
"code": "Trace Code"
|
||||
},
|
||||
"section": {
|
||||
"basic": "Basic Info",
|
||||
"timeline": "Provenance Timeline",
|
||||
"cert": "Certificates",
|
||||
"chain": "Digital Identity & Blockchain"
|
||||
},
|
||||
"timeline": {
|
||||
"expandMedia": "View images ({n})",
|
||||
"collapse": "Collapse"
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "Archive No.",
|
||||
"code": "Trace Code",
|
||||
"hash": "Tx Hash",
|
||||
"dataHash": "Data Hash",
|
||||
"blockHeight": "Block Height",
|
||||
"onchainAt": "On-chain Time",
|
||||
"explorer": "View Proof",
|
||||
"copy": "Copy",
|
||||
"copied": "Copied",
|
||||
"notOnchain": "This artwork has not been recorded on-chain yet."
|
||||
},
|
||||
"cert": {
|
||||
"type": {
|
||||
"PHOTO": "Photo with Author",
|
||||
"CERT": "Certificate",
|
||||
"APPRAISAL": "Appraisal"
|
||||
}
|
||||
},
|
||||
"field": {
|
||||
"viewFile": "View file"
|
||||
},
|
||||
"privacy": {
|
||||
"note": "Privacy: for anti-counterfeit risk control and query statistics, this visit's necessary info (time, IP, region and device) is recorded."
|
||||
},
|
||||
"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."
|
||||
},
|
||||
"viewer": {
|
||||
"zoomIn": "Zoom in",
|
||||
"zoomOut": "Zoom out",
|
||||
"reset": "Reset",
|
||||
"close": "Close",
|
||||
"prev": "Previous",
|
||||
"next": "Next"
|
||||
},
|
||||
"artist": "Artist",
|
||||
"lang": { "zh": "中文", "en": "EN", "switch": "Switch language" }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import zhCN from './zh-CN.json';
|
||||
import enUS from './en-US.json';
|
||||
|
||||
const KEY = 'artveris_client_locale';
|
||||
|
||||
// 支持的语言列表(后续新增语言只需在此追加)
|
||||
export const SUPPORTED_LOCALES = [
|
||||
{ value: 'zh-CN', label: '中文' },
|
||||
{ value: 'en-US', label: 'English' },
|
||||
];
|
||||
|
||||
export function getInitialLocale(): string {
|
||||
const saved = localStorage.getItem(KEY);
|
||||
if (saved && SUPPORTED_LOCALES.some((l) => l.value === saved)) return saved;
|
||||
// 无保存值时自动跟随浏览器/系统语言
|
||||
const sys = (navigator.languages?.[0] || navigator.language || '').toLowerCase();
|
||||
const matched = SUPPORTED_LOCALES.find((l) => sys.startsWith(l.value.slice(0, 2)));
|
||||
return matched?.value || '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';
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"app": { "name": "艺术品可信溯源" },
|
||||
"home": { "title": "艺术品可信溯源与认证", "hint": "请扫描艺术品上的防伪二维码以查看溯源信息" },
|
||||
"anti": {
|
||||
"firstTitle": "正品 · 首次查询",
|
||||
"repeatTitle": "正品验证",
|
||||
"firstDesc": "该防伪码为首次查询,本作品为正品。",
|
||||
"repeatDesc": "该防伪码已激活,请留意查询次数是否异常。",
|
||||
"queryCount": "累计查询 {n} 次",
|
||||
"firstActivatedAt": "首次激活:{t}",
|
||||
"queriedAt": "本次查询:{t}",
|
||||
"code": "唯一追溯码"
|
||||
},
|
||||
"section": {
|
||||
"basic": "基础信息",
|
||||
"timeline": "溯源时间轴",
|
||||
"cert": "认证文件",
|
||||
"chain": "数字身份与区块链存证"
|
||||
},
|
||||
"timeline": {
|
||||
"expandMedia": "查看图片({n})",
|
||||
"collapse": "收起图片"
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "档案编号",
|
||||
"code": "唯一追溯码",
|
||||
"hash": "交易哈希",
|
||||
"dataHash": "数据哈希",
|
||||
"blockHeight": "区块高度",
|
||||
"onchainAt": "上链时间",
|
||||
"explorer": "查看存证",
|
||||
"copy": "复制",
|
||||
"copied": "已复制",
|
||||
"notOnchain": "该作品暂未上链存证。"
|
||||
},
|
||||
"cert": {
|
||||
"type": {
|
||||
"PHOTO": "作者合照",
|
||||
"CERT": "证书",
|
||||
"APPRAISAL": "鉴定意见"
|
||||
}
|
||||
},
|
||||
"field": {
|
||||
"viewFile": "查看文件"
|
||||
},
|
||||
"privacy": {
|
||||
"note": "隐私说明:为防伪风控与查询统计,系统会记录本次访问的必要信息(如访问时间、IP、地区与设备信息)。"
|
||||
},
|
||||
"state": {
|
||||
"loading": "正在查询…",
|
||||
"invalidTitle": "无效的防伪码",
|
||||
"invalidDesc": "未查询到该防伪码对应的作品,请谨慎核验。",
|
||||
"disabledTitle": "防伪码已停用",
|
||||
"disabledDesc": "该防伪码已停用,请谨慎核验。",
|
||||
"abnormalTitle": "防伪码状态异常",
|
||||
"abnormalDesc": "该防伪码状态异常,请谨慎核验。"
|
||||
},
|
||||
"viewer": {
|
||||
"zoomIn": "放大",
|
||||
"zoomOut": "缩小",
|
||||
"reset": "还原",
|
||||
"close": "关闭",
|
||||
"prev": "上一个",
|
||||
"next": "下一个"
|
||||
},
|
||||
"artist": "艺术家",
|
||||
"lang": { "zh": "中文", "en": "EN", "switch": "切换语言" }
|
||||
}
|
||||
@@ -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');
|
||||
@@ -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: '/' },
|
||||
],
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user