feat: 用独立页面展示存证详情并按天河链版式绘制证书
This commit is contained in:
+23
-1
@@ -50,6 +50,28 @@ export interface TraceCertificateRecord {
|
||||
txHash: string;
|
||||
author: string;
|
||||
createdAt: string | null;
|
||||
environment?: 'test' | 'production';
|
||||
}
|
||||
export interface ChainDetailLog {
|
||||
address: string;
|
||||
name: string;
|
||||
data: string;
|
||||
topics: string[];
|
||||
}
|
||||
export interface ChainDetail {
|
||||
gasUsed: string;
|
||||
fromAddress: string;
|
||||
toAddress: string;
|
||||
timeStamp: string | null;
|
||||
blockHeight: string | null;
|
||||
method: string;
|
||||
methodId: string;
|
||||
inputs: Array<{ name: string; type: string; data: string }>;
|
||||
logs: ChainDetailLog[];
|
||||
action: { fromAddress: string; toAddress: string; contractAddress: string; tokenId: string } | null;
|
||||
}
|
||||
export function fetchChainDetail(shortCode: string): Promise<{ complete: boolean; detail: ChainDetail | null }> {
|
||||
return instance.post(`/public/trace/${encodeURIComponent(shortCode)}/chain-detail`, {}, { timeout: 30_000 }) as unknown as Promise<{ complete: boolean; detail: ChainDetail | null }>;
|
||||
}
|
||||
export interface TraceCertificateResult {
|
||||
status: 'NONE' | 'PENDING' | 'SUBMITTING' | 'CHECKING' | 'WAITING' | 'READY' | 'UNKNOWN' | 'FAILED';
|
||||
@@ -57,7 +79,7 @@ export interface TraceCertificateResult {
|
||||
certificate: TraceCertificateRecord | null;
|
||||
}
|
||||
export function requestTraceCertificate(shortCode: string): Promise<TraceCertificateResult> {
|
||||
return instance.post(`/public/trace/${encodeURIComponent(shortCode)}/certificate`, {}) as unknown as Promise<TraceCertificateResult>;
|
||||
return instance.post(`/public/trace/${encodeURIComponent(shortCode)}/certificate`, {}, { timeout: 90_000 }) as unknown as Promise<TraceCertificateResult>;
|
||||
}
|
||||
export function fetchTraceCertificate(shortCode: string): Promise<TraceCertificateResult> {
|
||||
return instance.get(`/public/trace/${encodeURIComponent(shortCode)}/certificate`) as unknown as Promise<TraceCertificateResult>;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 548 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -58,8 +58,8 @@
|
||||
<span class="chain-v">{{ formatTime(blockchain.onchainAt) }}</span>
|
||||
</div>
|
||||
<div class="chain-actions">
|
||||
<button v-if="blockchain.txHash" class="chain-link" @click="openProof">{{ t('chain.explorer') }}</button>
|
||||
<button ref="certificateButton" v-if="canViewCertificate" class="chain-link certificate-link" :disabled="opening || preview" @click="viewCertificate">
|
||||
<button v-if="blockchain.txHash" class="chain-link" type="button" @click="openProof">{{ t('chain.explorer') }}</button>
|
||||
<button v-if="canViewCertificate" class="chain-link certificate-link" type="button" :disabled="preview" @click="openCertificate">
|
||||
{{ t('chain.certificateView') }}
|
||||
</button>
|
||||
</div>
|
||||
@@ -67,56 +67,12 @@
|
||||
</template>
|
||||
<div v-else class="chain-empty muted">{{ t('chain.notOnchain') }}</div>
|
||||
</section>
|
||||
<Teleport to="body">
|
||||
<dialog ref="proofDialog" class="tx-dialog" aria-labelledby="proof-dialog-title" @cancel.prevent="closeProof">
|
||||
<h3 id="proof-dialog-title" class="sr-only">{{ t('chain.proofTitle') }}</h3>
|
||||
<trace-tx-detail
|
||||
:tx-hash="blockchain?.txHash"
|
||||
:succeeded="status === 'ONCHAIN'"
|
||||
:status-text="t(`chain.statuses.${status}`)"
|
||||
:block-height="blockchain?.blockHeight"
|
||||
:contract-address="blockchain?.contractAddress"
|
||||
:onchain-at="blockchain?.onchainAt"
|
||||
:token-id="blockchain?.tokenId"
|
||||
:author="blockchain?.author"
|
||||
:product-id="blockchain?.productId || shortCode"
|
||||
:feature="blockchain?.feature"
|
||||
:mint-to="blockchain?.mintTo"
|
||||
@copy="(value) => $emit('copy', value)"
|
||||
@close="closeProof"
|
||||
/>
|
||||
</dialog>
|
||||
<dialog ref="certificateDialog" class="certificate-dialog" aria-labelledby="certificate-dialog-title" @cancel.prevent="closeCertificateDialog">
|
||||
<button class="certificate-close" :aria-label="t('viewer.close')" @click="closeCertificateDialog">×</button>
|
||||
<h3 id="certificate-dialog-title">{{ t('chain.certificateView') }}</h3>
|
||||
<div v-if="!certificateError && !certificateRecord" class="certificate-spinner" aria-hidden="true" />
|
||||
<div class="sheet-body" aria-live="polite">
|
||||
<p v-if="certificateError" role="alert">{{ certificateError }}</p>
|
||||
<div v-else-if="certificateRecord" class="certificate-sheet">
|
||||
<div v-for="row in certificateRows" :key="row.label" class="sheet-row">
|
||||
<span>{{ row.label }}</span>
|
||||
<strong>{{ row.value }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<ol v-else class="certificate-steps">
|
||||
<li v-for="(key, index) in certificateSteps" :key="key" :class="{ current: certificatePhase === index, done: certificatePhase > index }">
|
||||
<span aria-hidden="true">{{ certificatePhase > index ? '✓' : index + 1 }}</span>{{ t(key) }}
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div v-if="certificateRecord || (certificateError && retryable)" class="dialog-actions">
|
||||
<button v-if="certificateRecord" class="certificate-retry" type="button" @click="downloadCertificate">{{ t('chain.certificateDownload') }}</button>
|
||||
<button v-else class="certificate-retry" type="button" @click="viewCertificate">{{ t('chain.certificateCheckAgain') }}</button>
|
||||
</div>
|
||||
</dialog>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onUnmounted, ref, watch } from 'vue';
|
||||
import { fetchTraceCertificate, requestTraceCertificate, type TraceCertificateRecord, type TraceCertificateResult } from '@/api';
|
||||
import { downloadCertificatePng } from '@/utils/certificateImage';
|
||||
import TraceTxDetail from './TraceTxDetail.vue';
|
||||
import { computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { ChainDetail } from '@/api';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@@ -147,116 +103,35 @@ const props = defineProps<{
|
||||
productId?: string | null;
|
||||
feature?: string | null;
|
||||
mintTo?: string | null;
|
||||
chainDetail?: ChainDetail | null;
|
||||
failureReason?: string | null;
|
||||
chainName?: string | null;
|
||||
} | null;
|
||||
}>();
|
||||
defineEmits<{ (event: 'copy', value: string): void }>();
|
||||
const { t } = useI18n();
|
||||
const opening = ref(false);
|
||||
const certificateError = ref('');
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const canViewCertificate = computed(() => props.blockchain?.status === 'ONCHAIN' && Boolean(props.blockchain.txHash) && props.blockchain.chainName === '天河链');
|
||||
const proofDialog = ref<HTMLDialogElement>();
|
||||
const certificateDialog = ref<HTMLDialogElement>();
|
||||
const certificateButton = ref<HTMLButtonElement>();
|
||||
const certificatePhase = ref(0);
|
||||
const certificateRecord = ref<TraceCertificateRecord | null>(null);
|
||||
const retryable = ref(true);
|
||||
const certificateSteps = ['chain.certificateRetrieving', 'chain.certificateAcquiring', 'chain.certificatePreparing'];
|
||||
let certificateTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let certificateRun = 0;
|
||||
let certificatePolls = 0;
|
||||
|
||||
function stopCertificateWait() {
|
||||
certificateRun++;
|
||||
if (certificateTimer) clearTimeout(certificateTimer);
|
||||
opening.value = false;
|
||||
}
|
||||
function closeCertificateDialog() {
|
||||
stopCertificateWait();
|
||||
certificateRecord.value = null;
|
||||
certificateDialog.value?.close();
|
||||
certificateButton.value?.focus();
|
||||
}
|
||||
function openProof() {
|
||||
proofDialog.value?.showModal();
|
||||
const key = `artveris.trace.proof.${props.preview ? 'preview.' : ''}${props.shortCode}`;
|
||||
sessionStorage.setItem(key, JSON.stringify(props.blockchain || null));
|
||||
router.push({
|
||||
name: props.preview ? 'trace-preview-proof' : 'trace-proof',
|
||||
params: { code: props.shortCode },
|
||||
query: props.preview ? { token: route.query.token, state: route.query.state } : {},
|
||||
});
|
||||
}
|
||||
function closeProof() {
|
||||
proofDialog.value?.close();
|
||||
function openCertificate() {
|
||||
if (props.preview || !canViewCertificate.value) return;
|
||||
router.push({ name: 'trace-certificate', params: { code: props.shortCode } });
|
||||
}
|
||||
function failCertificate(messageKey: string, canRetry = true) {
|
||||
certificateError.value = t(messageKey);
|
||||
retryable.value = canRetry;
|
||||
opening.value = false;
|
||||
}
|
||||
function showCertificateResult(result: TraceCertificateResult, run: number, code: string) {
|
||||
if (run !== certificateRun) return;
|
||||
if (result.status === 'READY' && result.certificate) {
|
||||
certificatePhase.value = 2;
|
||||
certificateRecord.value = result.certificate;
|
||||
opening.value = false;
|
||||
return;
|
||||
}
|
||||
if (result.status === 'FAILED') return failCertificate('chain.certificateFailed', false);
|
||||
if (result.status === 'UNKNOWN') return failCertificate('chain.certificateDelayed');
|
||||
if (result.status === 'NONE') return failCertificate('chain.certificateUnavailable');
|
||||
certificatePhase.value = 1;
|
||||
if (++certificatePolls >= 60) return failCertificate('chain.certificateDelayed');
|
||||
certificateTimer = setTimeout(async () => {
|
||||
try { showCertificateResult(await fetchTraceCertificate(code), run, code); }
|
||||
catch { if (run === certificateRun) failCertificate('chain.certificateUnavailable'); }
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
async function viewCertificate() {
|
||||
if (opening.value || props.preview || !canViewCertificate.value) return;
|
||||
stopCertificateWait();
|
||||
const run = certificateRun;
|
||||
const code = props.shortCode;
|
||||
certificateError.value = '';
|
||||
certificatePhase.value = 0;
|
||||
certificatePolls = 0;
|
||||
if (!certificateDialog.value?.open) certificateDialog.value?.showModal();
|
||||
opening.value = true;
|
||||
try {
|
||||
const cached = await fetchTraceCertificate(code);
|
||||
if (run !== certificateRun) return;
|
||||
certificatePhase.value = 1;
|
||||
const result = cached.status === 'NONE' || cached.status === 'UNKNOWN'
|
||||
? await requestTraceCertificate(code) : cached;
|
||||
showCertificateResult(result, run, code);
|
||||
} catch {
|
||||
if (run === certificateRun) failCertificate('chain.certificateRequestFailed');
|
||||
}
|
||||
}
|
||||
watch(() => props.shortCode, closeCertificateDialog);
|
||||
onUnmounted(stopCertificateWait);
|
||||
|
||||
const status = computed<ProofStatus>(() => {
|
||||
const value = props.blockchain?.status as ProofStatus | undefined;
|
||||
return value && STATUSES.has(value) ? value : 'ONCHAIN';
|
||||
});
|
||||
const certificateRows = computed(() => {
|
||||
const record = certificateRecord.value;
|
||||
if (!record) return [];
|
||||
return [
|
||||
{ label: t('chain.certificateContent'), value: record.text },
|
||||
{ label: t('chain.certificateDigest'), value: record.digest },
|
||||
{ label: t('chain.hash'), value: record.txHash },
|
||||
{ label: t('chain.certificateAuthor'), value: record.author },
|
||||
{ label: t('chain.certificateTime'), value: formatTime(record.createdAt) },
|
||||
];
|
||||
});
|
||||
function downloadCertificate() {
|
||||
const record = certificateRecord.value;
|
||||
if (!record) return;
|
||||
downloadCertificatePng({
|
||||
title: t('chain.certificateView'),
|
||||
filename: `certificate-${props.shortCode}.png`,
|
||||
rows: certificateRows.value,
|
||||
});
|
||||
}
|
||||
|
||||
function ellipsis(value?: string | null) {
|
||||
if (!value) return '-';
|
||||
return value.length > 16 ? `${value.slice(0, 8)}…${value.slice(-6)}` : value;
|
||||
@@ -369,28 +244,6 @@ function formatTime(value?: string | null) {
|
||||
padding: 8px 0;
|
||||
}
|
||||
.chain-actions { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
|
||||
.certificate-link { margin-left: auto; padding: 0; border: 0; background: none; cursor: pointer; font-family: inherit; }
|
||||
.certificate-link { margin-left: auto; }
|
||||
.certificate-link:disabled { opacity: .55; cursor: default; }
|
||||
.tx-dialog { width: min(960px, calc(100vw - 16px)); max-height: calc(100vh - 16px); padding: 0; border: 0; background: transparent; box-shadow: none; overflow: auto; }
|
||||
.tx-dialog::backdrop { background: #0007; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
|
||||
.certificate-dialog { width: min(420px, calc(100vw - 40px)); max-height: min(640px, calc(100vh - 48px)); box-sizing: border-box; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--card-bg); color: var(--text); box-shadow: 0 16px 60px #0003; }
|
||||
.certificate-dialog[open] { display: flex; flex-direction: column; }
|
||||
.sheet-body { overflow: auto; min-height: 0; }
|
||||
.sheet-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--trace-divider); font-size: 13px; }
|
||||
.sheet-row span { color: var(--muted); }
|
||||
.sheet-row strong { font-weight: 500; word-break: break-all; white-space: pre-wrap; }
|
||||
.dialog-actions { padding-top: 16px; }
|
||||
.certificate-dialog::backdrop { background: #0007; }
|
||||
.certificate-dialog h3 { margin: 0 0 22px; font-size: 18px; }
|
||||
.certificate-close { position: absolute; top: 9px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }
|
||||
.certificate-spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; margin: 0 auto 24px; animation: certificate-spin .8s linear infinite; }
|
||||
.certificate-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; font-size: 14px; }
|
||||
.certificate-steps li { display: flex; gap: 12px; align-items: center; color: var(--muted); }
|
||||
.certificate-steps li span { border: 1px solid var(--border); border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; flex-shrink: 0; }
|
||||
.certificate-steps li.current { color: var(--text); font-weight: 600; }
|
||||
.certificate-steps li.done { color: var(--brand); }
|
||||
.certificate-retry { border: 0; background: var(--brand); color: white; padding: 9px 18px; border-radius: 6px; cursor: pointer; font: inherit; }
|
||||
@keyframes certificate-spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .certificate-spinner { animation: none; } }
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<template>
|
||||
<div ref="sheet" class="certificate-prove">
|
||||
<div class="cert-logo">
|
||||
<img :src="logoUrl" alt="" />
|
||||
</div>
|
||||
<h1 class="cert-title">区块链存证证书</h1>
|
||||
<p class="cert-notice"> 本证书由天河链签发,证明该文件由作者在存证时间操作上链,且链上内容未经篡改 </p>
|
||||
<div class="row-mod">
|
||||
<p class="row-title">天河链-区块链ID:</p>
|
||||
<p class="row-value"> {{ record.txHash || '未知' }} </p>
|
||||
</div>
|
||||
<div class="row-mod">
|
||||
<p class="row-title">电子证据SHA256值:</p>
|
||||
<p class="row-value"> {{ record.digest || '未知' }} </p>
|
||||
</div>
|
||||
<div class="cert-divider el-divider el-divider--horizontal"></div>
|
||||
<div class="prove-area prove-area-2">
|
||||
<div class="form-mod">
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">作者:</div>
|
||||
<div class="form-item-value"> {{ record.author }} </div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">存证时间:</div>
|
||||
<div class="form-item-value"> {{ created }} </div>
|
||||
</div>
|
||||
<div v-if="record.text" class="form-item">
|
||||
<div class="form-item-label">文本内容:</div>
|
||||
<div class="form-item-value"> {{ record.text }} </div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="check-img">
|
||||
<img :src="stampUrl" alt="" height="100%" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="prove-area prove-area-3">
|
||||
<div class="prove-notice">
|
||||
说明:<br /><br />
|
||||
1、本文件通过天河链网络进行存证,链上数据不可删除、不可篡改。<br /><br />
|
||||
2、本文件根据SHA256加密算法加密。
|
||||
</div>
|
||||
<div class="wx-link">
|
||||
<div id="qrcode">
|
||||
<img v-if="qrUrl" :src="qrUrl" alt="" width="88" height="88" />
|
||||
</div>
|
||||
<img class="qrcode-logo" :src="qrLogoUrl" alt="" width="16" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="prove-wrapper"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import dayjs from 'dayjs';
|
||||
import QRCode from 'qrcode';
|
||||
import type { TraceCertificateRecord } from '@/api';
|
||||
import logoUrl from '@/assets/certificate/logo.png';
|
||||
import stampUrl from '@/assets/certificate/check.png';
|
||||
import qrLogoUrl from '@/assets/certificate/qr-logo.png';
|
||||
import './certificate-prove.css';
|
||||
|
||||
const props = defineProps<{ record: TraceCertificateRecord }>();
|
||||
const sheet = ref<HTMLElement>();
|
||||
const qrUrl = ref('');
|
||||
const created = computed(() => {
|
||||
if (!props.record.createdAt) return '';
|
||||
const parsed = dayjs(props.record.createdAt);
|
||||
return parsed.isValid() ? parsed.format('YYYY-MM-DD HH:mm:ss') : props.record.createdAt;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const host = props.record.environment === 'test' ? 'https://test.explorer.tianhecloud.com' : 'https://explorer.tianhecloud.com';
|
||||
qrUrl.value = await QRCode.toDataURL(`${host}/#/tiChain/transDetail?hash=${props.record.txHash}`, {
|
||||
width: 88,
|
||||
margin: 0,
|
||||
errorCorrectionLevel: 'H',
|
||||
color: { dark: '#000000', light: '#ffffff' },
|
||||
});
|
||||
});
|
||||
|
||||
async function download() {
|
||||
const target = sheet.value;
|
||||
if (!target) return;
|
||||
const host = document.createElement('div');
|
||||
host.style.cssText = 'position:fixed;left:-10000px;top:0;width:508px;height:720px;';
|
||||
const clone = target.cloneNode(true) as HTMLElement;
|
||||
host.appendChild(clone);
|
||||
document.body.appendChild(host);
|
||||
try {
|
||||
const { default: html2canvas } = await import('html2canvas');
|
||||
const canvas = await html2canvas(clone, { scale: 3, backgroundColor: '#e0e0e0', useCORS: true });
|
||||
const link = document.createElement('a');
|
||||
link.href = canvas.toDataURL('image/png');
|
||||
link.download = `${Date.now()}.png`;
|
||||
link.click();
|
||||
} finally {
|
||||
host.remove();
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ download });
|
||||
</script>
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="tx-page">
|
||||
<div class="tx-top">
|
||||
<h3>{{ t('chain.txTitle') }}</h3>
|
||||
<h3 v-if="showHeading">{{ t('chain.txTitle') }}</h3>
|
||||
<div class="tx-hashbox">{{ txHash || '-' }}</div>
|
||||
</div>
|
||||
<section class="tx-card">
|
||||
@@ -27,11 +27,24 @@
|
||||
<em v-else class="tx-pending">{{ statusText }}</em>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="blockHeight != null" class="tx-row">
|
||||
<div v-if="shownBlock != null && shownBlock !== ''" class="tx-row">
|
||||
<span>{{ t('chain.blockHeight') }}</span>
|
||||
<div class="tx-value">
|
||||
<b>{{ blockHeight }}</b>
|
||||
<button type="button" class="tx-copy" :aria-label="t('chain.copy')" @click="$emit('copy', String(blockHeight))">
|
||||
<b>{{ shownBlock }}</b>
|
||||
<button type="button" class="tx-copy" :aria-label="t('chain.copy')" @click="$emit('copy', String(shownBlock))">
|
||||
<CopyIcon />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>{{ t('chain.txGas') }}</span>
|
||||
<div class="tx-value"><b>{{ detail?.gasUsed || '' }}</b></div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>{{ t('chain.txSender') }}</span>
|
||||
<div class="tx-value">
|
||||
<span class="tx-addr">{{ detail?.fromAddress || '' }}</span>
|
||||
<button v-if="detail?.fromAddress" type="button" class="tx-copy" :aria-label="t('chain.copy')" @click="$emit('copy', detail.fromAddress)">
|
||||
<CopyIcon />
|
||||
</button>
|
||||
</div>
|
||||
@@ -39,12 +52,14 @@
|
||||
<div class="tx-row">
|
||||
<span>{{ t('chain.txAction') }}</span>
|
||||
<div class="tx-value tx-action">
|
||||
{{ t('chain.txIssue') }} <b>{{ tokenId || '-' }}</b>
|
||||
{{ t('chain.txFromNull') }}
|
||||
<span class="tx-addr">{{ zeroAddress }}</span>
|
||||
<template v-if="mintTo">
|
||||
{{ t('chain.txIssue') }} <b>{{ actionToken || '' }}</b>
|
||||
<template v-if="actionFrom">
|
||||
{{ t('chain.txFromNull') }}
|
||||
<span class="tx-addr">{{ actionFrom }}</span>
|
||||
</template>
|
||||
<template v-if="actionTo">
|
||||
{{ t('chain.txToward') }}
|
||||
<span class="tx-addr">{{ mintTo }}</span>
|
||||
<span class="tx-addr">{{ actionTo }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
@@ -57,11 +72,11 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="contractAddress" class="tx-row">
|
||||
<div v-if="receiver" class="tx-row">
|
||||
<span>{{ t('chain.txReceiver') }}</span>
|
||||
<div class="tx-value">
|
||||
<span class="tx-addr">{{ contractAddress }}</span>
|
||||
<button type="button" class="tx-copy" :aria-label="t('chain.copy')" @click="$emit('copy', contractAddress)">
|
||||
<span class="tx-addr">{{ receiver }}</span>
|
||||
<button type="button" class="tx-copy" :aria-label="t('chain.copy')" @click="$emit('copy', receiver)">
|
||||
<CopyIcon />
|
||||
</button>
|
||||
</div>
|
||||
@@ -73,8 +88,8 @@
|
||||
<div class="tx-row tx-input-row">
|
||||
<span>{{ t('chain.txInput') }}</span>
|
||||
<div class="tx-value">
|
||||
<div class="tx-method"><i>Method</i><b>{{ mintMethod }}</b></div>
|
||||
<div class="tx-method"><i>MethodId</i><b class="mono">{{ mintMethodId }}</b></div>
|
||||
<div class="tx-method"><i>Method</i><b>{{ detail?.method || '' }}</b></div>
|
||||
<div class="tx-method"><i>MethodId</i><b class="mono">{{ detail?.methodId || '' }}</b></div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -103,31 +118,35 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="tx-panel" role="tabpanel">
|
||||
<div class="tx-row">
|
||||
<span>Address</span>
|
||||
<div class="tx-value"><span class="tx-addr">{{ contractAddress || '-' }}</span></div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Name</span>
|
||||
<div class="tx-value"><b>Transfer(address from, address to, uint256 tokenId)</b></div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Topics</span>
|
||||
<div class="tx-value">
|
||||
<div v-for="(topic, index) in topics" :key="index" class="tx-topic">
|
||||
<i>[{{ index }}]</i>
|
||||
<em v-if="index > 0">Dec</em>
|
||||
<span class="mono">{{ topic }}</span>
|
||||
<p v-if="!detail?.logs?.length" class="tx-empty">{{ t('chain.txLogsEmpty') }}</p>
|
||||
<template v-else>
|
||||
<article v-for="(log, logIndex) in detail.logs" :key="logIndex" class="tx-log">
|
||||
<div class="tx-row">
|
||||
<span>Address</span>
|
||||
<div class="tx-value"><span class="tx-addr">{{ log.address }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Data</span>
|
||||
<div class="tx-value"><b class="mono">0x</b></div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Name</span>
|
||||
<div class="tx-value"><b>{{ log.name }}</b></div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Topics</span>
|
||||
<div class="tx-value">
|
||||
<div v-for="(topic, index) in log.topics" :key="index" class="tx-topic">
|
||||
<i>[{{ index }}]</i>
|
||||
<span class="mono">{{ topic }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Data</span>
|
||||
<div class="tx-value"><b class="mono">{{ log.data || '0x' }}</b></div>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<button type="button" class="tx-back" @click="$emit('close')">{{ t('chain.txBack') }}</button>
|
||||
<button v-if="showClose" type="button" class="tx-back" @click="$emit('close')">{{ t('chain.txBack') }}</button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -136,6 +155,7 @@
|
||||
import { computed, defineComponent, h, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import type { ChainDetail } from '@/api';
|
||||
|
||||
const CopyIcon = defineComponent({
|
||||
name: 'CopyIcon',
|
||||
@@ -147,12 +167,7 @@ const CopyIcon = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const ZERO_ADDRESS = '0x' + '0'.repeat(40);
|
||||
const TRANSFER_TOPIC = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
||||
const MINT_METHOD = 'mint(address to, string author, string productId, string feature, string initPrice)';
|
||||
const MINT_METHOD_ID = '0xa40d1b10';
|
||||
|
||||
const props = defineProps<{
|
||||
const props = withDefaults(defineProps<{
|
||||
txHash?: string | null;
|
||||
succeeded: boolean;
|
||||
statusText: string;
|
||||
@@ -164,36 +179,34 @@ const props = defineProps<{
|
||||
productId?: string | null;
|
||||
feature?: string | null;
|
||||
mintTo?: string | null;
|
||||
}>();
|
||||
detail?: ChainDetail | null;
|
||||
showHeading?: boolean;
|
||||
showClose?: boolean;
|
||||
}>(), { showHeading: true, showClose: true });
|
||||
defineEmits<{ (event: 'copy', value: string): void; (event: 'close'): void }>();
|
||||
const { t } = useI18n();
|
||||
const tab = ref<'info' | 'logs'>('info');
|
||||
const zeroAddress = ZERO_ADDRESS;
|
||||
const mintMethod = MINT_METHOD;
|
||||
const mintMethodId = MINT_METHOD_ID;
|
||||
|
||||
const shownBlock = computed(() => props.detail?.blockHeight || props.blockHeight);
|
||||
const receiver = computed(() => props.detail?.toAddress || props.contractAddress || '');
|
||||
const actionToken = computed(() => props.detail?.action?.tokenId || (props.tokenId == null ? '' : String(props.tokenId)));
|
||||
const actionFrom = computed(() => props.detail?.action?.fromAddress || '');
|
||||
const actionTo = computed(() => props.detail?.action?.toAddress || props.mintTo || '');
|
||||
const timeText = computed(() => {
|
||||
if (!props.onchainAt) return '-';
|
||||
const parsed = dayjs(props.onchainAt);
|
||||
return parsed.isValid() ? parsed.format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
});
|
||||
const inputs = computed(() => [
|
||||
{ name: 'to', type: 'address', value: props.mintTo || '-', copy: props.mintTo || '' },
|
||||
{ name: 'author', type: 'string', value: props.author || '-', copy: props.author || '' },
|
||||
{ name: 'productId', type: 'string', value: props.productId || '-', copy: props.productId || '' },
|
||||
{ name: 'feature', type: 'string', value: props.feature || '-', copy: props.feature || '' },
|
||||
{ name: 'initPrice', type: 'string', value: '-', copy: '' },
|
||||
]);
|
||||
|
||||
const topics = computed(() => {
|
||||
const token = props.tokenId == null || props.tokenId === '' ? null : String(props.tokenId);
|
||||
return [
|
||||
TRANSFER_TOPIC,
|
||||
ZERO_ADDRESS,
|
||||
props.mintTo || '-',
|
||||
token && /^\d+$/.test(token) ? token : '-',
|
||||
];
|
||||
const value = props.detail?.timeStamp || props.onchainAt;
|
||||
if (!value) return '';
|
||||
const numeric = /^\d+$/.test(String(value)) ? Number(value) : value;
|
||||
const parsed = dayjs(numeric);
|
||||
return parsed.isValid() ? parsed.format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
});
|
||||
const inputs = computed(() => props.detail?.inputs?.length
|
||||
? props.detail.inputs.map((row) => ({ ...row, value: row.data, copy: row.data }))
|
||||
: [
|
||||
{ name: 'to', type: 'address', value: props.mintTo || '', copy: props.mintTo || '' },
|
||||
{ name: 'author', type: 'string', value: props.author || '', copy: props.author || '' },
|
||||
{ name: 'productId', type: 'string', value: props.productId || '', copy: props.productId || '' },
|
||||
{ name: 'feature', type: 'string', value: props.feature || '', copy: props.feature || '' },
|
||||
{ name: 'initPrice', type: 'string', value: '', copy: '' },
|
||||
]);
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -216,8 +229,8 @@ const topics = computed(() => {
|
||||
.tx-copy { width: 22px; height: 22px; border: 0; background: transparent; color: #98a2b3; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
|
||||
.tx-method { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; width: 100%; padding: 4px 0; }
|
||||
.tx-method i { color: #667085; font-style: normal; }
|
||||
.tx-input-row .tx-value { display: block; }
|
||||
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
|
||||
.tx-input-row .tx-value { display: block; overflow-x: auto; }
|
||||
table { width: 100%; min-width: 520px; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
|
||||
th, td { border-bottom: 1px solid #f2f4f8; text-align: left; padding: 8px 6px; vertical-align: top; }
|
||||
th { color: #667085; font-weight: 500; }
|
||||
.tx-cell { word-break: break-all; white-space: pre-wrap; }
|
||||
@@ -225,6 +238,7 @@ th { color: #667085; font-weight: 500; }
|
||||
.tx-topic i, .tx-topic em { color: #98a2b3; font-style: normal; flex: none; }
|
||||
.mono { font-family: Consolas, 'SFMono-Regular', monospace; word-break: break-all; }
|
||||
.tx-back { margin-top: 18px; border: 0; background: #3b6cff; color: #fff; border-radius: 6px; padding: 8px 18px; font: inherit; cursor: pointer; }
|
||||
.tx-empty { margin: 18px 0; color: #98a2b3; font-size: 14px; }
|
||||
@media (max-width: 720px) {
|
||||
.tx-page { padding: 12px; }
|
||||
.tx-top, .tx-row { display: block; }
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
.certificate-prove h1,
|
||||
.certificate-prove p { margin: 0; }
|
||||
.certificate-prove .el-divider { background-color: #dcdfe6; position: relative; }
|
||||
.certificate-prove .el-divider--horizontal { display: block; height: 1px; width: 100%; margin: 24px 0; }
|
||||
.certificate-prove{position:relative;height:720px;min-width:508px;background-color:#e0e0e0;text-align:center;padding:60px;background-image:url('../../assets/certificate/prove-bg.png');background-repeat:no-repeat;background-size:auto 100%}
|
||||
.certificate-prove .prove-wrapper{position:absolute;left:0;right:0;bottom:0;top:0;background:transparent;z-index:1}
|
||||
.certificate-prove .cert-logo{height:26px;text-align:center;margin-bottom:17px}
|
||||
.certificate-prove .cert-logo img{height:26px}
|
||||
.certificate-prove .cert-title{font-family:PingFangSC-Semibold;font-size:24px;color:#333;letter-spacing:0;margin-bottom:15.6px}
|
||||
.certificate-prove .cert-notice{font-family:PingFangSC-Regular;font-size:12px;color:#333;letter-spacing:0;word-break:keep-all;width:calc(100% + 60px);transform:translateX(-30px) scale(.833);margin-bottom:40.4px}
|
||||
.certificate-prove .row-mod{font-family:PingFang-SC-Bold;letter-spacing:0;line-height:17px;word-break:break-all;text-align:left;margin-bottom:17px}
|
||||
.certificate-prove .row-mod .row-title{font-size:12px;color:#333}
|
||||
.certificate-prove .row-mod .row-value{width:120%;font-size:12px;transform:translateX(-8.33%) scale(.833);color:#151515}
|
||||
.certificate-prove .cert-divider{margin:20px 0;background:rgba(155,176,207,.4)}
|
||||
.certificate-prove .prove-area{display:flex;width:100%;justify-content:space-between}
|
||||
.certificate-prove .prove-area-2{position:relative;margin-top:94px}
|
||||
.certificate-prove .prove-area-2 .form-mod{flex:1}
|
||||
.certificate-prove .prove-area-2 .check-img{position:absolute;right:0;align-self:center;height:100px;width:100px}
|
||||
.certificate-prove .prove-area-3{margin-top:52px}
|
||||
.certificate-prove .prove-area-3 .prove-notice{flex:1;text-align:left;font-family:PingFangSC-Regular;font-size:12px;color:#666;letter-spacing:0;width:120%;transform:translateX(-8.33%) scale(.833)}
|
||||
.certificate-prove .prove-area-3 .wx-link{width:100px;height:100px;display:flex;justify-content:center;align-items:center;position:relative;border:4px solid #999}
|
||||
.certificate-prove .prove-area-3 .wx-link .qrcode-logo{background:#fff;padding:4px;border-radius:1px;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:16px}
|
||||
.certificate-prove #qrcode{width:88px;height:88px;line-height:0}
|
||||
.certificate-prove #qrcode img{display:block;width:88px;height:88px}
|
||||
.certificate-prove .form-mod{display:flex;flex-direction:column;justify-content:flex-start;align-items:flex-start}
|
||||
.certificate-prove .form-mod .form-item{display:flex;width:100%;margin-bottom:12px}
|
||||
.certificate-prove .form-mod .form-item .form-item-label,.certificate-prove .form-mod .form-item .form-item-value{display:inline-block;font-family:PingFangSC-Regular;font-size:12px;letter-spacing:0;transform:translateX(-8.33%) scale(.833)}
|
||||
.certificate-prove .form-mod .form-item .form-item-label{width:60px;text-align:right;color:#666}
|
||||
.certificate-prove .form-mod .form-item .form-item-value{box-sizing:border-box;padding-left:4px;width:calc(100% - 60px);text-align:left;word-wrap:break-word;color:#000}
|
||||
.certificate-prove .form-mod .form-item:last-child{margin-bottom:0}
|
||||
|
||||
.certificate-prove {
|
||||
width: 508px;
|
||||
box-sizing: border-box;
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
color: #2c3e50;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
@@ -78,6 +78,9 @@
|
||||
"txType": "Type",
|
||||
"txData": "Data",
|
||||
"txBack": "Back",
|
||||
"txGas": "Gas used",
|
||||
"txSender": "Sender",
|
||||
"txLogsEmpty": "",
|
||||
"explorer": "View Proof",
|
||||
"copy": "Copy",
|
||||
"copied": "Copied",
|
||||
|
||||
@@ -78,6 +78,9 @@
|
||||
"txType": "类型",
|
||||
"txData": "数据",
|
||||
"txBack": "返回",
|
||||
"txGas": "Gas花费",
|
||||
"txSender": "发送方",
|
||||
"txLogsEmpty": "",
|
||||
"explorer": "查看存证",
|
||||
"copy": "复制",
|
||||
"copied": "已复制",
|
||||
|
||||
@@ -4,9 +4,13 @@ export default createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: () => import('@/views/Home.vue') },
|
||||
{ path: '/trace/:code', component: () => import('@/views/Trace.vue') },
|
||||
{ path: '/trace/:code/proof', name: 'trace-proof', component: () => import('@/views/TraceProof.vue') },
|
||||
{ path: '/trace/:code/certificate', name: 'trace-certificate', component: () => import('@/views/TraceCertificate.vue') },
|
||||
{ path: '/trace/:code', name: 'trace', component: () => import('@/views/Trace.vue') },
|
||||
// 后台预览模式:复用 Trace.vue,凭 ?token= 时间令牌访问,不激活/不计数
|
||||
{ path: '/trace/preview/:code', component: () => import('@/views/Trace.vue') },
|
||||
{ path: '/trace/preview/:code/proof', name: 'trace-preview-proof', component: () => import('@/views/TraceProof.vue') },
|
||||
{ path: '/trace/preview/:code/certificate', name: 'trace-preview-certificate', component: () => import('@/views/TraceCertificate.vue') },
|
||||
{ path: '/trace/preview/:code', name: 'trace-preview', component: () => import('@/views/Trace.vue') },
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
export interface CertificateImageInput {
|
||||
title: string;
|
||||
rows: Array<{ label: string; value: string }>;
|
||||
filename: string;
|
||||
}
|
||||
|
||||
const FONT = '"Microsoft YaHei", "PingFang SC", sans-serif';
|
||||
|
||||
function wrap(ctx: CanvasRenderingContext2D, value: string, maxWidth: number): string[] {
|
||||
const lines: string[] = [];
|
||||
let line = '';
|
||||
for (const char of Array.from(value || '-')) {
|
||||
const next = line + char;
|
||||
if (line && ctx.measureText(next).width > maxWidth) {
|
||||
lines.push(line);
|
||||
line = char;
|
||||
} else {
|
||||
line = next;
|
||||
}
|
||||
}
|
||||
lines.push(line || '-');
|
||||
return lines;
|
||||
}
|
||||
|
||||
export function downloadCertificatePng(input: CertificateImageInput): void {
|
||||
const width = 750;
|
||||
const pad = 48;
|
||||
const maxWidth = width - pad * 2;
|
||||
const measure = document.createElement('canvas').getContext('2d');
|
||||
if (!measure) return;
|
||||
const lines: Array<{ text: string; font: string; gap: number; color: string }> = [];
|
||||
measure.font = `bold 28px ${FONT}`;
|
||||
for (const text of wrap(measure, input.title, maxWidth)) {
|
||||
lines.push({ text, font: measure.font, gap: 36, color: '#143028' });
|
||||
}
|
||||
for (const row of input.rows) {
|
||||
measure.font = `bold 14px ${FONT}`;
|
||||
lines.push({ text: row.label, font: measure.font, gap: 22, color: '#5c6b66' });
|
||||
measure.font = `16px ${FONT}`;
|
||||
const wrapped = wrap(measure, row.value, maxWidth);
|
||||
wrapped.forEach((text, index) => {
|
||||
lines.push({ text, font: measure.font, gap: index === wrapped.length - 1 ? 28 : 22, color: '#1c1c1c' });
|
||||
});
|
||||
}
|
||||
const height = pad * 2 + lines.reduce((sum, line) => sum + line.gap, 0);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = width * 2;
|
||||
canvas.height = height * 2;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
ctx.scale(2, 2);
|
||||
ctx.fillStyle = '#f7f3ea';
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
ctx.strokeStyle = '#0f766e';
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeRect(18, 18, width - 36, height - 36);
|
||||
let y = pad + 8;
|
||||
for (const line of lines) {
|
||||
ctx.font = line.font;
|
||||
ctx.fillStyle = line.color;
|
||||
ctx.fillText(line.text, pad, y);
|
||||
y += line.gap;
|
||||
}
|
||||
canvas.toBlob((blob) => {
|
||||
if (!blob) return;
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = input.filename;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}, 'image/png');
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<div class="subpage">
|
||||
<header class="subpage-bar">
|
||||
<button type="button" class="subpage-back" @click="back">{{ t('chain.txBack') }}</button>
|
||||
<h1>{{ t('chain.certificateView') }}</h1>
|
||||
<button v-if="certificateRecord" type="button" class="subpage-action" @click="certificateSheet?.download()">
|
||||
{{ t('chain.certificateDownload') }}
|
||||
</button>
|
||||
</header>
|
||||
<div class="subpage-body">
|
||||
<p v-if="preview" class="subpage-note">{{ t('chain.certificatePreview') }}</p>
|
||||
<template v-else>
|
||||
<p v-if="certificateError" class="subpage-note" role="alert">{{ certificateError }}</p>
|
||||
<button v-if="certificateError && retryable" type="button" class="subpage-action" @click="load">
|
||||
{{ t('chain.certificateCheckAgain') }}
|
||||
</button>
|
||||
<div v-else-if="certificateRecord" ref="stage" class="cert-stage" :style="{ height: `${720 * scale}px` }">
|
||||
<div class="cert-fit" :style="{ transform: `scale(${scale})` }">
|
||||
<trace-certificate-sheet ref="certificateSheet" :record="certificateRecord" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="subpage-wait">
|
||||
<div class="certificate-spinner" aria-hidden="true" />
|
||||
<ol class="certificate-steps">
|
||||
<li v-for="(key, index) in certificateSteps" :key="key" :class="{ current: certificatePhase === index, done: certificatePhase > index }">
|
||||
<span aria-hidden="true">{{ certificatePhase > index ? '✓' : index + 1 }}</span>{{ t(key) }}
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { fetchTraceCertificate, requestTraceCertificate, type TraceCertificateRecord, type TraceCertificateResult } from '@/api';
|
||||
import TraceCertificateSheet from '@/components/trace/TraceCertificateSheet.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const preview = route.name === 'trace-preview-certificate';
|
||||
const code = String(route.params.code || '');
|
||||
const certificateError = ref('');
|
||||
const certificatePhase = ref(0);
|
||||
const certificateRecord = ref<TraceCertificateRecord | null>(null);
|
||||
const certificateSheet = ref<{ download: () => Promise<void> }>();
|
||||
const retryable = ref(true);
|
||||
const certificateSteps = ['chain.certificateRetrieving', 'chain.certificateAcquiring', 'chain.certificatePreparing'];
|
||||
const stage = ref<HTMLElement>();
|
||||
const scale = ref(1);
|
||||
let certificateTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let certificateRun = 0;
|
||||
let certificatePolls = 0;
|
||||
let observer: ResizeObserver | undefined;
|
||||
|
||||
function back() {
|
||||
const name = preview ? 'trace-preview' : 'trace';
|
||||
if (window.history.state?.back) router.back();
|
||||
else router.push({ name, params: { code }, query: route.query });
|
||||
}
|
||||
function failCertificate(messageKey: string, canRetry = true) {
|
||||
certificateError.value = t(messageKey);
|
||||
retryable.value = canRetry;
|
||||
}
|
||||
async function showCertificateResult(result: TraceCertificateResult, run: number) {
|
||||
if (run !== certificateRun) return;
|
||||
if (result.status === 'READY' && result.certificate) {
|
||||
certificatePhase.value = 2;
|
||||
certificateRecord.value = result.certificate;
|
||||
await nextTick();
|
||||
measure();
|
||||
return;
|
||||
}
|
||||
if (result.status === 'FAILED') return failCertificate('chain.certificateFailed', false);
|
||||
if (result.status === 'UNKNOWN') return failCertificate('chain.certificateDelayed');
|
||||
if (result.status === 'NONE') return failCertificate('chain.certificateUnavailable');
|
||||
certificatePhase.value = 1;
|
||||
if (++certificatePolls >= 60) return failCertificate('chain.certificateDelayed');
|
||||
certificateTimer = setTimeout(async () => {
|
||||
try { showCertificateResult(await fetchTraceCertificate(code), run); }
|
||||
catch { if (run === certificateRun) failCertificate('chain.certificateUnavailable'); }
|
||||
}, 5000);
|
||||
}
|
||||
async function load() {
|
||||
if (preview) return;
|
||||
certificateRun += 1;
|
||||
if (certificateTimer) clearTimeout(certificateTimer);
|
||||
const run = certificateRun;
|
||||
certificateError.value = '';
|
||||
certificateRecord.value = null;
|
||||
certificatePhase.value = 0;
|
||||
certificatePolls = 0;
|
||||
retryable.value = true;
|
||||
try {
|
||||
const cached = await fetchTraceCertificate(code);
|
||||
if (run !== certificateRun) return;
|
||||
certificatePhase.value = 1;
|
||||
const result = cached.status === 'NONE' || cached.status === 'UNKNOWN'
|
||||
? await requestTraceCertificate(code) : cached;
|
||||
showCertificateResult(result, run);
|
||||
} catch {
|
||||
if (run === certificateRun) failCertificate('chain.certificateRequestFailed');
|
||||
}
|
||||
}
|
||||
function measure() {
|
||||
const width = stage.value?.clientWidth || 0;
|
||||
scale.value = width > 0 ? Math.min(1, width / 508) : 1;
|
||||
}
|
||||
onMounted(() => {
|
||||
load();
|
||||
observer = new ResizeObserver(measure);
|
||||
observer.observe(document.documentElement);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
certificateRun += 1;
|
||||
if (certificateTimer) clearTimeout(certificateTimer);
|
||||
observer?.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.subpage { max-width: 560px; margin: 0 auto; min-height: 100vh; background: var(--bg); }
|
||||
.subpage-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; background: var(--card-bg); border-bottom: 1px solid var(--border); }
|
||||
.subpage-bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.subpage-bar { flex-wrap: wrap; }
|
||||
.subpage-back, .subpage-action { border: 0; background: transparent; color: var(--brand-2); font: inherit; font-size: 14px; cursor: pointer; padding: 6px 0; }
|
||||
.subpage-action { background: var(--brand); color: #fff; border-radius: 6px; padding: 8px 12px; }
|
||||
.subpage-body { padding: 12px 12px 28px; }
|
||||
.subpage-note { margin: 12px 0; font-size: 14px; line-height: 1.6; }
|
||||
.cert-stage { position: relative; width: 100%; margin: 0 auto; }
|
||||
.cert-fit { position: absolute; left: 50%; top: 0; width: 508px; margin-left: -254px; transform-origin: top center; }
|
||||
.subpage-wait { padding: 12px 4px 24px; }
|
||||
.certificate-spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; margin: 0 auto 24px; animation: certificate-spin .8s linear infinite; }
|
||||
.certificate-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; font-size: 14px; }
|
||||
.certificate-steps li { display: flex; gap: 12px; align-items: center; color: var(--muted); }
|
||||
.certificate-steps li span { border: 1px solid var(--border); border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; flex-shrink: 0; }
|
||||
.certificate-steps li.current { color: var(--text); font-weight: 600; }
|
||||
.certificate-steps li.done { color: var(--brand); }
|
||||
@keyframes certificate-spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .certificate-spinner { animation: none; } }
|
||||
</style>
|
||||
@@ -0,0 +1,138 @@
|
||||
<template>
|
||||
<div class="subpage">
|
||||
<header class="subpage-bar">
|
||||
<button type="button" class="subpage-back" @click="back">{{ t('chain.txBack') }}</button>
|
||||
<h1>{{ t('chain.txTitle') }}</h1>
|
||||
</header>
|
||||
<div v-if="loading" class="subpage-state">
|
||||
<div class="spinner" />
|
||||
<p class="muted">{{ t('state.loading') }}</p>
|
||||
</div>
|
||||
<div v-else-if="missing" class="subpage-state">
|
||||
<p>{{ t('chain.notOnchain') }}</p>
|
||||
</div>
|
||||
<trace-tx-detail
|
||||
v-else
|
||||
:tx-hash="blockchain?.txHash"
|
||||
:succeeded="blockchain?.status === 'ONCHAIN'"
|
||||
:status-text="t(`chain.statuses.${status}`)"
|
||||
:block-height="blockchain?.blockHeight"
|
||||
:contract-address="blockchain?.contractAddress"
|
||||
:onchain-at="blockchain?.onchainAt"
|
||||
:token-id="blockchain?.tokenId"
|
||||
:author="blockchain?.author"
|
||||
:product-id="blockchain?.productId || code"
|
||||
:feature="blockchain?.feature"
|
||||
:mint-to="blockchain?.mintTo"
|
||||
:detail="blockchain?.chainDetail"
|
||||
:show-heading="false"
|
||||
:show-close="false"
|
||||
@copy="copy"
|
||||
@close="back"
|
||||
/>
|
||||
<transition name="toast">
|
||||
<div v-if="toast" class="toast">{{ toast }}</div>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { fetchChainDetail, fetchTrace, fetchTracePreview, type ChainDetail } from '@/api';
|
||||
import TraceTxDetail from '@/components/trace/TraceTxDetail.vue';
|
||||
|
||||
type ProofBlockchain = {
|
||||
status?: string;
|
||||
txHash?: string | null;
|
||||
contractAddress?: string | null;
|
||||
blockHeight?: string | number | null;
|
||||
onchainAt?: string | null;
|
||||
tokenId?: string | number | null;
|
||||
author?: string | null;
|
||||
productId?: string | null;
|
||||
feature?: string | null;
|
||||
mintTo?: string | null;
|
||||
chainDetail?: ChainDetail | null;
|
||||
};
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const preview = route.name === 'trace-preview-proof';
|
||||
const code = String(route.params.code || '');
|
||||
const loading = ref(true);
|
||||
const missing = ref(false);
|
||||
const blockchain = ref<ProofBlockchain | null>(null);
|
||||
const toast = ref('');
|
||||
const status = computed(() => blockchain.value?.status || 'ONCHAIN');
|
||||
|
||||
function storageKey() {
|
||||
return `artveris.trace.proof.${preview ? 'preview.' : ''}${code}`;
|
||||
}
|
||||
function back() {
|
||||
const name = preview ? 'trace-preview' : 'trace';
|
||||
if (window.history.state?.back) router.back();
|
||||
else router.push({ name, params: { code }, query: route.query });
|
||||
}
|
||||
async function copy(text?: string) {
|
||||
if (!text) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
const area = document.createElement('textarea');
|
||||
area.value = text;
|
||||
document.body.appendChild(area);
|
||||
area.select();
|
||||
document.execCommand('copy');
|
||||
area.remove();
|
||||
}
|
||||
toast.value = t('chain.copied');
|
||||
setTimeout(() => (toast.value = ''), 1500);
|
||||
}
|
||||
onMounted(async () => {
|
||||
const cached = sessionStorage.getItem(storageKey());
|
||||
if (cached) {
|
||||
try { blockchain.value = JSON.parse(cached) as ProofBlockchain; } catch { blockchain.value = null; }
|
||||
}
|
||||
if (!blockchain.value?.txHash) {
|
||||
try {
|
||||
const data = preview
|
||||
? await fetchTracePreview(code, String(route.query.token || ''), route.query.state === 'inactive' ? 'inactive' : 'active')
|
||||
: await fetchTrace(code);
|
||||
blockchain.value = data?.status === 'OK' ? data.blockchain : null;
|
||||
} catch {
|
||||
blockchain.value = null;
|
||||
}
|
||||
}
|
||||
if (!blockchain.value?.txHash) {
|
||||
missing.value = true;
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
if (!preview && !blockchain.value.chainDetail) {
|
||||
try {
|
||||
const result = await fetchChainDetail(code);
|
||||
if (result.complete && result.detail) blockchain.value = { ...blockchain.value, chainDetail: result.detail };
|
||||
} catch { /* 查询不到时保留已有字段 */ }
|
||||
}
|
||||
sessionStorage.setItem(storageKey(), JSON.stringify(blockchain.value));
|
||||
loading.value = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.subpage { max-width: 960px; margin: 0 auto; min-height: 100vh; background: #f4f6fa; }
|
||||
.subpage-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; background: var(--card-bg); border-bottom: 1px solid var(--border); }
|
||||
.subpage-bar { flex-wrap: wrap; }
|
||||
.subpage-bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; text-align: left; }
|
||||
.subpage-back { border: 0; background: transparent; color: var(--brand-2); font: inherit; font-size: 14px; cursor: pointer; padding: 6px 0; }
|
||||
.subpage-state { padding: 48px 16px; text-align: center; }
|
||||
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
|
||||
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #111827; color: #fff; border-radius: 999px; padding: 8px 14px; font-size: 13px; }
|
||||
@media (max-width: 720px) {
|
||||
.subpage { max-width: none; }
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
Reference in New Issue
Block a user