浏览代码

兼容高密度设备

bill 2 年之前
父节点
当前提交
f0b8f15fb9
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 3 2
      src/store/sync.ts
  2. 15 0
      src/utils/index.ts

+ 3 - 2
src/store/sync.ts

@@ -6,7 +6,7 @@ import {fixPoints} from "@/store/fixPoint";
 import {photos} from "@/store/photos";
 import {photos} from "@/store/photos";
 import {accidentPhotos} from "@/store/accidentPhotos";
 import {accidentPhotos} from "@/store/accidentPhotos";
 import {roadPhotos} from "@/store/roadPhotos";
 import {roadPhotos} from "@/store/roadPhotos";
-import {debounce, getId} from '@/utils'
+import {blobToBase64, debounce, getId} from '@/utils'
 import {watch} from "vue";
 import {watch} from "vue";
 import {params} from "@/hook";
 import {params} from "@/hook";
 import router, {writeRouteName} from "@/router";
 import router, {writeRouteName} from "@/router";
@@ -34,7 +34,8 @@ export const api = import.meta.env.DEV && !global.android
         window.open(URL.createObjectURL(file))
         window.open(URL.createObjectURL(file))
       },
       },
       async getFile(url) {
       async getFile(url) {
-        return baseURL + url
+        const data = await axios.get(url,{responseType:'blob'})
+        return blobToBase64(data.data)
       },
       },
       async closePage() {
       async closePage() {
         return router.push({ name: writeRouteName.scene })
         return router.push({ name: writeRouteName.scene })

+ 15 - 0
src/utils/index.ts

@@ -526,6 +526,21 @@ export const base64ToBlob = (base64Data: string) => {
   });
   });
 };
 };
 
 
+export const blobToBase64 = (blob: Blob) => {
+  return new Promise((resolve, reject) => {
+    const fileReader = new FileReader();
+    fileReader.onload = (e) => {
+      resolve(e.target.result);
+    };
+    // readAsDataURL
+    fileReader.readAsDataURL(blob);
+    fileReader.onerror = () => {
+      reject(new Error('blobToBase64 error'));
+    };
+  });
+}
+
+
 
 
 export const getId = () => {
 export const getId = () => {
   return (new Date()).getTime().toString() + Math.ceil(Math.random() * 1000).toString()
   return (new Date()).getTime().toString() + Math.ceil(Math.random() * 1000).toString()