|
@@ -3,7 +3,7 @@
|
|
|
<div class="content">
|
|
|
<div class="c_pdf">
|
|
|
<div id="pdf-content" style="width: 630px;" ref="pdfRef">
|
|
|
- <pdf :reportData="reportData"></pdf>
|
|
|
+ <pdf :reportData="reportData" @optionsMaps="optionsMaps"></pdf>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="c_footer adfac">
|
|
@@ -26,6 +26,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup name="">
|
|
|
+ import * as echarts from "echarts";
|
|
|
import { exportPDF } from './exportPDF';
|
|
|
import pdf from './pdf.vue'
|
|
|
const props = defineProps({
|
|
@@ -51,6 +52,7 @@
|
|
|
const reportName = ref(props.reportName);
|
|
|
const reportShow = ref(false);
|
|
|
const pdfRef = ref(null);
|
|
|
+ const echartsOptions = ref(new Map())
|
|
|
const emit = defineEmits(['cancel','refreshReportList']);
|
|
|
import { updateReportPdfUrl } from '@/api/agent/index.js';
|
|
|
|
|
@@ -60,7 +62,8 @@
|
|
|
|
|
|
const exportToPDF = async () => {
|
|
|
const clonedEl = cloneEl();
|
|
|
- await nextTick();
|
|
|
+ await reinitClonedCharts(clonedEl);
|
|
|
+ // return
|
|
|
try {
|
|
|
reportShow.value = true;
|
|
|
// 滚动到顶部确保完整渲染
|
|
@@ -95,6 +98,34 @@
|
|
|
document.body.appendChild(clonedEl);
|
|
|
return clonedEl
|
|
|
}
|
|
|
+ const optionsMaps = (optionsMap) => {
|
|
|
+ echartsOptions.value = optionsMap;
|
|
|
+ }
|
|
|
+ const reinitClonedCharts = async (clonedEl) => {
|
|
|
+ // 1. 查找所有图表容器(通过 class 或 data-* 标识)
|
|
|
+ const chartContainers = clonedEl.querySelectorAll('.pdfEchart');
|
|
|
+
|
|
|
+ // 2. 并行重新渲染
|
|
|
+ await Promise.all(
|
|
|
+ Array.from(chartContainers).map(async container => {
|
|
|
+ container.id = container.id+'_copy';
|
|
|
+ const chartId = container.id;
|
|
|
+ const originalOptions = echartsOptions.value.get(chartId);
|
|
|
+
|
|
|
+ const existingChart = echarts.getInstanceByDom(container);
|
|
|
+ if (existingChart) existingChart.dispose();
|
|
|
+
|
|
|
+ // 5. 重新初始化 ECharts
|
|
|
+ const chart = echarts.init(container);
|
|
|
+ chart.setOption(originalOptions);
|
|
|
+
|
|
|
+ await new Promise(resolve => {
|
|
|
+ chart.on('finished', resolve); // ECharts 3.0+ 支持
|
|
|
+ setTimeout(resolve, 500); // 双保险
|
|
|
+ });
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
const closeReportAlert = () => {
|
|
|
reportShow.value = false;
|
|
|
nextTick(()=>{
|