fix: 修正审查发现的出证重试、链上详情范围和手机保存证书问题
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { ChainDetail } from '@/api';
|
||||
import { writeProofCache } from './proofCache';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@@ -115,8 +116,7 @@ const router = useRouter();
|
||||
const canViewCertificate = computed(() => props.blockchain?.status === 'ONCHAIN' && Boolean(props.blockchain.txHash) && props.blockchain.chainName === '天河链');
|
||||
|
||||
function openProof() {
|
||||
const key = `artveris.trace.proof.${props.preview ? 'preview.' : ''}${props.shortCode}`;
|
||||
sessionStorage.setItem(key, JSON.stringify(props.blockchain || null));
|
||||
writeProofCache(props.shortCode, props.preview === true, props.blockchain);
|
||||
router.push({
|
||||
name: props.preview ? 'trace-preview-proof' : 'trace-proof',
|
||||
params: { code: props.shortCode },
|
||||
|
||||
@@ -71,33 +71,30 @@ const created = computed(() => {
|
||||
|
||||
onMounted(async () => {
|
||||
const host = props.record.environment === 'test' ? 'https://test.explorer.tianhecloud.com' : 'https://explorer.tianhecloud.com';
|
||||
// 按 4 倍像素生成,页面仍显示 88px,导出的大图里二维码才清晰
|
||||
qrUrl.value = await QRCode.toDataURL(`${host}/#/tiChain/transDetail?hash=${props.record.txHash}`, {
|
||||
width: 88,
|
||||
width: 352,
|
||||
margin: 0,
|
||||
errorCorrectionLevel: 'H',
|
||||
color: { dark: '#000000', light: '#ffffff' },
|
||||
});
|
||||
});
|
||||
|
||||
async function download() {
|
||||
/** 把证书画成 3 倍大图。页面上的证书可能被缩小显示,所以用一份原尺寸的副本来画。 */
|
||||
async function render(): Promise<HTMLCanvasElement> {
|
||||
const target = sheet.value;
|
||||
if (!target) return;
|
||||
if (!target) throw new Error('certificate is not ready');
|
||||
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);
|
||||
host.appendChild(target.cloneNode(true));
|
||||
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();
|
||||
return await html2canvas(host.firstElementChild as HTMLElement, { scale: 3, backgroundColor: '#e0e0e0' });
|
||||
} finally {
|
||||
host.remove();
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ download });
|
||||
defineExpose({ render });
|
||||
</script>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<template>
|
||||
<div class="tx-page">
|
||||
<div class="tx-top">
|
||||
<h3 v-if="showHeading">{{ t('chain.txTitle') }}</h3>
|
||||
<div class="tx-hashbox">{{ txHash || '-' }}</div>
|
||||
</div>
|
||||
<div class="tx-hashbox">{{ txHash || '-' }}</div>
|
||||
<section class="tx-card">
|
||||
<div class="tx-tabs" role="tablist">
|
||||
<button type="button" role="tab" :class="{ active: tab === 'info' }" :aria-selected="tab === 'info'" @click="tab = 'info'">{{ t('chain.txInfo') }}</button>
|
||||
@@ -118,35 +115,30 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="tx-panel" role="tabpanel">
|
||||
<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 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>
|
||||
<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 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 class="tx-row">
|
||||
<span>Data</span>
|
||||
<div class="tx-value"><b class="mono">{{ log.data || '0x' }}</b></div>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</div>
|
||||
<div class="tx-row">
|
||||
<span>Data</span>
|
||||
<div class="tx-value"><b class="mono">{{ log.data || '0x' }}</b></div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<button v-if="showClose" type="button" class="tx-back" @click="$emit('close')">{{ t('chain.txBack') }}</button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -167,7 +159,7 @@ const CopyIcon = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
const props = defineProps<{
|
||||
txHash?: string | null;
|
||||
succeeded: boolean;
|
||||
statusText: string;
|
||||
@@ -180,10 +172,8 @@ const props = withDefaults(defineProps<{
|
||||
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 }>();
|
||||
}>();
|
||||
defineEmits<{ (event: 'copy', value: string): void }>();
|
||||
const { t } = useI18n();
|
||||
const tab = ref<'info' | 'logs'>('info');
|
||||
const shownBlock = computed(() => props.detail?.blockHeight || props.blockHeight);
|
||||
@@ -211,9 +201,7 @@ const inputs = computed(() => props.detail?.inputs?.length
|
||||
|
||||
<style scoped>
|
||||
.tx-page { background: #f4f6fa; color: #1f2a37; border-radius: 12px; padding: 18px 18px 22px; }
|
||||
.tx-top { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 14px; }
|
||||
.tx-top h3 { margin: 0; font-size: 18px; font-weight: 600; }
|
||||
.tx-hashbox { max-width: 420px; flex: 1; border: 1px solid #e3e8f0; background: #fff; border-radius: 999px; padding: 7px 14px; color: #667085; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tx-hashbox { max-width: 420px; margin: 0 0 14px; border: 1px solid #e3e8f0; background: #fff; border-radius: 999px; padding: 7px 14px; color: #667085; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tx-card { background: #fff; border: 1px solid #e6ebf2; border-radius: 10px; padding: 8px 22px 22px; }
|
||||
.tx-tabs { display: flex; gap: 22px; border-bottom: 1px solid #edf1f6; }
|
||||
.tx-tabs button { border: 0; background: transparent; padding: 12px 0; color: #667085; font: inherit; cursor: pointer; }
|
||||
@@ -235,14 +223,12 @@ th, td { border-bottom: 1px solid #f2f4f8; text-align: left; padding: 8px 6px; v
|
||||
th { color: #667085; font-weight: 500; }
|
||||
.tx-cell { word-break: break-all; white-space: pre-wrap; }
|
||||
.tx-topic { display: flex; gap: 8px; align-items: flex-start; width: 100%; padding: 3px 0; }
|
||||
.tx-topic i, .tx-topic em { color: #98a2b3; font-style: normal; flex: none; }
|
||||
.tx-topic i { 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; }
|
||||
.tx-hashbox { max-width: none; margin-top: 10px; }
|
||||
.tx-row { display: block; }
|
||||
.tx-hashbox { max-width: none; }
|
||||
.tx-row > span { display: block; margin-bottom: 6px; }
|
||||
.tx-card { padding: 8px 12px 16px; }
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ export function openTraceViewer(items: PublicMediaItem[], index: number): void {
|
||||
export function safeTraceUrl(value?: string): string {
|
||||
const url = traceMediaUrl(value);
|
||||
if (!/^(https?:\/\/|\/)/i.test(url)) return '';
|
||||
if (url.startsWith('/')) return url;
|
||||
try {
|
||||
if (/(^|\.)tianhecloud\.com$/i.test(new URL(url).hostname)) return '';
|
||||
// 以当前站点为基准解析,“//域名/路径”这种写法也会按真实域名判断
|
||||
if (/(^|\.)tianhecloud\.com$/i.test(new URL(url, window.location.origin).hostname)) return '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 溯源页把已拿到的区块链信息带给存证详情页,详情页不必为此再查一次溯源接口
|
||||
* (每查一次都会计入防伪查询次数)。浏览器不允许使用存储时静默跳过,详情页会自行查询。
|
||||
*/
|
||||
function key(code: string, preview: boolean): string {
|
||||
return `artveris.trace.proof.${preview ? 'preview.' : ''}${code}`;
|
||||
}
|
||||
|
||||
export function writeProofCache(code: string, preview: boolean, value: unknown): void {
|
||||
try {
|
||||
sessionStorage.setItem(key(code, preview), JSON.stringify(value ?? null));
|
||||
} catch {
|
||||
// 存储不可用
|
||||
}
|
||||
}
|
||||
|
||||
export function readProofCache<T>(code: string, preview: boolean): T | null {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(key(code, preview));
|
||||
return raw ? (JSON.parse(raw) as T) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user