From 66b3c4c129b05b634d37ac7eac63eff0f0b9f426 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 27 二月 2025 10:11:52 +0800
Subject: [PATCH] 修改体系管理要求bug

---
 src/utils/file.js |   69 ++++++++++++++++++++++------------
 1 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/src/utils/file.js b/src/utils/file.js
index c3a3e7b..9c7e99e 100644
--- a/src/utils/file.js
+++ b/src/utils/file.js
@@ -1,48 +1,55 @@
-import { convertToHtml } from 'mammoth';
-import Vue from 'vue'
+import { convertToHtml } from "mammoth";
+import pako from "pako";
+import Vue from "vue";
 
 export default {
   async convertFileToHtml(url) {
     var xhr = new XMLHttpRequest();
-    xhr.open('GET', Vue.prototype.javaApi+url, true);//鑾峰彇鏂囦欢娴佺殑鎺ュ彛
+    xhr.open("GET", Vue.prototype.javaApi + url, true); //鑾峰彇鏂囦欢娴佺殑鎺ュ彛
     xhr.send();
-    xhr.responseType = "blob";//涓嶈兘婕�
+    xhr.responseType = "blob"; //涓嶈兘婕�
     let xhrPromise = new Promise((resolve, reject) => {
       xhr.onload = async function () {
         if (this.status === 200) {
           // 杩斿洖鐨勬枃浠舵祦锛岃浆鎹㈡垚blob瀵硅薄
-          var blob = new Blob([this.response],{ type:'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
+          var blob = new Blob([this.response], {
+            type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+          });
           // 浣跨敤mammoth灏哤ord杞崲涓篐TML
           let reader = new FileReader();
           reader.readAsArrayBuffer(blob);
           let htmlContentPromise = new Promise((resolve, reject) => {
             reader.onload = async function () {
               var arrayBuffer = xhr.response; //arrayBuffer
-              const result = await convertToHtml({ arrayBuffer: arrayBuffer })
-              let html = result.value.replace(/飪�/g, '')
-              .replace('<h1>', '<h1 style="text-align: center;">')
-              .replace(/<table>/g, '<table style="border-collapse: collapse;border: 1px solid #000;">')
-              .replace(/<tr>/g, '<tr style="height: 30px;">')
-              .replace(/<td>/g, '<td style="border: 1px solid #000;">')
-              .replace(/<p>/g, '<p style="text-indent: 2em;">')
-              .replace(/<a [^>]*>/g, "")
-              .replace(/<\/a>/g, "")
+              const result = await convertToHtml({ arrayBuffer: arrayBuffer });
+              let html = result.value
+                .replace(/飪�/g, "")
+                .replace("<h1>", '<h1 style="text-align: center;">')
+                .replace(
+                  /<table>/g,
+                  '<table style="border-collapse: collapse;border: 1px solid #000;">'
+                )
+                .replace(/<tr>/g, '<tr style="height: 30px;">')
+                .replace(/<td>/g, '<td style="border: 1px solid #000;">')
+                .replace(/<p>/g, '<p style="text-indent: 2em;">')
+                .replace(/<a [^>]*>/g, "")
+                .replace(/<\/a>/g, "");
               // .replace(/em/g, "cm");
-              resolve(html)
+              resolve(html);
             };
-          })
-          resolve(await htmlContentPromise)
+          });
+          resolve(await htmlContentPromise);
         }
-
-      }
-    })
-    return await xhrPromise
+      };
+    });
+    return await xhrPromise;
   },
-  downloadIamge(imgsrc, name) {//涓嬭浇鍥剧墖鍦板潃鍜屽浘鐗囧悕
+  downloadIamge(imgsrc, name) {
+    //涓嬭浇鍥剧墖鍦板潃鍜屽浘鐗囧悕
     var image = new Image();
     // 瑙e喅璺ㄥ煙 Canvas 姹℃煋闂
     image.setAttribute("crossOrigin", "anonymous");
-    image.onload = function() {
+    image.onload = function () {
       var canvas = document.createElement("canvas");
       canvas.width = image.width;
       canvas.height = image.height;
@@ -57,5 +64,19 @@
       a.dispatchEvent(event); // 瑙﹀彂a鐨勫崟鍑讳簨浠�
     };
     image.src = imgsrc;
-  }
+  },
+  // 鍘嬬缉blob
+  compressBlob(blob) {
+    const reader = new FileReader();
+    reader.readAsArrayBuffer(blob);
+    return new Promise((resolve) => {
+      reader.onload = () => {
+        const arrayBuffer = reader.result;
+        const uint8Array = new Uint8Array(arrayBuffer);
+        const compressedData = pako.deflate(uint8Array);
+        const compressedBlob = new Blob([compressedData], { type: blob.type });
+        resolve(compressedBlob);
+      };
+    });
+  },
 };

--
Gitblit v1.9.3