瀏覽代碼

Merge branch 'master' of http://173.18.12.196:3000/front/self-constructing_graph

yangdr 1 月之前
父節點
當前提交
665378a607
共有 1 個文件被更改,包括 19 次插入5 次删除
  1. 19 5
      src/dialogs/OCRDialog.vue

+ 19 - 5
src/dialogs/OCRDialog.vue

@@ -418,11 +418,25 @@ const handleRemove = (file: any, fileList: any) => {
 }
 
 async function calculateFileHash(file: File) {
-  const arrayBuffer = await file.arrayBuffer();
-  const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
-  const hashArray = Array.from(new Uint8Array(hashBuffer));
-  const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
-  return hashHex;
+  // const arrayBuffer = await file.arrayBuffer();
+  // const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
+  // const hashArray = Array.from(new Uint8Array(hashBuffer));
+  // const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
+  // return hashHex;
+    // 使用 crypto-js 计算哈希值
+  return new Promise((resolve, reject) => {
+    const reader = new FileReader();
+    reader.readAsArrayBuffer(file);
+    reader.onload = function (e) {
+      const arrayBuffer = e.target?.result;
+      const wordArray = CryptoJS.lib.WordArray.create(arrayBuffer);
+      const hashHex = CryptoJS.SHA256(wordArray).toString(CryptoJS.enc.hex);
+      resolve(hashHex);
+    };
+    reader.onerror = () => {
+      reject('');
+    };
+  });
 }
 
 function handleImportFiles(filesList: any[]) {