Files
Artveris/apps/client/src/components/trace/TraceCertificateSheet.vue
T

104 lines
3.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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>