浏览代码

数据本地化

jinx 1 年之前
父节点
当前提交
cd86efb24b
共有 1 个文件被更改,包括 10 次插入33 次删除
  1. 10 33
      src/store/sync.ts

+ 10 - 33
src/store/sync.ts

@@ -63,9 +63,7 @@ export const api = !global.android
         url = url.trim();
         const paths = url.split("/");
         const notBase64BaseTypes = [".png", ".jpg"];
-        const notBase64 = notBase64BaseTypes.some((type) =>
-          paths[paths.length - 1].includes(type)
-        );
+        const notBase64 = notBase64BaseTypes.some((type) => paths[paths.length - 1].includes(type));
         if (notBase64) {
           // await new Promise((resolve) => setTimeout(resolve, 2000));
           return baseURL + url;
@@ -110,11 +108,7 @@ export const api = !global.android
           global.setSceneStoreCallback = (data) => {
             resolve(data);
           };
-          global.android.setSceneStore(
-            params.m + "/store.json",
-            JSON.stringify(data),
-            "setSceneStoreCallback"
-          );
+          global.android.setSceneStore(params.m + "/store.json", JSON.stringify(data), "setSceneStoreCallback");
         });
       },
       getStore() {
@@ -139,9 +133,7 @@ export const api = !global.android
           // ".png", ".jpg"
           // , ".bin"
         ];
-        const notBase64 = notBase64BaseTypes.some((type) =>
-          paths[paths.length - 1].includes(type)
-        );
+        const notBase64 = notBase64BaseTypes.some((type) => paths[paths.length - 1].includes(type));
 
         if (!notBase64) {
           return await new Promise<string>((resolve) => {
@@ -165,11 +157,7 @@ export const api = !global.android
             delete global[apiName];
           };
           const data = await blobToBase64(file);
-          global.android.uploadImage(
-            params.m + "/attach/upload/" + file.name,
-            data,
-            apiName
-          );
+          global.android.uploadImage(params.m + "/attach/upload/" + file.name, data, apiName);
         });
       },
       downloadImage(file: File) {
@@ -188,11 +176,7 @@ export const api = !global.android
         return new Promise<string>((resolve) => {
           const apiName = `photograph${count++}`;
           global[apiName] = (data) => {
-            data
-              ? rotate
-                ? normalImage(data).then(resolve)
-                : resolve(data)
-              : resolve(null);
+            data ? (rotate ? normalImage(data).then(resolve) : resolve(data)) : resolve(null);
             delete global[apiName];
           };
           global.android.cameraPhotograph(params.m, apiName);
@@ -202,11 +186,7 @@ export const api = !global.android
         return new Promise<string>((resolve) => {
           const apiName = `selectPhotoAlbum${count++}`;
           global[apiName] = (data) => {
-            data
-              ? rotate
-                ? normalImage(data).then(resolve)
-                : resolve(data)
-              : resolve(null);
+            data ? (rotate ? normalImage(data).then(resolve) : resolve(data)) : resolve(null);
             delete global[apiName];
           };
           global.android.selectPhotoAlbum(params.m, apiName);
@@ -235,8 +215,8 @@ const loadStore = async () => {
   accidentPhotos.value = data?.accidentPhotos || [];
   roadPhotos.value = data?.roadPhotos || [];
   uses.value = data?.uses || defaultUses;
-  tables.value = data?.tables || null;
-  
+  tables.value = data?.tables || {};
+
   syncSceneStore();
 };
 
@@ -247,10 +227,7 @@ export const uploadImage = (blob: Blob, name = `${getId()}.jpg`) => {
 };
 
 export const downloadImage = async (data: Blob | string, name = `${getId()}.jpg`) => {
-  const blob: Blob =
-    typeof data === "string"
-      ? (await axios.get(data, { responseType: "blob" })).data
-      : data;
+  const blob: Blob = typeof data === "string" ? (await axios.get(data, { responseType: "blob" })).data : data;
   const file = new File([blob], name, { type: "image/jpeg" });
 
   return await api.downloadImage(file);
@@ -268,7 +245,7 @@ const syncSceneStore = () => {
       uses: uses.value,
       accidentPhotos: accidentPhotos.value,
       roadPhotos: roadPhotos.value,
-      tables : tables.value,
+      tables: tables.value,
     }),
     (data) => {
       updateSceneStore(data);