From 45c4b11938c6d88553b1de609713bda8b907f0f5 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 28 Jun 2026 16:58:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=20C=20=E7=AB=AF?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=BA=AF=E6=BA=90=E9=A1=B5=EF=BC=88=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=BC=8F=20H5=20+=20=E4=B8=AD=E8=8B=B1=20i18n?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- apps/api/src/config/configuration.ts | 3 +- apps/h5/index.html | 15 + apps/h5/package.json | 25 ++ apps/h5/src/App.vue | 3 + apps/h5/src/api.ts | 22 ++ apps/h5/src/env.d.ts | 7 + apps/h5/src/locales/en-US.json | 38 +++ apps/h5/src/locales/index.ts | 23 ++ apps/h5/src/locales/zh-CN.json | 38 +++ apps/h5/src/main.ts | 7 + apps/h5/src/router.ts | 10 + apps/h5/src/styles.css | 51 +++ apps/h5/src/views/Home.vue | 56 +++ apps/h5/src/views/Trace.vue | 487 +++++++++++++++++++++++++++ apps/h5/tsconfig.json | 19 ++ apps/h5/vite.config.ts | 19 ++ pnpm-lock.yaml | 28 ++ 17 files changed, 849 insertions(+), 2 deletions(-) create mode 100644 apps/h5/index.html create mode 100644 apps/h5/package.json create mode 100644 apps/h5/src/App.vue create mode 100644 apps/h5/src/api.ts create mode 100644 apps/h5/src/env.d.ts create mode 100644 apps/h5/src/locales/en-US.json create mode 100644 apps/h5/src/locales/index.ts create mode 100644 apps/h5/src/locales/zh-CN.json create mode 100644 apps/h5/src/main.ts create mode 100644 apps/h5/src/router.ts create mode 100644 apps/h5/src/styles.css create mode 100644 apps/h5/src/views/Home.vue create mode 100644 apps/h5/src/views/Trace.vue create mode 100644 apps/h5/tsconfig.json create mode 100644 apps/h5/vite.config.ts diff --git a/apps/api/src/config/configuration.ts b/apps/api/src/config/configuration.ts index d36aed3..1b41b78 100644 --- a/apps/api/src/config/configuration.ts +++ b/apps/api/src/config/configuration.ts @@ -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', diff --git a/apps/h5/index.html b/apps/h5/index.html new file mode 100644 index 0000000..dddd90c --- /dev/null +++ b/apps/h5/index.html @@ -0,0 +1,15 @@ + + + + + + 艺术品溯源认证 + + +
+ + + diff --git a/apps/h5/package.json b/apps/h5/package.json new file mode 100644 index 0000000..67fe0ab --- /dev/null +++ b/apps/h5/package.json @@ -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" + } +} diff --git a/apps/h5/src/App.vue b/apps/h5/src/App.vue new file mode 100644 index 0000000..98240ae --- /dev/null +++ b/apps/h5/src/App.vue @@ -0,0 +1,3 @@ + diff --git a/apps/h5/src/api.ts b/apps/h5/src/api.ts new file mode 100644 index 0000000..787ea78 --- /dev/null +++ b/apps/h5/src/api.ts @@ -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 { + return instance.get(`/public/trace/${shortCode}`) as unknown as Promise; +} + +export function fetchAppInfo(): Promise { + return instance.get('/settings/public') as unknown as Promise; +} diff --git a/apps/h5/src/env.d.ts b/apps/h5/src/env.d.ts new file mode 100644 index 0000000..51c682d --- /dev/null +++ b/apps/h5/src/env.d.ts @@ -0,0 +1,7 @@ +/// + +declare module '*.vue' { + import type { DefineComponent } from 'vue'; + const component: DefineComponent, Record, unknown>; + export default component; +} diff --git a/apps/h5/src/locales/en-US.json b/apps/h5/src/locales/en-US.json new file mode 100644 index 0000000..7fff09d --- /dev/null +++ b/apps/h5/src/locales/en-US.json @@ -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" } +} diff --git a/apps/h5/src/locales/index.ts b/apps/h5/src/locales/index.ts new file mode 100644 index 0000000..a33af70 --- /dev/null +++ b/apps/h5/src/locales/index.ts @@ -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'; +} diff --git a/apps/h5/src/locales/zh-CN.json b/apps/h5/src/locales/zh-CN.json new file mode 100644 index 0000000..1dae016 --- /dev/null +++ b/apps/h5/src/locales/zh-CN.json @@ -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" } +} diff --git a/apps/h5/src/main.ts b/apps/h5/src/main.ts new file mode 100644 index 0000000..8223169 --- /dev/null +++ b/apps/h5/src/main.ts @@ -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'); diff --git a/apps/h5/src/router.ts b/apps/h5/src/router.ts new file mode 100644 index 0000000..cbd5fae --- /dev/null +++ b/apps/h5/src/router.ts @@ -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: '/' }, + ], +}); diff --git a/apps/h5/src/styles.css b/apps/h5/src/styles.css new file mode 100644 index 0000000..7b289db --- /dev/null +++ b/apps/h5/src/styles.css @@ -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; +} diff --git a/apps/h5/src/views/Home.vue b/apps/h5/src/views/Home.vue new file mode 100644 index 0000000..c6fa161 --- /dev/null +++ b/apps/h5/src/views/Home.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/apps/h5/src/views/Trace.vue b/apps/h5/src/views/Trace.vue new file mode 100644 index 0000000..bc09d34 --- /dev/null +++ b/apps/h5/src/views/Trace.vue @@ -0,0 +1,487 @@ + + + + + diff --git a/apps/h5/tsconfig.json b/apps/h5/tsconfig.json new file mode 100644 index 0000000..461811e --- /dev/null +++ b/apps/h5/tsconfig.json @@ -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"] +} diff --git a/apps/h5/vite.config.ts b/apps/h5/vite.config.ts new file mode 100644 index 0000000..3d0acc3 --- /dev/null +++ b/apps/h5/vite.config.ts @@ -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 }, + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1017d6..c7c1589 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: