|
@@ -213,9 +213,9 @@
|
|
|
<el-dropdown-item command="word">Word格式</el-dropdown-item
|
|
|
><!-- word -->
|
|
|
<el-dropdown-item command="pdf">PDF格式</el-dropdown-item>
|
|
|
- <!-- <el-dropdown-item command="pdf-to-word"
|
|
|
+ <el-dropdown-item command="pdf-to-word"
|
|
|
>PDF转Word</el-dropdown-item
|
|
|
- > -->
|
|
|
+ >
|
|
|
</el-dropdown-menu>
|
|
|
</template>
|
|
|
</el-dropdown>
|
|
@@ -279,6 +279,7 @@ import {
|
|
|
exportDocument,
|
|
|
exportToPDF,
|
|
|
htmlWordNew,
|
|
|
+ htmlPDFWord,
|
|
|
} from "@/api/document";
|
|
|
import { searchCustomer } from "@/api/customer";
|
|
|
import { searchProduct } from "@/api/product";
|
|
@@ -433,10 +434,10 @@ export default {
|
|
|
const tempDiv = document.createElement("div");
|
|
|
tempDiv.innerHTML = item.content;
|
|
|
// 处理所有表格
|
|
|
- tempDiv.querySelectorAll("table").forEach(table => {
|
|
|
+ tempDiv.querySelectorAll("table").forEach((table) => {
|
|
|
// 检查表格及其单元格是否有任何边框
|
|
|
const tableStyle = table.getAttribute("style");
|
|
|
-
|
|
|
+
|
|
|
// 如果表格没有style属性,直接判定为无边框
|
|
|
if (!tableStyle) {
|
|
|
table.setAttribute("data-code", "noactive");
|
|
@@ -445,14 +446,16 @@ export default {
|
|
|
|
|
|
// 检查所有单元格
|
|
|
const cells = Array.from(table.querySelectorAll("td, th"));
|
|
|
- const hasBorder = cells.some(cell => {
|
|
|
+ const hasBorder = cells.some((cell) => {
|
|
|
const cellStyle = cell.getAttribute("style");
|
|
|
// 如果单元格没有style属性,视为无边框
|
|
|
if (!cellStyle) {
|
|
|
return false;
|
|
|
}
|
|
|
// 检查是否存在任何边框相关的样式
|
|
|
- return /border(?:-(top|right|bottom|left))?:\s*[^;]*[1-9]/.test(cellStyle);
|
|
|
+ return /border(?:-(top|right|bottom|left))?:\s*[^;]*[1-9]/.test(
|
|
|
+ cellStyle
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
if (hasBorder) {
|
|
@@ -1727,9 +1730,9 @@ export default {
|
|
|
break;
|
|
|
case "pdf-to-word": // 添加新的命令类型
|
|
|
const pdfResult = await this.exportToPDF_url(row);
|
|
|
- if (pdfResult && pdfResult.file_path) {
|
|
|
+ /* if (pdfResult && pdfResult.file_path) {
|
|
|
await this.convertPDFToWord(pdfResult.file_path);
|
|
|
- }
|
|
|
+ } */
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
@@ -1806,7 +1809,7 @@ export default {
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
- ${processImages(contentContainer.innerHTML)}
|
|
|
+ ${this.processImages(contentContainer.innerHTML)}
|
|
|
</body>
|
|
|
</html>`;
|
|
|
|
|
@@ -1814,17 +1817,37 @@ export default {
|
|
|
contentData = contentData
|
|
|
.replaceAll("<table ", `<table style="border-collapse: collapse;" `)
|
|
|
.replaceAll("<td>", `<td style="border: 1px solid black;">`); */
|
|
|
-
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("content", contentData);
|
|
|
+ formData.append("title", template.title);
|
|
|
// 调用导出接口,指定导出类型为 PDF
|
|
|
- const res = await exportToPDF({
|
|
|
+ const res = await axios.post(
|
|
|
+ `${process.env.VUE_APP_BASE_API}/document/htmlPDFWord`,
|
|
|
+ formData,
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ "Content-Type": "multipart/form-data", // 设置请求头为form-data
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ); /* await htmlPDFWord({
|
|
|
content: contentData,
|
|
|
title: template.title,
|
|
|
- });
|
|
|
+ }); */
|
|
|
|
|
|
if (res.status !== 200) {
|
|
|
this.$alert(res.errMsg);
|
|
|
return;
|
|
|
}
|
|
|
+ console.log(res)
|
|
|
+ // 处理文件下载
|
|
|
+ const link = document.createElement("a");
|
|
|
+ link.href = res.data.data.file_path;
|
|
|
+ link.download = res.data.data.file_name;
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+
|
|
|
+ this.$message.success("导出成功");
|
|
|
|
|
|
// 处理文件下载
|
|
|
return res.data; // 返回结果,包含 file_path
|
|
@@ -1906,7 +1929,7 @@ export default {
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
- ${processImages(contentContainer.innerHTML)}
|
|
|
+ ${this.processImages(contentContainer.innerHTML)}
|
|
|
</body>
|
|
|
</html>`;
|
|
|
|
|
@@ -1943,42 +1966,42 @@ export default {
|
|
|
},
|
|
|
// 添加处理图片的辅助方法
|
|
|
processImages(content) {
|
|
|
- const tempDiv = document.createElement('div');
|
|
|
+ const tempDiv = document.createElement("div");
|
|
|
tempDiv.innerHTML = content;
|
|
|
-
|
|
|
+
|
|
|
// 处理所有图片
|
|
|
- tempDiv.querySelectorAll('img').forEach(img => {
|
|
|
+ tempDiv.querySelectorAll("img").forEach((img) => {
|
|
|
// 保存原始宽高属性
|
|
|
- const originalWidth = img.getAttribute('width');
|
|
|
- const originalHeight = img.getAttribute('height');
|
|
|
-
|
|
|
+ const originalWidth = img.getAttribute("width");
|
|
|
+ const originalHeight = img.getAttribute("height");
|
|
|
+
|
|
|
// 创建图片容器
|
|
|
- const container = document.createElement('div');
|
|
|
- container.className = 'image-container';
|
|
|
-
|
|
|
+ const container = document.createElement("div");
|
|
|
+ container.className = "image-container";
|
|
|
+
|
|
|
// 设置图片样式
|
|
|
- img.style.maxWidth = '100%';
|
|
|
- img.style.height = 'auto';
|
|
|
-
|
|
|
+ img.style.maxWidth = "100%";
|
|
|
+ img.style.height = "auto";
|
|
|
+
|
|
|
// 如果有原始尺寸,使用原始尺寸(但确保不超过页面宽度)
|
|
|
if (originalWidth && originalHeight) {
|
|
|
const aspectRatio = originalWidth / originalHeight;
|
|
|
const maxWidth = 595; // A4纸宽度(像素,减去边距)
|
|
|
-
|
|
|
+
|
|
|
if (originalWidth > maxWidth) {
|
|
|
- img.style.width = maxWidth + 'px';
|
|
|
- img.style.height = (maxWidth / aspectRatio) + 'px';
|
|
|
+ img.style.width = maxWidth + "px";
|
|
|
+ img.style.height = maxWidth / aspectRatio + "px";
|
|
|
} else {
|
|
|
- img.style.width = originalWidth + 'px';
|
|
|
- img.style.height = originalHeight + 'px';
|
|
|
+ img.style.width = originalWidth + "px";
|
|
|
+ img.style.height = originalHeight + "px";
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 将图片包装在容器中
|
|
|
img.parentNode.insertBefore(container, img);
|
|
|
container.appendChild(img);
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return tempDiv.innerHTML;
|
|
|
},
|
|
|
},
|