feat: 用独立页面展示存证详情并按天河链版式绘制证书
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user