Pārlūkot izejas kodu

添加pdf转word

yangg 6 mēneši atpakaļ
vecāks
revīzija
12a9f4fd48

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/index.html


+ 0 - 0
dist/static/css/chunk-58cde076.6ad25138.css → dist/static/css/chunk-48f27aa5.6ad25138.css


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/css/chunk-603868e3.ef10ade3.css


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/js/app.0251da54.js


+ 0 - 0
dist/static/js/chunk-0074d5fe.96e6dcd9.js → dist/static/js/chunk-0074d5fe.71bef035.js


+ 0 - 0
dist/static/js/chunk-138f7583.39386086.js → dist/static/js/chunk-138f7583.6fdbaed8.js


+ 0 - 0
dist/static/js/chunk-143f34d0.d98c71f9.js → dist/static/js/chunk-143f34d0.45cedec0.js


+ 0 - 0
dist/static/js/chunk-194e2959.d6320bd6.js → dist/static/js/chunk-194e2959.e8a774bf.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/js/chunk-48f27aa5.3126eb16.js


+ 0 - 0
dist/static/js/chunk-4ac7f82e.13997463.js → dist/static/js/chunk-4ac7f82e.d7acc3d1.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/js/chunk-548e1b57.9b37fb06.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/js/chunk-58cde076.c35a5481.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/static/js/chunk-603868e3.bf81a673.js


+ 0 - 0
dist/static/js/chunk-77486988.59b884d2.js → dist/static/js/chunk-77486988.9b244a9e.js


+ 0 - 0
dist/static/js/chunk-9235c1ae.facbc646.js → dist/static/js/chunk-9235c1ae.608f0d76.js


+ 0 - 0
dist/static/js/chunk-dfd55446.dd1bde95.js → dist/static/js/chunk-dfd55446.8fa96974.js


+ 12 - 1
src/api/document.js

@@ -172,4 +172,15 @@ export function htmlWordNew(data) {
     method: 'post',
     data
   })
-}
+}
+
+
+/* pdf转word */
+
+export function htmlPDFWord(data) {
+  return request({
+    url: '/document/htmlPDFWord',
+    method: 'post',
+    data
+  })
+}

+ 55 - 32
src/views/project/components/dataList.vue

@@ -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;
     },
   },

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels