|
@@ -1,5 +1,6 @@
|
|
|
-import { nextTick, computed } from 'vue';
|
|
|
+import { nextTick, computed, ref } from 'vue';
|
|
|
import { useMainStore } from '@/store';
|
|
|
+import { ElLoading } from 'element-plus';
|
|
|
import html2canvas from 'html2canvas';
|
|
|
import jsPDF from 'jspdf';
|
|
|
import { showMessage } from './common';
|
|
@@ -7,8 +8,21 @@ import { showMessage } from './common';
|
|
|
const mainStore = useMainStore();
|
|
|
|
|
|
const expanded = computed(() => mainStore.getExpanded);
|
|
|
+const isLoadOver = computed(() => mainStore.getIsLoadOver);
|
|
|
|
|
|
-export const downloadPDF = async (pdfContent: HTMLElement, callback: () => void) => {
|
|
|
+export const downloadPDF = async (pdfContent: HTMLElement) => {
|
|
|
+ if (!isLoadOver.value) {
|
|
|
+ showMessage({
|
|
|
+ type: 'warning',
|
|
|
+ message: '数据加载中,请稍后再试'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const loading = ElLoading.service({
|
|
|
+ lock: true,
|
|
|
+ text: '下载中...',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
|
+ });
|
|
|
if (!expanded.value) {
|
|
|
mainStore.setExpanded(true);
|
|
|
await nextTick();
|
|
@@ -22,7 +36,9 @@ export const downloadPDF = async (pdfContent: HTMLElement, callback: () => void)
|
|
|
backgroundColor: '#fff' // 防止透明背景
|
|
|
});
|
|
|
} catch (error) {
|
|
|
- callback && callback();
|
|
|
+ setTimeout(() => {
|
|
|
+ loading.close();
|
|
|
+ }, 1000);
|
|
|
mainStore.setExpanded(false);
|
|
|
showMessage({
|
|
|
type: 'error',
|
|
@@ -47,5 +63,7 @@ export const downloadPDF = async (pdfContent: HTMLElement, callback: () => void)
|
|
|
pdf.addImage(imgData, 'JPEG', x, y, imgWidth, imgHeight);
|
|
|
mainStore.setExpanded(false);
|
|
|
pdf.save('charts-and-table.pdf');
|
|
|
- callback && callback();
|
|
|
+ setTimeout(() => {
|
|
|
+ loading.close();
|
|
|
+ }, 1000);
|
|
|
};
|