From 5c73fdea86438aa65c0a22d98ee593a2c576d257 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=97=E5=BF=97=E5=86=9B?= <543024265@qq.com>
Date: Wed, 9 Jul 2025 14:24:09 +0800
Subject: [PATCH] =?UTF-8?q?feat(property-marketing):=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E6=8A=95=E6=94=BE=E6=8C=87=E5=8D=97=E4=B8=8B=E8=BD=BD=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=B9=B6=E9=87=8D=E6=9E=84PDF=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../table-data/guideListHistory.vue | 34 ++--
.../components/table-data/listSearchForm.vue | 2 +-
.../table-data/placementGuideList.vue | 3 +-
.../investment-guidelines/index.vue | 147 +++++++++++++-----
4 files changed, 123 insertions(+), 63 deletions(-)
diff --git a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/guideListHistory.vue b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/guideListHistory.vue
index eac738f..cba3821 100644
--- a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/guideListHistory.vue
+++ b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/guideListHistory.vue
@@ -21,7 +21,7 @@
- 下载
+ 下载
详情
@@ -82,32 +82,24 @@ const goDetail = async (id) => {
router.push(`/put-account/detail/${id}`);
};
-const downloadDetailAsImage = (id) => {
- const url = `/put-account/detail/${id}`;
- const win = window.open(url, '_blank');
-
- win.onload = () => {
- setTimeout(() => {
- html2canvas(win.document.body, {
- useCORS: true,
- scale: 2,
- }).then((canvas) => {
- const imgData = canvas.toDataURL('image/png');
- const link = document.createElement('a');
- link.href = imgData;
- link.download = `详情页面_${Date.now()}.png`;
- link.click();
- win.close(); // 关闭新窗口
- });
- }, 2000); // 等待页面加载
- };
+const downLoad = (fileUrl) => {
+ if (isEmpty(fileUrl)) {
+ Message.error('下载失败,文件不存在');
+ return;
+ }
+ const link = document.createElement('a');
+ link.href = fileUrl;
+ link.download = '投放指南.pdf';
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
};
const deleteData = async (id) => {
const { code, message } = await deleteHistorylog(id);
if (code == 200) {
Message.success(message);
emits('onSearch');
- console.log('onsearch')
+ console.log('onsearch');
}
};
diff --git a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/listSearchForm.vue b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/listSearchForm.vue
index a28c68f..816b0cb 100644
--- a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/listSearchForm.vue
+++ b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/listSearchForm.vue
@@ -50,7 +50,7 @@
-
+
diff --git a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/placementGuideList.vue b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/placementGuideList.vue
index 456372c..ebd2c5b 100644
--- a/src/views/property-marketing/put-account/investment-guidelines/components/table-data/placementGuideList.vue
+++ b/src/views/property-marketing/put-account/investment-guidelines/components/table-data/placementGuideList.vue
@@ -54,8 +54,7 @@
-
- {{ PLATFORM_LIST[record.platform].label }}
+
diff --git a/src/views/property-marketing/put-account/investment-guidelines/index.vue b/src/views/property-marketing/put-account/investment-guidelines/index.vue
index 20298ce..a1f079a 100644
--- a/src/views/property-marketing/put-account/investment-guidelines/index.vue
+++ b/src/views/property-marketing/put-account/investment-guidelines/index.vue
@@ -5,7 +5,7 @@
@@ -16,6 +16,7 @@
-
-
-
+
+
-
-
+
@@ -89,7 +93,10 @@ import {
} from '@/api/all/propertyMarketing';
import { Message } from '@arco-design/web-vue';
import html2canvas from 'html2canvas';
+import { jsPDF } from 'jspdf';
import { AiResultStatus } from '@/views/property-marketing/put-account/investment-guidelines/constants';
+import { fetchUploadFile } from '@/api/all';
+import axios from 'axios';
const tabData = ref('placement_guide');
@@ -121,6 +128,7 @@ const handleUpdateQuery = (payload) => {
query.sort_column = payload.column;
query.sort_order = payload.order;
isGetAi.value = false;
+ loading.value = false;
onSearch();
};
@@ -143,11 +151,10 @@ const onSearch = async () => {
guideHistoryList.value = result?.data?.data || [];
}
listData.total = result.data.total;
- if (placementGuideList.value.length > 0) {
+ if (placementGuideList.value.length > 0 && isGetAi.value) {
loading.value = true;
- if (isGetAi.value) {
- startTask();
- }
+ syncGetAiResult();
+ startTask();
}
isGetAi.value = true;
};
@@ -159,15 +166,14 @@ const aiResult = reactive({
// 下载当前页面
const downPage = async () => {
- await nextTick(); // 确保 DOM 更新完成
- html2canvas(document.querySelector('.guidelines-data-wrap')).then((canvas) => {
- const imgData = canvas.toDataURL('image/png');
- const link = document.createElement('a');
- link.href = imgData;
- const timestamp = new Date().getTime();
- link.download = `投放指南-${timestamp}.png`;
- link.click();
- });
+ await nextTick();
+ const fileUrl = await uploadPdf();
+ const link = document.createElement('a');
+ link.href = fileUrl;
+ link.download = '投放指南.pdf';
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
};
const saveForm = reactive({
account: [],
@@ -175,33 +181,48 @@ const saveForm = reactive({
platform: [],
aiResult: [],
code: '',
+ file_url: '',
});
const timerRef = ref(null);
const startTask = () => {
if (timerRef.value !== null) return;
timerRef.value = setInterval(async () => {
- try {
- const { code, data } = await getAiResult(query);
- console.log('定时任务执行结果:', data);
- if (data.ai_result_status === AiResultStatus.SUCCESS || data.ai_result_status === AiResultStatus.FAILED) {
- stopTask();
- console.log('任务已完成,定时器已关闭');
- }
- if (data.ai_result_status === AiResultStatus.SUCCESS) {
- loading.value = false;
- aiResult.optimization = data.result?.optimization?.modules || [];
- aiResult.action_guide = data.result?.action_guide?.modules || [];
- aiResult.overview = data.result?.overview?.content_blocks[0] || [];
- }
- saveForm.code = data?.code;
- console.log(aiResult, 'aiResult');
- } catch (error) {
- console.error('定时任务执行出错:', error);
- stopTask();
- }
+ syncGetAiResult();
}, 5000);
};
+const syncGetAiResult = async () => {
+ try {
+ const { code, data } = await getAiResult(query);
+ saveForm.file_url = '';
+ console.log('定时任务执行结果:', data);
+ if (data.ai_result_status === AiResultStatus.SUCCESS || data.ai_result_status === AiResultStatus.FAILED) {
+ stopTask();
+ console.log('任务已完成,定时器已关闭');
+ }
+ if (data.ai_result_status === AiResultStatus.SUCCESS) {
+ loading.value = false;
+ aiResult.optimization = data.result?.optimization?.modules || [];
+ aiResult.action_guide = data.result?.action_guide?.modules || [];
+ aiResult.overview = data.result?.overview?.content_blocks[0] || [];
+ } else if (data.ai_result_status === AiResultStatus.FAILED) {
+ Message.error('AI分析失败');
+ aiError();
+ }
+ saveForm.code = data?.code;
+ } catch (error) {
+ aiError();
+ }
+};
+
+// ai 检测失败执行方法
+const aiError = () => {
+ aiResult.optimization = [];
+ aiResult.action_guide = [];
+ aiResult.overview = [];
+ stopTask();
+};
+
const handleReset = () => {
console.log('handleReset');
query.page = 1;
@@ -226,6 +247,7 @@ onUnmounted(() => {
stopTask();
});
const handleSave = async () => {
+ await uploadPdf();
const updatedSaveForm = {
...saveForm,
ai_result: aiResult,
@@ -235,6 +257,52 @@ const handleSave = async () => {
Message.success(message);
}
};
+
+// 上传pdf文件
+const uploadPdf = async () => {
+ if (saveForm.file_url !== '') {
+ return saveForm.file_url;
+ }
+ const response = await fetchUploadFile({ suffix: 'pdf' });
+ const preSignedUrl = response?.data?.upload_url;
+ const fileUrl = response?.data?.file_url;
+ if (!preSignedUrl) {
+ throw new Error('未能获取有效的预签名上传地址');
+ }
+ saveForm.file_url = fileUrl;
+ const pdfBlob = await generatePDF(); // 生成 PDF Blob
+ console.log('pdfBlob', pdfBlob);
+ await axios.put(preSignedUrl, pdfBlob, {
+ headers: {
+ 'Content-Type': pdfBlob.type,
+ },
+ });
+ return fileUrl;
+};
+
+const generatePDF = async (): Promise => {
+ await nextTick();
+ const sections = document.querySelectorAll('.guidelines-data-wrap');
+ const pdf = new jsPDF('p', 'mm', 'a4');
+ let position = 0;
+ for (const section of sections) {
+ if (section.children.length === 0) continue; // 跳过空内容区域
+ const canvas = await html2canvas(section as HTMLElement, {
+ ignoreElements: (element) => {
+ return element.classList.contains('ignore-export'); // 例如:忽略 class 为 ignore-export 的元素
+ },
+ });
+ const imgData = canvas.toDataURL('image/png');
+ const imgProps = pdf.getImageProperties(imgData);
+ const pdfWidth = pdf.internal.pageSize.getWidth();
+ const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
+ pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight);
+ position += pdfHeight + 10;
+ }
+
+ return pdf.output('blob');
+};
+
onMounted(() => {
onSearch();
});
@@ -242,6 +310,7 @@ onMounted(() => {