feat: 出库上链菜单按登记/上链状态动态切换标题与只读回填

This commit is contained in:
Nixevol
2026-07-10 15:16:34 +08:00
parent 18bdfd7e46
commit fccedb411b
5 changed files with 97 additions and 22 deletions
+1
View File
@@ -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-10):`TraceCodePanel` 行操作菜单「登记出库/上链」改名「出库上链」并按状态切换:未登记=「出库上链」(弹窗可编辑,按钮 保存登记 / 保存并触发上链);已登记未上链=「上链」(弹窗回填已登记出库时间/备注/实况图且只读,按钮仅「触发上链」,saveOutbound 跳过 updateSingle 只调 onchain,避免撞出库幂等);已登记已上链=「上链信息」(只读回填 + 追加区块链信息 n-descriptions:上链状态/dataHash/txHash/tokenId/合约/区块高度/上链时间/存证链接,底部仅「关闭」,隐藏所有保存按钮)。状态判定 `rowIsOutbound`(outTime 或 outImages)、`rowIsOnchain`(latestProof=ONCHAIN);只读态用 `outboundReadonly` 驱动表单与新增的 `MediaUpload :disabled`(禁上传/删除、保留预览)。i18n 新增 traceCode.triggerOnchainOnly/onchainInfo、blockchain.status/tokenId/contract。admin 构建通过。
- 天河链决策文档(2026-07-10):完整分析沉淀为 `aidocs/天河链对接分析与建议.md`——含当前实现状态、官方文档勘误(接口5路径/status语义/operateId限20字符/upload链接定位)、三个哈希与地址的概念澄清、11 接口逐一评估表、方案 A(纯存证,现状)vs 方案 B(存证+发行 NFT,已实测可行)对比与建议、优先级建议清单(计费确认为最高优先)、已定稿事项。等待用户对方案 A/B 与「轮换 UserKey」拍板。
- 天河链全接口分析与实测(2026-07-10,dev/refine):依据 APIFox 官方文档(11 接口,比语雀 md 准确)+ 测试环境全链路实测(publish 铸 NFT→接口9/5 确认→token/query→burn,测试数据已清理)。**勘误**:接口 5 真实路径是 `/api/v2/nfr/transaction/detail`(语雀 md 少了 `/nfr`);接口 9 `status` 官方语义「"0x0"=成功,否则失败」(已修正 `confirmTransaction` 判定:status 非 0x0 → `transactionStatus:'failed'`);publish `operateId` 限 20 字符。**结论**:确认接口 9/5 对 mint 等 token 交易完全正常(拿 blockHash/blockNum/tokenId),仅对纯存证 upload 交易结构性 500。完整分析与「存证+发行」升级方案(每物铸 NFT:productId=追溯码、feature=存证链接、mint 可确认拿区块信息)已记录到 `aidocs/代码审查问题清单.md`「天河链全接口适用性分析」,等待用户决策;user/update 轮换 UserKey 建议接入(同待拍板)。
- 天河链存证确认策略定稿(2026-07-10,dev/qa-polish):实测确认接口对**纯存证(upload)交易结构性不适用**——接口 9 与接口 5(全部 methodName)对 upload 交易一律返回 `500 "Index: 3, Size: 1"`(服务端按 token 交易结构解析导致数组越界),非偶发。官方文档对 upload 的定义即「获得链上存证哈希 + 数字商品唯一哈希 + 存证链接」,无确认环节。定稿:`TianheProvider.attest` 改 `confirmationRequired=false`(upload 成功=存证生效,直接 ONCHAIN),凭据 = txHash + digest + UDFS 存证链接(`udfs/Qm...` 是天河链上分布式文件存储的内容寻址地址,可公开访问、内容即存证 JSON;它不是钱包地址也不是浏览器交易页)。概念区分:钱包地址=注册返回的 0x…(链上身份)、txHash=存证交易哈希、udfs url=存证文件链上 URI;区块浏览器为 test.explorer.tianhecloud.com。存量 CONFIRMING 已修正 ONCHAIN;确认循环代码保留(未来 token 类交易可用)。
+5 -5
View File
@@ -4,7 +4,7 @@
<div v-for="(m, i) in items" :key="m.key" class="image-item previewable" @click="preview(i)">
<img v-if="isImage(m)" class="image-thumb" :src="mediaSrc(m)" :alt="m.name || m.key" loading="lazy" />
<div v-else class="file-thumb">{{ fileExt(m) }}</div>
<button class="remove" type="button" :title="t('common.action.delete')" @click.stop="remove(m.key)">×</button>
<button v-if="!disabled" class="remove" type="button" :title="t('common.action.delete')" @click.stop="remove(m.key)">×</button>
</div>
<div v-for="u in uploading" :key="u.id" class="image-item uploading">
<n-spin size="small" />
@@ -19,7 +19,7 @@
<div v-else class="file-list">
<div v-for="(m, i) in items" :key="m.key" class="file-row">
<span class="file-name" :title="m.name || m.key" @click="preview(i)">{{ m.name || m.key }}</span>
<n-button quaternary circle size="tiny" type="error" :title="t('common.action.delete')" @click="remove(m.key)">
<n-button v-if="!disabled" quaternary circle size="tiny" type="error" :title="t('common.action.delete')" @click="remove(m.key)">
×
</n-button>
</div>
@@ -56,8 +56,8 @@ interface MediaItem {
}
const props = withDefaults(
defineProps<{ modelValue: MediaItem[]; type?: 'image' | 'video' | 'file'; max?: number }>(),
{ type: 'image', max: 8 },
defineProps<{ modelValue: MediaItem[]; type?: 'image' | 'video' | 'file'; max?: number; disabled?: boolean }>(),
{ type: 'image', max: 8, disabled: false },
);
const emit = defineEmits<{ (e: 'update:modelValue', v: MediaItem[]): void }>();
const { t } = useI18n();
@@ -71,7 +71,7 @@ const accept = computed(() =>
props.type === 'image' ? 'image/*' : props.type === 'video' ? 'video/*' : 'application/pdf,image/*',
);
const allowMultiple = computed(() => props.max > 1);
const canUpload = computed(() => items.value.length + uploading.value.length < props.max);
const canUpload = computed(() => !props.disabled && items.value.length + uploading.value.length < props.max);
function mediaSrc(m: MediaItem) {
return resolveMediaUrl(m.url || m.key);
+79 -15
View File
@@ -144,28 +144,68 @@
</template>
</n-modal>
<n-modal v-model:show="outboundModal" preset="card" :title="t('pages.traceCode.registerOutbound')" style="width: 620px">
<n-modal v-model:show="outboundModal" preset="card" :title="outboundModalTitle" style="width: 620px">
<n-form :model="outboundForm" label-placement="top">
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi :label="t('pages.outbound.outTime')">
<n-date-picker v-model:formatted-value="outboundForm.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
<n-date-picker v-if="!outboundReadonly" v-model:formatted-value="outboundForm.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
<n-text v-else>{{ outboundForm.outTime || '-' }}</n-text>
</n-form-item-gi>
<n-form-item-gi :label="t('common.label.remark')">
<n-input v-model:value="outboundForm.remark" />
<n-input v-if="!outboundReadonly" v-model:value="outboundForm.remark" />
<n-text v-else>{{ outboundForm.remark || '-' }}</n-text>
</n-form-item-gi>
</n-grid>
<n-form-item :label="t('pages.outbound.outImage')">
<media-upload v-model="outImages" type="image" :max="8" />
<media-upload v-if="!outboundReadonly || outImages.length" v-model="outImages" type="image" :max="8" :disabled="outboundReadonly" />
<n-text v-else>-</n-text>
</n-form-item>
<n-alert type="info" :bordered="false" class="onchain-tip">
<template v-if="targetOnchain && targetProof">
<n-divider style="margin: 4px 0 12px">{{ t('pages.blockchain.title') }}</n-divider>
<n-descriptions :column="1" label-placement="left" size="small" bordered>
<n-descriptions-item :label="t('pages.blockchain.status')">
<n-tag size="small" :type="proofStatusType(targetProof)">{{ proofStatusText(targetProof) }}</n-tag>
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.dataHash" :label="t('pages.blockchain.dataHash')">
<span class="onchain-mono">{{ targetProof.dataHash }}</span>
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.txHash" :label="t('pages.blockchain.txHash')">
<span class="onchain-mono">{{ targetProof.txHash }}</span>
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.tokenId" :label="t('pages.blockchain.tokenId')">
<span class="onchain-mono">{{ targetProof.tokenId }}</span>
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.contractAddress" :label="t('pages.blockchain.contract')">
<span class="onchain-mono">{{ targetProof.contractAddress }}</span>
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.blockHeight" :label="t('pages.blockchain.blockHeight')">
{{ targetProof.blockHeight }}
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.onchainAt" :label="t('pages.blockchain.onchainAt')">
{{ fmt(targetProof.onchainAt) }}
</n-descriptions-item>
<n-descriptions-item v-if="targetProof.explorerUrl" :label="t('pages.blockchain.explorer')">
<a :href="targetProof.explorerUrl" target="_blank" rel="noopener" style="color: var(--brand)">{{ targetProof.explorerUrl }}</a>
</n-descriptions-item>
</n-descriptions>
</template>
<n-alert v-if="!targetOnchain" type="info" :bordered="false" class="onchain-tip">
{{ t('pages.outbound.onchainAutoTip') }}
</n-alert>
</n-form>
<template #footer>
<div style="text-align: right">
<n-button class="mr8" @click="outboundModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button class="mr8" :loading="outboundSaving" @click="saveOutbound(false)">{{ t('pages.outbound.saveRecord') }}</n-button>
<n-button type="primary" :loading="outboundTriggering" @click="saveOutbound(true)">{{ t('pages.outbound.saveAndTriggerOnchain') }}</n-button>
<n-button class="mr8" @click="outboundModal = false">
{{ targetOnchain ? t('common.action.close') : t('common.action.cancel') }}
</n-button>
<template v-if="!targetOnchain">
<n-button v-if="!targetOutbound" class="mr8" :loading="outboundSaving" @click="saveOutbound(false)">{{ t('pages.outbound.saveRecord') }}</n-button>
<n-button type="primary" :loading="outboundTriggering" @click="saveOutbound(true)">
{{ targetOutbound ? t('pages.blockchain.trigger') : t('pages.outbound.saveAndTriggerOnchain') }}
</n-button>
</template>
</div>
</template>
</n-modal>
@@ -281,6 +321,23 @@ const outboundForm = reactive<any>({
remark: '',
});
function rowIsOutbound(row: any) {
return Boolean(row?.outTime || getOutImages(row).length);
}
function rowIsOnchain(row: any) {
return Boolean(row?.latestProof);
}
function outboundMenuLabel(row: any) {
if (rowIsOnchain(row)) return t('pages.traceCode.onchainInfo');
if (rowIsOutbound(row)) return t('pages.traceCode.triggerOnchainOnly');
return t('pages.traceCode.registerOutbound');
}
const targetOutbound = computed(() => rowIsOutbound(outboundTarget.value));
const targetOnchain = computed(() => rowIsOnchain(outboundTarget.value));
const outboundReadonly = computed(() => targetOutbound.value || targetOnchain.value);
const targetProof = computed<any>(() => outboundTarget.value?.latestProof ?? null);
const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value));
const columns = computed<DataTableColumns<any>>(() => {
const base: DataTableColumns<any> = [
{ type: 'selection' },
@@ -619,7 +676,7 @@ function rowActionOptions(row: any): DropdownOption[] {
const options: DropdownOption[] = [
{ label: t('pages.traceCode.changeGroup'), key: 'changeGroup', children: rowGroupOptions.value },
{ label: t('pages.traceCode.changeBatch'), key: 'batch:open' },
{ label: t('pages.traceCode.registerOutbound'), key: 'outbound:open' },
{ label: outboundMenuLabel(row), key: 'outbound:open' },
];
if (canManualConfirm(row.latestAnyProof)) {
options.push({ label: t('pages.traceCode.reconfirmOnchain'), key: 'onchain:confirm' });
@@ -775,12 +832,14 @@ async function saveOutbound(triggerOnchain: boolean) {
outboundSaving.value = true;
}
try {
await outboundApi.updateSingle(String(outboundTarget.value.id), {
outTime: outboundForm.outTime ? dayjs(outboundForm.outTime).toISOString() : null,
outImageKey: outImages.value[0]?.key ?? null,
outImageKeys: outImages.value.map((item) => item.key).filter(Boolean),
remark: outboundForm.remark || null,
});
if (!outboundReadonly.value) {
await outboundApi.updateSingle(String(outboundTarget.value.id), {
outTime: outboundForm.outTime ? dayjs(outboundForm.outTime).toISOString() : null,
outImageKey: outImages.value[0]?.key ?? null,
outImageKeys: outImages.value.map((item) => item.key).filter(Boolean),
remark: outboundForm.remark || null,
});
}
if (triggerOnchain) {
await traceCodeApi.onchain(String(outboundTarget.value.id));
}
@@ -946,6 +1005,11 @@ onUnmounted(() => {
.onchain-tip {
margin-top: 4px;
}
.onchain-mono {
font-family: 'JetBrains Mono', Consolas, monospace;
font-size: 12px;
word-break: break-all;
}
@media (max-width: 720px) {
.toolbar-control,
.toolbar-control.wide,
+6 -1
View File
@@ -416,7 +416,9 @@
"reconfirmOnchain": "Reconfirm",
"confirmSubmitted": "Reconfirm task submitted",
"tableFilter": "Filter",
"registerOutbound": "Record Outbound / Chain",
"registerOutbound": "Outbound & On-chain",
"triggerOnchainOnly": "On-chain",
"onchainInfo": "On-chain Info",
"enableOne": "Enable",
"disableOne": "Disable",
"selected": "{n} selected",
@@ -468,9 +470,12 @@
},
"blockchain": {
"title": "Blockchain Attestation",
"status": "On-chain Status",
"dataHash": "Data Hash",
"txHash": "Tx Hash",
"blockHeight": "Block Height",
"tokenId": "Token ID",
"contract": "Contract Address",
"onchainAt": "On-chain Time",
"explorer": "Explorer",
"trigger": "Trigger On-chain",
+6 -1
View File
@@ -416,7 +416,9 @@
"reconfirmOnchain": "重新确认",
"confirmSubmitted": "已提交重新确认任务",
"tableFilter": "筛选",
"registerOutbound": "登记出库/上链",
"registerOutbound": "出库上链",
"triggerOnchainOnly": "上链",
"onchainInfo": "上链信息",
"enableOne": "启用",
"disableOne": "禁用",
"selected": "已选{n}项",
@@ -468,9 +470,12 @@
},
"blockchain": {
"title": "区块链存证",
"status": "上链状态",
"dataHash": "数据哈希",
"txHash": "交易哈希",
"blockHeight": "区块高度",
"tokenId": "数字商品ID",
"contract": "合约地址",
"onchainAt": "上链时间",
"explorer": "存证查询",
"trigger": "触发上链",