feat: 拆分上链与出库管理界面
This commit is contained in:
@@ -24,6 +24,17 @@ export function fetchTrace(shortCode: string): Promise<any> {
|
||||
return instance.get(`/public/trace/${shortCode}`) as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
export function fetchTraceOutboundImages(
|
||||
shortCode: string,
|
||||
page: number,
|
||||
pageSize = 20,
|
||||
preview?: { token?: string; state?: 'inactive' | 'active' },
|
||||
): Promise<any> {
|
||||
return instance.get(`/public/trace/${shortCode}/outbound-images`, {
|
||||
params: { page, pageSize, ...preview },
|
||||
}) as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
// 后台预览:凭时间令牌访问,零副作用(不激活/不计数/不写日志);state 控制未激活/已激活形态
|
||||
export function fetchTracePreview(shortCode: string, token: string, state: 'inactive' | 'active'): Promise<any> {
|
||||
return instance.get(`/public/trace/${shortCode}/preview`, { params: { token, state } }) as unknown as Promise<any>;
|
||||
|
||||
@@ -19,12 +19,34 @@
|
||||
"timeline": {
|
||||
"expandMedia": "View images ({n})",
|
||||
"collapse": "Collapse",
|
||||
"loadMoreMedia": "Load more images",
|
||||
"loadingMedia": "Loading…",
|
||||
"loadFailed": "Images could not be loaded. Please try again.",
|
||||
"remark": "Outbound note: ",
|
||||
"outboundTitle": "Outbound Record",
|
||||
"outboundDesc": "Outbound photos for the physical item of this trace code."
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "Archive No.",
|
||||
"status": "On-chain Status",
|
||||
"statuses": {
|
||||
"PENDING": "Pending",
|
||||
"SUBMITTING": "Submitting",
|
||||
"CONFIRMING": "Confirming",
|
||||
"ONCHAIN": "On-chain",
|
||||
"FAILED": "Failed",
|
||||
"UNKNOWN": "Verification Pending"
|
||||
},
|
||||
"statusDescriptions": {
|
||||
"PENDING": "The on-chain task has been created and is waiting to be processed.",
|
||||
"SUBMITTING": "The digital identity is being submitted to the blockchain.",
|
||||
"CONFIRMING": "The transaction has been submitted and is awaiting confirmation.",
|
||||
"ONCHAIN": "The digital identity has been recorded on-chain.",
|
||||
"FAILED": "This on-chain attempt did not succeed and is being handled by the platform.",
|
||||
"UNKNOWN": "The result cannot yet be confirmed and is being safely verified."
|
||||
},
|
||||
"hash": "Tx Hash",
|
||||
"failureReason": "Details: ",
|
||||
"contract": "Contract",
|
||||
"blockHeight": "Block Height",
|
||||
"onchainAt": "On-chain Time",
|
||||
|
||||
@@ -19,12 +19,34 @@
|
||||
"timeline": {
|
||||
"expandMedia": "查看图片({n})",
|
||||
"collapse": "收起图片",
|
||||
"loadMoreMedia": "加载更多图片",
|
||||
"loadingMedia": "正在加载…",
|
||||
"loadFailed": "图片加载失败,请稍后重试",
|
||||
"remark": "出库备注:",
|
||||
"outboundTitle": "本件出库记录",
|
||||
"outboundDesc": "该追溯码对应实物的出库实况记录。"
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "档案编号",
|
||||
"status": "上链状态",
|
||||
"statuses": {
|
||||
"PENDING": "等待上链",
|
||||
"SUBMITTING": "正在提交",
|
||||
"CONFIRMING": "链上确认中",
|
||||
"ONCHAIN": "已上链",
|
||||
"FAILED": "上链失败",
|
||||
"UNKNOWN": "结果待核实"
|
||||
},
|
||||
"statusDescriptions": {
|
||||
"PENDING": "上链任务已创建,正在等待处理。",
|
||||
"SUBMITTING": "数字身份正在提交至区块链,请稍后查看。",
|
||||
"CONFIRMING": "交易已提交,正在等待链上确认。",
|
||||
"ONCHAIN": "数字身份已完成链上存证。",
|
||||
"FAILED": "本次上链未成功,平台正在处理。",
|
||||
"UNKNOWN": "链上结果暂时无法确认,平台正在安全核实。"
|
||||
},
|
||||
"hash": "交易哈希",
|
||||
"failureReason": "说明:",
|
||||
"contract": "合约地址",
|
||||
"blockHeight": "区块高度",
|
||||
"onchainAt": "上链时间",
|
||||
|
||||
+252
-10
@@ -206,30 +206,43 @@
|
||||
</section>
|
||||
|
||||
<!-- 溯源时间轴 -->
|
||||
<section v-if="data.timeline?.length" class="card">
|
||||
<section v-if="timelineItems.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 v-for="(n, i) in timelineItems" :key="n.system || `${n.nodeType || 'node'}-${i}`" class="tl-item">
|
||||
<div class="tl-dot" />
|
||||
<div class="tl-body">
|
||||
<div class="tl-title">{{ nodeTitle(n) }}</div>
|
||||
<div class="tl-meta muted">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
|
||||
<div class="tl-meta muted">{{ [nodeOccurredAt(n), n.location].filter(Boolean).join(' · ') }}</div>
|
||||
<div v-if="nodeDesc(n)" class="tl-desc">{{ nodeDesc(n) }}</div>
|
||||
<div v-if="n.system === 'OUTBOUND_RECORD' && outboundRemark" class="tl-remark">
|
||||
<span class="muted">{{ t('timeline.remark') }}</span>
|
||||
{{ outboundRemark }}
|
||||
</div>
|
||||
<template v-if="n.media?.length">
|
||||
<button class="tl-toggle" @click="toggleNode(i)">
|
||||
<span class="tl-toggle-ico" :class="{ open: expanded.has(i) }">▸</span>
|
||||
{{ expanded.has(i) ? t('timeline.collapse') : t('timeline.expandMedia', { n: n.media.length }) }}
|
||||
{{ expanded.has(i) ? t('timeline.collapse') : t('timeline.expandMedia', { n: nodeMediaCount(n) }) }}
|
||||
</button>
|
||||
<div v-if="expanded.has(i)" class="tl-media">
|
||||
<div v-for="(m, j) in n.media" :key="j" class="tl-media-item" @click="openViewer(n.media, j)">
|
||||
<div class="tl-media-thumb">
|
||||
<video v-if="isVideo(m)" :src="mediaUrl(m)" muted playsinline preload="metadata" />
|
||||
<img v-else :src="mediaUrl(m)" loading="lazy" />
|
||||
<img v-else :src="mediaUrl(m)" :alt="m.name || nodeTitle(n)" loading="lazy" />
|
||||
<div v-if="isVideo(m)" class="tl-play">▶</div>
|
||||
</div>
|
||||
<div v-if="m.name" class="tl-cap text-ellipsis">{{ m.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
v-if="n.system === 'OUTBOUND_RECORD' && expanded.has(i) && canLoadMoreOutboundImages"
|
||||
type="button"
|
||||
class="tl-load-more"
|
||||
:disabled="outboundImagesLoading"
|
||||
@click="loadMoreOutboundImages"
|
||||
>
|
||||
{{ outboundImagesLoading ? t('timeline.loadingMedia') : t('timeline.loadMoreMedia') }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
@@ -295,7 +308,18 @@
|
||||
<span class="chain-v mono">{{ data.artwork.archiveNo }}</span>
|
||||
</div>
|
||||
<template v-if="data.blockchain">
|
||||
<div class="chain-row">
|
||||
<div class="chain-row chain-status-row">
|
||||
<span class="chain-k">{{ t('chain.status') }}</span>
|
||||
<span class="chain-status" :class="`is-${chainStatus.toLowerCase()}`">{{ t(`chain.statuses.${chainStatus}`) }}</span>
|
||||
</div>
|
||||
<p v-if="chainStatus !== 'ONCHAIN'" class="chain-status-note muted">
|
||||
{{ t(`chain.statusDescriptions.${chainStatus}`) }}
|
||||
</p>
|
||||
<p v-if="data.blockchain.failureReason" class="chain-failure-reason">
|
||||
<span class="muted">{{ t('chain.failureReason') }}</span>
|
||||
{{ data.blockchain.failureReason }}
|
||||
</p>
|
||||
<div v-if="data.blockchain.txHash" class="chain-row">
|
||||
<span class="chain-k">{{ t('chain.hash') }}</span>
|
||||
<span class="chain-v mono">{{ ellipsis(data.blockchain.txHash) }}</span>
|
||||
<button class="icon-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.blockchain.txHash)">
|
||||
@@ -315,11 +339,11 @@
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="chain-row">
|
||||
<div v-if="data.blockchain.blockHeight != null" class="chain-row">
|
||||
<span class="chain-k">{{ t('chain.blockHeight') }}</span>
|
||||
<span class="chain-v">{{ data.blockchain.blockHeight ?? '-' }}</span>
|
||||
<span class="chain-v">{{ data.blockchain.blockHeight }}</span>
|
||||
</div>
|
||||
<div class="chain-row">
|
||||
<div v-if="data.blockchain.onchainAt" class="chain-row">
|
||||
<span class="chain-k">{{ t('chain.onchainAt') }}</span>
|
||||
<span class="chain-v">{{ fmt(data.blockchain.onchainAt) }}</span>
|
||||
</div>
|
||||
@@ -380,7 +404,7 @@ import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchTrace, fetchTracePreview, fetchAppInfo } from '@/api';
|
||||
import { fetchTrace, fetchTracePreview, fetchTraceOutboundImages, fetchAppInfo } from '@/api';
|
||||
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
@@ -408,6 +432,92 @@ const antiModalOpen = ref(false);
|
||||
const certIndex = ref(0);
|
||||
const currentCert = computed(() => data.value?.certificates?.[certIndex.value] || null);
|
||||
|
||||
type ProofStatus = 'PENDING' | 'SUBMITTING' | 'CONFIRMING' | 'ONCHAIN' | 'FAILED' | 'UNKNOWN';
|
||||
|
||||
const PROOF_STATUSES = new Set<ProofStatus>([
|
||||
'PENDING',
|
||||
'SUBMITTING',
|
||||
'CONFIRMING',
|
||||
'ONCHAIN',
|
||||
'FAILED',
|
||||
'UNKNOWN',
|
||||
]);
|
||||
const OUTBOUND_IMAGE_PAGE_SIZE = 20;
|
||||
|
||||
const chainStatus = computed<ProofStatus>(() => {
|
||||
const status = data.value?.blockchain?.status as ProofStatus | undefined;
|
||||
return status && PROOF_STATUSES.has(status) ? status : 'ONCHAIN';
|
||||
});
|
||||
const outboundRemark = computed(() => String(data.value?.outbound?.remark || '').trim());
|
||||
const outboundImages = ref<any[]>([]);
|
||||
const outboundImagesTotal = ref(0);
|
||||
const outboundImagesPage = ref(1);
|
||||
const outboundImagesPageSize = ref(OUTBOUND_IMAGE_PAGE_SIZE);
|
||||
const outboundImagesHasMore = ref(false);
|
||||
const outboundImagesLoading = ref(false);
|
||||
const outboundVisibleCount = ref(OUTBOUND_IMAGE_PAGE_SIZE);
|
||||
const visibleOutboundImages = computed(() => outboundImages.value.slice(0, outboundVisibleCount.value));
|
||||
const canLoadMoreOutboundImages = computed(
|
||||
() => outboundVisibleCount.value < outboundImages.value.length || outboundImagesHasMore.value,
|
||||
);
|
||||
|
||||
function outboundPageFrom(value: any) {
|
||||
const images = value?.outbound?.images;
|
||||
if (Array.isArray(images)) {
|
||||
return {
|
||||
items: images,
|
||||
total: images.length,
|
||||
page: 1,
|
||||
pageSize: OUTBOUND_IMAGE_PAGE_SIZE,
|
||||
hasMore: false,
|
||||
};
|
||||
}
|
||||
if (images && Array.isArray(images.items)) return images;
|
||||
|
||||
const legacyNode = value?.timeline?.find((node: any) => node?.system === 'OUTBOUND_RECORD');
|
||||
const legacyItems = Array.isArray(legacyNode?.media) ? legacyNode.media : [];
|
||||
return {
|
||||
items: legacyItems,
|
||||
total: legacyItems.length,
|
||||
page: 1,
|
||||
pageSize: OUTBOUND_IMAGE_PAGE_SIZE,
|
||||
hasMore: false,
|
||||
};
|
||||
}
|
||||
|
||||
function resetOutboundImages(value: any) {
|
||||
const page = outboundPageFrom(value);
|
||||
outboundImages.value = page.items || [];
|
||||
outboundImagesTotal.value = Number(page.total) || outboundImages.value.length;
|
||||
outboundImagesPage.value = Number(page.page) || 1;
|
||||
outboundImagesPageSize.value = Number(page.pageSize) || OUTBOUND_IMAGE_PAGE_SIZE;
|
||||
outboundImagesHasMore.value = Boolean(page.hasMore);
|
||||
outboundVisibleCount.value = Math.min(OUTBOUND_IMAGE_PAGE_SIZE, outboundImages.value.length);
|
||||
outboundImagesLoading.value = false;
|
||||
}
|
||||
|
||||
const timelineItems = computed<any[]>(() => {
|
||||
const source = Array.isArray(data.value?.timeline) ? data.value.timeline : [];
|
||||
const regularNodes = source.filter((node: any) => node?.system !== 'OUTBOUND_RECORD');
|
||||
const legacyOutbound = source.find((node: any) => node?.system === 'OUTBOUND_RECORD');
|
||||
const outbound = data.value?.outbound;
|
||||
|
||||
if (!outbound && !legacyOutbound) return regularNodes;
|
||||
return [
|
||||
...regularNodes,
|
||||
{
|
||||
...(legacyOutbound || {}),
|
||||
nodeType: 'OUTBOUND',
|
||||
system: 'OUTBOUND_RECORD',
|
||||
title: null,
|
||||
occurredAt: outbound?.outTime ?? legacyOutbound?.occurredAt ?? null,
|
||||
location: legacyOutbound?.location ?? null,
|
||||
description: null,
|
||||
media: visibleOutboundImages.value,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
// 后台预览模式:/trace/preview/:code?token=xxx,零副作用(不激活/不计数),可切换未激活/已激活形态
|
||||
const isPreview = computed(() => route.path.startsWith('/trace/preview/'));
|
||||
const previewState = ref<'inactive' | 'active'>('inactive');
|
||||
@@ -427,6 +537,69 @@ function toggleNode(i: number) {
|
||||
expanded.value = s;
|
||||
}
|
||||
|
||||
function nodeMediaCount(n: { system?: string | null; media?: unknown[] }): number {
|
||||
if (n.system === 'OUTBOUND_RECORD') return outboundImagesTotal.value;
|
||||
return n.media?.length || 0;
|
||||
}
|
||||
|
||||
function nodeOccurredAt(n: { system?: string | null; occurredAt?: string | null }): string {
|
||||
return n.system === 'OUTBOUND_RECORD' ? fmt(n.occurredAt) : fmtDate(n.occurredAt);
|
||||
}
|
||||
|
||||
async function loadMoreOutboundImages() {
|
||||
if (outboundImagesLoading.value) return;
|
||||
|
||||
if (outboundVisibleCount.value < outboundImages.value.length) {
|
||||
outboundVisibleCount.value = Math.min(
|
||||
outboundVisibleCount.value + outboundImagesPageSize.value,
|
||||
outboundImages.value.length,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!outboundImagesHasMore.value) return;
|
||||
|
||||
const code = String(route.params.code || '');
|
||||
if (!code) return;
|
||||
outboundImagesLoading.value = true;
|
||||
try {
|
||||
const nextPage = outboundImagesPage.value + 1;
|
||||
const response = await fetchTraceOutboundImages(
|
||||
code,
|
||||
nextPage,
|
||||
outboundImagesPageSize.value,
|
||||
isPreview.value
|
||||
? { token: String(route.query.token || ''), state: previewState.value }
|
||||
: undefined,
|
||||
);
|
||||
const page = Array.isArray(response?.outbound?.images?.items)
|
||||
? response.outbound.images
|
||||
: Array.isArray(response?.images?.items)
|
||||
? response.images
|
||||
: response;
|
||||
const items = Array.isArray(page?.items) ? page.items : [];
|
||||
const known = new Set(
|
||||
outboundImages.value.map((item) => String(item?.id ?? item?.key ?? item?.url ?? '')),
|
||||
);
|
||||
for (const item of items) {
|
||||
const key = String(item?.id ?? item?.key ?? item?.url ?? '');
|
||||
if (!key || !known.has(key)) {
|
||||
outboundImages.value.push(item);
|
||||
if (key) known.add(key);
|
||||
}
|
||||
}
|
||||
outboundImagesPage.value = Number(page?.page) || nextPage;
|
||||
outboundImagesPageSize.value = Number(page?.pageSize) || outboundImagesPageSize.value;
|
||||
outboundImagesTotal.value = Number(page?.total) || outboundImages.value.length;
|
||||
outboundImagesHasMore.value = items.length > 0 && Boolean(page?.hasMore);
|
||||
outboundVisibleCount.value = outboundImages.value.length;
|
||||
} catch {
|
||||
toast.value = t('timeline.loadFailed');
|
||||
setTimeout(() => (toast.value = ''), 1800);
|
||||
} finally {
|
||||
outboundImagesLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const stateKey = computed(() => {
|
||||
const s = data.value?.status;
|
||||
if (s === 'DISABLED') return 'disabled';
|
||||
@@ -739,6 +912,7 @@ watch(
|
||||
() => data.value,
|
||||
(value) => {
|
||||
certIndex.value = 0;
|
||||
resetOutboundImages(value);
|
||||
antiModalOpen.value = value?.status === 'OK' && value?.antiCounterfeit?.firstQuery === true;
|
||||
},
|
||||
);
|
||||
@@ -1207,6 +1381,13 @@ watch(
|
||||
font-size: 13px;
|
||||
color: var(--trace-desc);
|
||||
}
|
||||
.tl-remark {
|
||||
margin-top: 5px;
|
||||
font-size: 13px;
|
||||
color: var(--trace-desc);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.tl-toggle {
|
||||
margin-top: 8px;
|
||||
display: inline-flex;
|
||||
@@ -1271,6 +1452,21 @@ watch(
|
||||
margin-top: 4px;
|
||||
text-align: center;
|
||||
}
|
||||
.tl-load-more {
|
||||
min-width: 124px;
|
||||
margin-top: 8px;
|
||||
padding: 7px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--card-bg);
|
||||
color: var(--brand-2);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tl-load-more:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.65;
|
||||
}
|
||||
.cert-carousel {
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -1389,6 +1585,52 @@ watch(
|
||||
flex: 1;
|
||||
word-break: break-all;
|
||||
}
|
||||
.chain-status-row {
|
||||
min-height: 45px;
|
||||
}
|
||||
.chain-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.chain-status.is-pending {
|
||||
color: #596579;
|
||||
background: rgba(100, 116, 139, 0.14);
|
||||
}
|
||||
.chain-status.is-submitting {
|
||||
color: #2563a6;
|
||||
background: rgba(37, 99, 166, 0.13);
|
||||
}
|
||||
.chain-status.is-confirming {
|
||||
color: #a15c00;
|
||||
background: rgba(217, 119, 6, 0.14);
|
||||
}
|
||||
.chain-status.is-onchain {
|
||||
color: #087d5a;
|
||||
background: rgba(5, 150, 105, 0.14);
|
||||
}
|
||||
.chain-status.is-failed {
|
||||
color: #b42318;
|
||||
background: rgba(180, 35, 24, 0.12);
|
||||
}
|
||||
.chain-status.is-unknown {
|
||||
color: #9a4a00;
|
||||
background: rgba(194, 83, 0, 0.13);
|
||||
}
|
||||
.chain-status-note,
|
||||
.chain-failure-reason {
|
||||
margin: 8px 0 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.chain-failure-reason {
|
||||
color: var(--trace-desc);
|
||||
word-break: break-word;
|
||||
}
|
||||
.mono {
|
||||
font-family: 'SFMono-Regular', Consolas, monospace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user