Browse Source

抽出64转file

lifanagju_citu 5 tháng trước cách đây
mục cha
commit
aa8ef41e5f
2 tập tin đã thay đổi với 17 bổ sung14 xóa
  1. 1 1
      src/utils/dealData.js
  2. 16 13
      src/utils/index.js

+ 1 - 1
src/utils/dealData.js

@@ -46,4 +46,4 @@ export const findFirstDuplicateWithIndices = (arr) => {
   }
   // 如果没有找到重复元素,返回 null 或其他表示未找到的值
   return null;
-}
+}

+ 16 - 13
src/utils/index.js

@@ -57,21 +57,24 @@ export const generateUUID = () => {
   return uuid.replace(/-/g, "")
 }
 
-export const downloadBase64 = (content, fileName) => {
-  const base64ToBlob = function (code) {
-    let parts = code.split(';base64,')
-    let contentType = parts[0].split(':')[1]
-    let raw = window.atob(parts[1])
-    let rawLength = raw.length
-    let uInt8Array = new Uint8Array(rawLength)
-    for (let i = 0; i < rawLength; ++i) {
-      uInt8Array[i] = raw.charCodeAt(i)
-    }
 
-    return new Blob([uInt8Array], {
-      type: contentType
-    })
+// 64转file
+export const base64ToBlob = (code) => {
+  let parts = code.split(';base64,')
+  let contentType = parts[0].split(':')[1]
+  let raw = window.atob(parts[1])
+  let rawLength = raw.length
+  let uInt8Array = new Uint8Array(rawLength)
+  for (let i = 0; i < rawLength; ++i) {
+    uInt8Array[i] = raw.charCodeAt(i)
   }
+
+  return new Blob([uInt8Array], {
+    type: contentType
+  })
+}
+
+export const downloadBase64 = (content, fileName) => {
   let aLink = document.createElement('a')
   let blob = base64ToBlob(content)
   aLink.download = fileName + '.png'