2026-09-28 17:50:46 +08:00
|
|
|
<template>
|
2026-09-30 19:11:44 +08:00
|
|
|
<view :class="toolbar ? 'export-area export-toolbar' : (compact ? 'export-area export-compact' : 'export-area')">
|
|
|
|
|
<view class="export-row"><text v-if="!toolbar" class="export-label">{{ compact ? '评估 #' + assessmentId + ' · 已保存' : '报告已保存至融资档案' }}</text><button :class="toolbar ? 'export-button toolbar-button' : 'export-button'" :disabled="busy" @click="download">{{ toolbar ? (busy ? '…' : toolbarLabel) : (busy ? '正在生成…' : '下载PDF') }}</button></view>
|
|
|
|
|
<text v-if="message.length > 0 && !toolbar" :class="failed ? 'export-message export-error' : 'export-message'">{{ message }}</text>
|
|
|
|
|
<text v-if="message.length == 0 && !compact && !toolbar" class="export-message">导出不含身份信息,请妥善保管下载文件。</text>
|
2026-09-28 17:50:46 +08:00
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="uts">
|
|
|
|
|
import { getSession } from '@/services/api.uts'
|
|
|
|
|
import { ReportDownload, downloadReportPdf } from '@/packages/finance/services/report-export.uts'
|
2026-09-30 19:11:44 +08:00
|
|
|
// 顶栏模式由报告页显示完整导出回执,避免窄导航栏中的错误消息被裁切。
|
|
|
|
|
const props = defineProps({ revisionId: { type: String, default: '' }, assessmentId: { type: String, required: true }, compact: { type: Boolean, default: false }, toolbar: { type: Boolean, default: false } })
|
|
|
|
|
const emit = defineEmits(['authrequired', 'sessionchanged', 'statuschange'])
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
const toolbarLabel = 'PDF'
|
|
|
|
|
// #endif
|
|
|
|
|
// #ifndef MP-WEIXIN
|
|
|
|
|
const toolbarLabel = '下载PDF'
|
|
|
|
|
// #endif
|
2026-09-28 17:50:46 +08:00
|
|
|
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 = ''
|
2026-09-30 19:11:44 +08:00
|
|
|
if (props.toolbar) emit('statuschange', '正在生成PDF…')
|
2026-09-28 17:50:46 +08:00
|
|
|
const token = getSession()?.getString('token') ?? ''
|
2026-09-30 19:11:44 +08:00
|
|
|
operation = downloadReportPdf(props.assessmentId, props.revisionId)
|
2026-09-28 17:50:46 +08:00
|
|
|
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')
|
2026-09-30 19:11:44 +08:00
|
|
|
} finally { if (request == generation) { busy.value = false; operation = null; if (props.toolbar) emit('statuschange', message.value) } }
|
2026-09-28 17:50:46 +08:00
|
|
|
}
|
|
|
|
|
// 父页面离开即移除报告,组件销毁时中止下载,避免隐藏页面导出旧账户资料。
|
|
|
|
|
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; }
|
2026-09-29 17:27:25 +08:00
|
|
|
.export-compact { margin-top: 0; margin-bottom: 0; }
|
2026-09-30 19:11:44 +08:00
|
|
|
.export-toolbar { margin: 0; }
|
|
|
|
|
.toolbar-button { background-color: #0868f7; color: #fff; margin: 0; padding: 0 16rpx; height: 50rpx; line-height: 50rpx; font-size: 21rpx; border-radius: 12rpx; }
|
|
|
|
|
/* #ifdef MP-WEIXIN */
|
|
|
|
|
.toolbar-button { width: 32px; height: 32px; line-height: 32px; padding: 0; font-size: 11px; }
|
|
|
|
|
/* #endif */
|
2026-09-28 17:50:46 +08:00
|
|
|
</style>
|