From e47c70d32e6fa7c9cb16ca19a79338ea36a83e94 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 10 六月 2025 16:38:37 +0800
Subject: [PATCH] fix: v1.4

---
 apps/taro/src/utils/file.ts |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/apps/taro/src/utils/file.ts b/apps/taro/src/utils/file.ts
index 34a5b36..c959ae4 100644
--- a/apps/taro/src/utils/file.ts
+++ b/apps/taro/src/utils/file.ts
@@ -86,3 +86,38 @@
     return fileName;
   });
 }
+
+export function downloadBase64File(base64Data: string, filename: string) {
+  // 灏哹ase64鏁版嵁鍒嗗壊锛岃幏鍙杕ime-type
+  const [, mime, b64data] = base64Data.match(/^data:([^;]+);base64,(.+)$/);
+
+  // 瑙g爜base64鏁版嵁
+  const byteString = atob(b64data);
+  const arrayBuffer = new ArrayBuffer(byteString.length);
+  const intArray = new Uint8Array(arrayBuffer);
+
+  for (let i = 0; i < byteString.length; i++) {
+    intArray[i] = byteString.charCodeAt(i);
+  }
+
+  // 鍒涘缓Blob瀵硅薄
+  const blob = new Blob([intArray], { type: mime });
+
+  //@ts-ignore
+  if (typeof navigator !== 'undefined' && navigator.msSaveOrOpenBlob) {
+    //@ts-ignore 鍏煎IE
+    navigator.msSaveOrOpenBlob(blob, filename);
+  } else {
+    // 鍒涘缓涓�涓复鏃剁殑a鏍囩鐢ㄤ簬瑙﹀彂涓嬭浇
+    const a = document.createElement('a');
+    const url = window.URL.createObjectURL(blob);
+    a.href = url;
+    a.download = filename; // 璁剧疆涓嬭浇鍚庣殑鏂囦欢鍚�
+    document.body.appendChild(a);
+    a.click(); // 瑙﹀彂涓嬭浇
+    document.body.removeChild(a);
+    setTimeout(() => {
+      window.URL.revokeObjectURL(url); // 娓呴櫎鍒涘缓鐨勫璞RL
+    }, 0);
+  }
+}

--
Gitblit v1.9.1