feat: 支持消费者按实物点击生成天河链存证证书
This commit is contained in:
@@ -57,22 +57,31 @@
|
||||
<span class="chain-k">{{ t('chain.onchainAt') }}</span>
|
||||
<span class="chain-v">{{ formatTime(blockchain.onchainAt) }}</span>
|
||||
</div>
|
||||
<a
|
||||
v-if="explorerUrl"
|
||||
class="chain-link"
|
||||
:href="explorerUrl"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{{ t('chain.explorer') }} →
|
||||
</a>
|
||||
<div class="chain-actions">
|
||||
<a
|
||||
v-if="explorerUrl"
|
||||
class="chain-link"
|
||||
:href="explorerUrl"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{{ t('chain.explorer') }} →
|
||||
</a>
|
||||
<button v-if="canViewCertificate" class="chain-link certificate-link" :disabled="opening || preview" @click="viewCertificate">
|
||||
{{ t(opening ? 'chain.certificateOpening' : 'chain.certificateView') }} →
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="preview && canViewCertificate" class="muted chain-status-note">{{ t('chain.certificatePreview') }}</p>
|
||||
<p v-if="certificateError" role="alert" class="chain-status-note">{{ certificateError }}</p>
|
||||
</template>
|
||||
<div v-else class="chain-empty muted">{{ t('chain.notOnchain') }}</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { fetchTraceCertificate, requestTraceCertificate } from '@/api';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import { safeTraceUrl } from './media';
|
||||
@@ -90,6 +99,8 @@ const STATUSES = new Set<ProofStatus>([
|
||||
const props = defineProps<{
|
||||
title: string;
|
||||
archiveNo?: string | null;
|
||||
shortCode: string;
|
||||
preview?: boolean;
|
||||
blockchain?: {
|
||||
status?: string;
|
||||
txHash?: string | null;
|
||||
@@ -98,10 +109,38 @@ const props = defineProps<{
|
||||
onchainAt?: string | null;
|
||||
explorerUrl?: string | null;
|
||||
failureReason?: string | null;
|
||||
chainName?: string | null;
|
||||
} | null;
|
||||
}>();
|
||||
defineEmits<{ (event: 'copy', value: string): void }>();
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const opening = ref(false);
|
||||
const certificateError = ref('');
|
||||
const canViewCertificate = computed(() => status.value === 'ONCHAIN' && props.blockchain?.chainName === '天河链');
|
||||
|
||||
async function viewCertificate() {
|
||||
if (opening.value || props.preview) return;
|
||||
certificateError.value = '';
|
||||
const href = router.resolve({ path: `/certificate/${props.shortCode}` }).href;
|
||||
// Open while the click gesture is active. The waiting page never starts a deposit itself.
|
||||
const popup = window.open(href, '_blank');
|
||||
if (popup) popup.opener = null;
|
||||
opening.value = true;
|
||||
try {
|
||||
const cached = await fetchTraceCertificate(props.shortCode);
|
||||
const result = cached.status === 'NONE' || cached.status === 'UNKNOWN'
|
||||
? await requestTraceCertificate(props.shortCode) : cached;
|
||||
if (!popup) {
|
||||
await router.push(`/certificate/${props.shortCode}`);
|
||||
} else if (result.status === 'READY' && result.url) {
|
||||
popup.location.replace(result.url);
|
||||
}
|
||||
} catch {
|
||||
if (popup && !popup.closed) popup.close();
|
||||
certificateError.value = t('chain.certificateRequestFailed');
|
||||
} finally { opening.value = false; }
|
||||
}
|
||||
|
||||
const status = computed<ProofStatus>(() => {
|
||||
const value = props.blockchain?.status as ProofStatus | undefined;
|
||||
@@ -213,4 +252,7 @@ function formatTime(value: string) {
|
||||
font-size: 13px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.chain-actions { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
|
||||
.certificate-link { padding: 0; border: 0; background: none; cursor: pointer; font-family: inherit; }
|
||||
.certificate-link:disabled { opacity: .55; cursor: default; }
|
||||
</style>
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
:title="moduleTitle(module)"
|
||||
:archive-no="data.artwork.archiveNo"
|
||||
:blockchain="data.blockchain"
|
||||
:short-code="shortCode"
|
||||
:preview="data.preview === true"
|
||||
@copy="(value) => $emit('copy', value)"
|
||||
/>
|
||||
<trace-image-text-module
|
||||
@@ -78,6 +80,7 @@ import TraceHorizontalGalleryModule from './TraceHorizontalGalleryModule.vue';
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
data: any;
|
||||
shortCode: string;
|
||||
layout?: TraceLayout;
|
||||
timelineItems?: any[];
|
||||
carouselInterval?: number;
|
||||
|
||||
Reference in New Issue
Block a user