diff --git a/aidocs/project_context.md b/aidocs/project_context.md index 2d64af7..d8f3264 100644 --- a/aidocs/project_context.md +++ b/aidocs/project_context.md @@ -250,6 +250,7 @@ - 出库/上链防重复(2026-07-10):按「一物一码只能出库一次、已上链不可再上」补齐幂等校验。① 出库:`outbound.service.updateSingle`(单件)、`import-preview.processor`(导入预览)、`import.processor`(导入提交,防预览→提交竞态)三处均对 `code.outTime` 已存在拒绝「该追溯码已登记出库,不可重复出库」。② 上链:`attestation.service.trigger` 新增查重——存在 ONCHAIN/CONFIRMING/PENDING 的 proof 即拒绝(已上链→「不可重复上链」,处理中→「请稍候」);仅 FAILED 可通过独立 `retry` 接口重试(retry 原地更新既有 proof、不走 trigger,不受影响)。实测重复上链/重复出库均返回 400 拒绝。 - 天河链确认节奏调整(2026-07-10):`onchain.processor` 确认查询改为「提交完立即查 1 次 → 未到 10s → 再 30s」共 3 次自动尝试,之后停等手动重新确认(原为 30s/60s 两次)。用延迟数组 `AUTO_CONFIRM_DELAYS_MS=[0,10_000,30_000]`、`MAX_AUTO_CONFIRM_ATTEMPTS=数组长度`,第 attempt 次延迟取 `[attempt-1]`。实测:提交同秒即查到 mint 已进块(status 0x0、blockHeight、tokenId),直接 ONCHAIN。 - 天河链方案 B 落地(存证+发行+轮换,2026-07-10,dev/refine):按甲方决策「其余全做、媒体待定」实现。① 数据模型:`blockchain_proof` 加 `token_id`/`contract_address`(迁移 `20260710110000_add_proof_token_fields`);schema 补 `@db.VarChar` 注解消除历史 drift(operation_log.path 512 / outbound_import_session.file_key 512 / backup_record.file_path 1024)。② `TianheProvider` 新增 `publish`(接口2,operateId≤20,name≤42,author≤120,feature≤500)与 `updateUserKey`(接口7)。③ `BlockchainService.attestWithTianhe`:upload 存证→publish 铸 1 NFT(productId=追溯码、feature=存证链接)→ 主 txHash 切为 mint 交易、confirmationRequired=true 走接口9确认→ONCHAIN;合约地址存 `tianheContractAddress`、已发行最大 tokenId 存 `tianheMaxTokenId`(指定合约时作 baseTokenId,队列串行无争用);缺 product 时退化纯存证。`confirmTransaction` 确认成功回填 tokenId、更新 maxTokenId。④ `rotateTianheUserKey`:生成新随机 key→接口7链上改→持久化→接口8校验地址,`/settings/tianhe/identity/rotate` + 设置页「轮换密钥」(二次确认+回显强提示)。⑤ C 端:public-trace + Trace.vue 区块链卡增 tokenId/合约地址展示(i18n chain.tokenId/chain.contract)。⑥ 实测(测试环境):追溯码 412680781069 走通 upload→publish(合约 0xc96ae8a4... tokenId=0)→确认(区块高度 5820347)→ONCHAIN,C 端展示数字藏品编号 0/合约地址/区块高度;轮换 UserKey 成功(钱包地址不变),新 key 回填测试文档。验证:4 包构建 + 27 单测通过。**唯一待定:媒体上链层级 L1/L2/L3 待甲方确认「链上放什么」,当前维持 JSON 存证。** +- 追溯码客户端预览功能(2026-07-12,分支 `dev/tianhe-no-metadata-upload`):后台可预览 C 端页面且**零副作用**(不激活/不计数/不写查询日志)。① 令牌:`common/utils/preview-token.util.ts` 类 TOTP——HMAC-SHA256(jwt.secret, `preview:窗口号`) 取 16 hex,周期 10 分钟,校验接受当前+上一窗口(实际有效 10~20 分钟),无状态不落库,`timingSafeEqual` 防时序;外泄地址最长 2 窗口失效。② 后端:`GET /trace-codes/preview-token`(登录态)返回 `{token, clientBase, periodMs}`;`GET public/trace/:shortCode/preview?token&state`(@Public+限流)校验失败返回 `{status:'PREVIEW_EXPIRED'}`,成功走 `PublicTraceService.preview(state)`——与 trace() 共用 `buildArtworkPayload`(作品/时间线/证书/链上),但无任何 update/writeLog;`state=inactive` 时 antiCounterfeit 演示为首次扫码,`active` 用库中现值(0 时占位 2)。③ C 端:路由 `/trace/preview/:code` 复用 Trace.vue;`isPreview` 按路径判定,预览条(sticky 橙色)含「未激活/已激活」切换(切换重新请求),PREVIEW_EXPIRED 显示「预览链接已过期请回后台重开」。④ 后台:`traceCodeApi.previewToken`;TraceCodePanel 令牌缓存 8 分钟;**点追溯码=进预览页**(hover 提示「点击进入预览页(不激活、不计入查询次数)」;先同步 window.open('about:blank') 再异步填 URL 防弹窗拦截);**点链接列=弹确认框**告知直接访问会激活/计数,按钮[取消][访问预览页面][访问实际页面]。⑤ 预览 URL 仅点击时临时拼接不进行数据,导出仍只含真实短链。验证:5 项令牌单测 + API 实测(preview 前后 queryCount=0/INACTIVE 不变、查询日志 0 条、坏令牌拒绝、双状态正确)+ 全量构建 + 32 单测通过。 - 追溯码列表列重排+关联跳转(2026-07-12,分支 `dev/tianhe-no-metadata-upload`,两页共用 `TraceCodePanel` 同时生效):列顺序改为 追溯码→名称→档案编号→批次编号→分组→出库状态→上链状态→出库时间→激活状态→查询次数→激活时间→链接→创建时间→操作;名称/档案编号仅全局页显示(`fixedArtworkId` 时隐藏,档案内为同一作品)。关联:追溯码列渲染为 `` 点击开 C 端溯源页;名称/档案编号渲染为 `.cell-link` 点击 `goArtwork(id)` → `router.push({name:'artwork-detail'})`。`status` 列标题改用 `pages.traceCode.activationStatus`(激活状态),`firstActivatedAt` 标签改为「激活时间」,新增 `openTrace` i18n。追溯码列 `fixed:'left'`、操作列 `fixed:'right'`。浏览器双页实测通过。 - 出库/上链弹窗 UI 打磨(2026-07-10,分支 `dev/tianhe-no-metadata-upload`):① 出库时间加红星必填标识(`n-form-item-gi :required="!outboundReadonly"`);② 修复「关闭」按钮显示字面量——`common.action` 原缺 `close` 键,已补中英;③「区块链存证」详情用 `n-descriptions` 的 `label-style` 设 `whiteSpace:nowrap + verticalAlign:middle`,标题不再折行、垂直居中;④ 除「上链状态」外每项(数据哈希/交易哈希/tokenId/合约/区块高度/上链时间/存证查询)加复制按钮(`CopyOutline` + `navigator.clipboard`,`copyValue` 提示 `common.msg.copied/copyFailed`)。浏览器实测通过。 - 出库/上链一致性强化(2026-07-10,分支 `dev/tianhe-no-metadata-upload`):按甲方口径补三条不变量。① 确认中即已上链:前端 `rowIsOnchain` 由仅认 ONCHAIN 改为认 `ONCHAIN/CONFIRMING/PENDING`(这些状态菜单均显示「上链信息」、不给再触发;仅 FAILED 显示「上链」可重试),与后端 `attestation.trigger` 早有的防重复拦截对齐(天河 publish 一返回 mint 哈希即已广播上链、必进块,除非明确失败,故确认中不可重复上链);`targetProof` 回退用 `latestAnyProof` 使确认中也能展示上链信息。② 出库时间必填默认此刻:弹窗未出库时默认 `dayjs()` 此刻、前端空值拦截、后端 `outbound.updateSingle` 强制 `outTime` 非空。③ 上链必先出库:后端 `attestation.trigger` 增 `isOutbound(code)` 校验,未出库拒绝「请先登记出库再上链」,杜绝「已上链未登记」不一致(防直连 API 绕过)。注:这些为通用改进,暂随本分支;方案二合并时一并进 dev/refine,若方案二被否再单独回植。 diff --git a/apps/admin/src/api/index.ts b/apps/admin/src/api/index.ts index 579baaa..0b530d1 100644 --- a/apps/admin/src/api/index.ts +++ b/apps/admin/src/api/index.ts @@ -85,6 +85,7 @@ export const traceCodeApi = { qrBlob: (id: string) => download(`/trace-codes/${id}/qrcode`), onchain: (id: string) => post(`/trace-codes/${id}/onchain`, {}), confirmProof: (id: number) => post(`/blockchain-proofs/${id}/confirm`, {}), + previewToken: () => get<{ token: string; clientBase: string; periodMs: number }>('/trace-codes/preview-token'), // 分组 groups: (params?: object) => get('/trace-code-groups', params), createGroup: (data: { name: string; remark?: string }) => post('/trace-code-groups', data), @@ -138,6 +139,7 @@ export const settingsApi = { tianheVerify: (data: { userId: string; userKey: string }) => post<{ userId: string; address: string }>('/settings/tianhe/verify', data), tianheIdentity: () => get<{ userId: string; address: string; userKeyMasked: string }>('/settings/tianhe/identity'), + tianheRevealAppKey: () => post<{ appKeyMasked: string }>('/settings/tianhe/app-key/reveal', {}), tianheReveal: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity/reveal', {}), tianheRotate: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity/rotate', {}), }; diff --git a/apps/admin/src/components/TraceCodePanel.vue b/apps/admin/src/components/TraceCodePanel.vue index 6f58231..b0f1aeb 100644 --- a/apps/admin/src/components/TraceCodePanel.vue +++ b/apps/admin/src/components/TraceCodePanel.vue @@ -366,7 +366,7 @@ const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value const columns = computed>(() => { const cols: DataTableColumns = [ { type: 'selection' }, - // 追溯码:点击打开该码的 C 端溯源页 + // 追溯码:点击进入预览页(不激活、不计数) { title: () => t('pages.traceCode.shortCode'), key: 'shortCode', @@ -376,7 +376,7 @@ const columns = computed>(() => { render: (r) => h( 'a', - { href: r.url, target: '_blank', rel: 'noopener', class: 'cell-link', title: t('pages.traceCode.openTrace') }, + { class: 'cell-link', title: t('pages.traceCode.previewHint'), onClick: () => openPreview(r) }, r.shortCode, ), }, @@ -464,7 +464,7 @@ const columns = computed>(() => { { title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 100, align: 'center' }, // 激活时间 { title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, align: 'center', render: (r) => fmt(r.firstActivatedAt), ...sortProps('firstActivatedAt') }, - // 链接 + // 链接:拦截直跳,先告知「直接访问会激活/计数」,再让用户选预览或实际访问 { title: () => t('pages.traceCode.url'), key: 'url', @@ -473,7 +473,15 @@ const columns = computed>(() => { render: (r) => h( 'a', - { href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' }, + { + href: r.url, + style: 'color: var(--brand); text-decoration: none', + title: t('pages.traceCode.visitWarnTitle'), + onClick: (e: MouseEvent) => { + e.preventDefault(); + confirmVisitReal(r); + }, + }, [r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })], ), }, @@ -514,6 +522,68 @@ function goArtwork(id?: number) { router.push({ name: 'artwork-detail', params: { id: String(id) } }); } +// 预览令牌缓存:令牌自取用起至少 10 分钟有效(当前+上一窗口),缓存 8 分钟内复用,过期自动重取。 +// 预览 URL 仅在点击时临时拼接,不进入行数据,因此导出永远只含真实短链。 +let previewCache: { token: string; clientBase: string; fetchedAt: number } | null = null; +async function getPreviewInfo() { + if (!previewCache || Date.now() - previewCache.fetchedAt > 8 * 60_000) { + const res = await traceCodeApi.previewToken(); + previewCache = { token: res.token, clientBase: res.clientBase, fetchedAt: Date.now() }; + } + return previewCache; +} + +// 先同步开空白窗口再异步填充地址,避免 await 后 window.open 被浏览器拦截 +function openPreview(row: any) { + const win = window.open('about:blank', '_blank'); + getPreviewInfo() + .then((info) => { + const url = `${info.clientBase}/#/trace/preview/${encodeURIComponent(row.shortCode)}?token=${info.token}&state=inactive`; + if (win) win.location.href = url; + else window.open(url, '_blank'); + }) + .catch(() => { + win?.close(); + message.error(t('pages.traceCode.previewOpenFailed')); + }); +} + +// 点「链接」列:告知直接访问会激活/计数,提供预览与实际两个入口 +function confirmVisitReal(row: any) { + const d = dialog.warning({ + title: t('pages.traceCode.visitWarnTitle'), + content: t('pages.traceCode.visitWarnContent'), + action: () => + h('div', { style: 'display:flex;gap:8px;justify-content:flex-end' }, [ + h(NButton, { size: 'small', onClick: () => d.destroy() }, { default: () => t('common.action.cancel') }), + h( + NButton, + { + size: 'small', + type: 'primary', + onClick: () => { + d.destroy(); + openPreview(row); + }, + }, + { default: () => t('pages.traceCode.visitPreview') }, + ), + h( + NButton, + { + size: 'small', + type: 'warning', + onClick: () => { + d.destroy(); + window.open(row.url, '_blank'); + }, + }, + { default: () => t('pages.traceCode.visitReal') }, + ), + ]), + }); +} + type HeaderFilterField = 'batchId' | 'groupId' | 'status' | 'outboundStatus'; type HeaderFilterValue = string | number | null; type HeaderFilterOption = { label: string; value: string | number }; diff --git a/apps/admin/src/locales/en-US.json b/apps/admin/src/locales/en-US.json index 120ce69..869eea2 100644 --- a/apps/admin/src/locales/en-US.json +++ b/apps/admin/src/locales/en-US.json @@ -386,6 +386,12 @@ "firstActivatedAt": "Activated At", "activationStatus": "Activation", "openTrace": "Open trace page", + "previewHint": "Click to open preview (no activation, no query counting)", + "previewOpenFailed": "Failed to open preview, please retry", + "visitWarnTitle": "Visit Notice", + "visitWarnContent": "Visiting the real trace link will activate the code and increase its query count. To just check the page, use the preview page (no activation, no counting).", + "visitPreview": "Open Preview Page", + "visitReal": "Open Real Page", "exportBatch": "Export Batch", "exportCurrent": "Current filter", "bindArtwork": "Link Artwork File", @@ -510,6 +516,11 @@ "platformInfo": "Platform Settings", "logAndDisplay": "Log Settings", "backupPolicy": "Backup Policy", + "tabPlatform": "Platform", + "tabLogsBackup": "Logs & Backup", + "tabBlockchain": "Blockchain", + "tabStorage": "Storage", + "backupList": "Backup List", "appName": "Platform Name", "appIcon": "System Icon", "logRetentionDays": "Query Log Days", @@ -572,6 +583,10 @@ "tianheRevealConfirmContent": "The User Key is the sole credential for the platform custodial wallet. Revealing it will be recorded in the operation log. Make sure your environment is secure before continuing.", "tianheCopy": "Copy", "tianheCopied": "User Key copied", + "tianheCopyConfirmTitle": "Copy User Key", + "tianheCopyConfirmContent": "Copying writes the full User Key to the clipboard and will be recorded in the operation log. Make sure your environment is secure before continuing.", + "tianheAppKeyRevealTitle": "View App Key", + "tianheAppKeyRevealContent": "This action will be recorded in the operation log. Make sure your environment is secure before continuing. Only the masked form is shown; the full App Key is never displayed.", "tianheIdentityHint": "The User Key is the only credential to open the platform custodial wallet. TiChain does not store it and it cannot be recovered. Keep the User ID and User Key offline; after reinstalling or migrating, use Manual Entry to continue with the same on-chain identity.", "tianheRegisterDone": "On-chain identity registered", "tianheSaveKeyWarning": "Save these credentials offline immediately (losing them means you cannot attest with the same identity again): User ID: {userId}; User Key: {userKey}", diff --git a/apps/admin/src/locales/zh-CN.json b/apps/admin/src/locales/zh-CN.json index e435998..97aa1b1 100644 --- a/apps/admin/src/locales/zh-CN.json +++ b/apps/admin/src/locales/zh-CN.json @@ -386,6 +386,12 @@ "firstActivatedAt": "激活时间", "activationStatus": "激活状态", "openTrace": "打开溯源页", + "previewHint": "点击进入预览页(不激活、不计入查询次数)", + "previewOpenFailed": "预览页打开失败,请重试", + "visitWarnTitle": "访问提示", + "visitWarnContent": "直接访问追溯码链接会激活该码并增加查询次数。如仅需查看页面效果,请使用预览页面(不激活、不计入查询次数)。", + "visitPreview": "访问预览页面", + "visitReal": "访问实际页面", "exportBatch": "导出本批", "exportCurrent": "当前筛选", "bindArtwork": "关联作品档案", @@ -510,6 +516,11 @@ "platformInfo": "平台设置", "logAndDisplay": "日志设置", "backupPolicy": "备份策略", + "tabPlatform": "平台设置", + "tabLogsBackup": "日志与备份", + "tabBlockchain": "区块链存证", + "tabStorage": "存储配置", + "backupList": "备份列表", "appName": "平台名称", "appIcon": "系统图标", "logRetentionDays": "查询日志保留天数", @@ -572,6 +583,10 @@ "tianheRevealConfirmContent": "User Key 是平台托管钱包的唯一凭据,揭示操作将被记入操作日志。请确认当前环境安全后再继续。", "tianheCopy": "复制", "tianheCopied": "User Key 已复制", + "tianheCopyConfirmTitle": "复制 User Key", + "tianheCopyConfirmContent": "复制会将完整 User Key 写入剪贴板,该操作将记入操作日志。请确认当前环境安全后再继续。", + "tianheAppKeyRevealTitle": "查看 App Key", + "tianheAppKeyRevealContent": "该操作将记入操作日志,请确认当前环境安全后再继续。查看仅显示掩码形式,不会显示完整 App Key。", "tianheIdentityHint": "User Key 是打开平台托管钱包的唯一凭据,天河链不留存、无法找回。请务必离线保存 User ID 与 User Key;重装或迁移系统后可通过「手动录入」继续使用同一链上身份。", "tianheRegisterDone": "链上身份注册成功", "tianheSaveKeyWarning": "请立即离线保存以下凭据(丢失将无法继续以同一身份存证):User ID:{userId};User Key:{userKey}", diff --git a/apps/admin/src/views/Settings.vue b/apps/admin/src/views/Settings.vue index f97f27d..0d7ddaf 100644 --- a/apps/admin/src/views/Settings.vue +++ b/apps/admin/src/views/Settings.vue @@ -1,14 +1,16 @@