43 lines
2.8 KiB
Plaintext
43 lines
2.8 KiB
Plaintext
<template>
|
|||
|
|
<view class="export-area">
|
||
|
|
<view class="export-row"><text class="export-label">报告已保存至融资档案</text><button class="export-button" :disabled="busy" @click="download">{{ busy ? '正在生成…' : '下载PDF' }}</button></view>
|
||
|
|
<text v-if="message.length > 0" :class="failed ? 'export-message export-error' : 'export-message'">{{ message }}</text>
|
||
|
|
<text v-if="message.length == 0" class="export-message">导出不含身份信息,请妥善保管下载文件。</text>
|
||
|
|
</view>
|
||
|
|
</template>
|
||
|
|
<script setup lang="uts">
|
||
|
|
import { getSession } from '@/services/api.uts'
|
||
|
|
import { ReportDownload, downloadReportPdf } from '@/packages/finance/services/report-export.uts'
|
||
|
|
const props = defineProps({ assessmentId: { type: String, required: true } })
|
||
|
|
const emit = defineEmits(['authrequired', 'sessionchanged'])
|
||
|
|
const busy = ref(false); const message = ref(''); const failed = ref(false)
|
||
|
|
let operation: ReportDownload | null = null; let generation = 0
|
||
|
|
const ownerToken = getSession()?.getString('token') ?? ''
|
||
|
|
const dispose = () => { generation++; operation?.cancel(); operation = null; busy.value = false }
|
||
|
|
const download = async () => {
|
||
|
|
if (busy.value) return
|
||
|
|
if (getSession() == null) { emit('authrequired'); return }
|
||
|
|
if (getSession()?.getString('token') != ownerToken) { emit('sessionchanged'); return }
|
||
|
|
const request = ++generation; busy.value = true; failed.value = false; message.value = ''
|
||
|
|
const token = getSession()?.getString('token') ?? ''
|
||
|
|
operation = downloadReportPdf(props.assessmentId)
|
||
|
|
try { const result = await operation!.done; if (request == generation) message.value = result }
|
||
|
|
catch (err) {
|
||
|
|
if (request != generation) return
|
||
|
|
failed.value = true; message.value = err instanceof Error ? err.message : '下载失败,请检查网络后重试。'
|
||
|
|
if (getSession() == null) emit('authrequired')
|
||
|
|
else if (getSession()?.getString('token') != token) emit('sessionchanged')
|
||
|
|
} finally { if (request == generation) { busy.value = false; operation = null } }
|
||
|
|
}
|
||
|
|
// 父页面离开即移除报告,组件销毁时中止下载,避免隐藏页面导出旧账户资料。
|
||
|
|
onUnmounted(() => dispose())
|
||
|
|
</script>
|
||
|
|
<style>
|
||
|
|
.export-area { margin-top: 18rpx; margin-bottom: 22rpx; }
|
||
|
|
.export-row { flex-direction: row; align-items: center; justify-content: space-between; }
|
||
|
|
.export-label { font-size: 23rpx; color: #73869d; flex: 1; }
|
||
|
|
.export-button { font-size: 24rpx; color: #0868f7; background-color: #eaf3ff; border-radius: 10rpx; margin-left: 18rpx; padding-left: 24rpx; padding-right: 24rpx; }
|
||
|
|
.export-message { color: #8393a6; font-size: 22rpx; line-height: 36rpx; margin-top: 12rpx; }
|
||
|
|
.export-error { color: #a05d37; }
|
||
|
|
</style>
|