|
@@ -19,6 +19,17 @@ import { drawSetting } from "./drawSetting";
|
|
|
|
|
|
const global = window as any;
|
|
|
|
|
|
+const getFilesIng = [];
|
|
|
+const getFilesSuccess = [];
|
|
|
+setInterval(() => {
|
|
|
+ console.log(
|
|
|
+ "请求资源数:" + getFilesIng.length,
|
|
|
+ "响应结果数:" + getFilesSuccess.length
|
|
|
+ );
|
|
|
+ console.log(
|
|
|
+ "未返回资源:" + getFilesIng.filter((url) => !getFilesSuccess.includes(url))
|
|
|
+ );
|
|
|
+}, 1000);
|
|
|
const normalImage = async (url: string) => {
|
|
|
const getUrl = await api.getFile(url);
|
|
|
const blob = await imageRotate(getUrl);
|
|
@@ -29,7 +40,11 @@ const normalImage = async (url: string) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-let count = 0;
|
|
|
+console.log("进入初始化sync count为" + global.count);
|
|
|
+if (!global.count) {
|
|
|
+ global.count = 0;
|
|
|
+}
|
|
|
+
|
|
|
export const api = !global.android
|
|
|
? // true
|
|
|
// const api = import.meta.env.DEV
|
|
@@ -58,19 +73,26 @@ export const api = !global.android
|
|
|
await window.open(await api.getFile(filename));
|
|
|
},
|
|
|
async getFile(url) {
|
|
|
+ const urlRaw = url;
|
|
|
+ getFilesIng.push(urlRaw);
|
|
|
+
|
|
|
if (url.includes(baseURL)) {
|
|
|
url = url.substring(baseURL.length);
|
|
|
}
|
|
|
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) {
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
// await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
return baseURL + url;
|
|
|
} else {
|
|
|
const data = await axios.get(url, { responseType: "blob" });
|
|
|
const base64 = await blobToBase64(data.data);
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
return URL.createObjectURL(base64ToBlob(base64));
|
|
|
}
|
|
|
},
|
|
@@ -109,7 +131,11 @@ 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() {
|
|
@@ -117,14 +143,21 @@ export const api = !global.android
|
|
|
global.getSceneStoreCallback = (data) => {
|
|
|
resolve(data);
|
|
|
};
|
|
|
- global.android.getSceneStore(params.m + "/store.json", "getSceneStoreCallback");
|
|
|
+ global.android.getSceneStore(
|
|
|
+ params.m + "/store.json",
|
|
|
+ "getSceneStoreCallback"
|
|
|
+ );
|
|
|
});
|
|
|
},
|
|
|
// genUseLoading()
|
|
|
async getFile(fileUrl: string) {
|
|
|
+ const urlRaw = fileUrl;
|
|
|
+ getFilesIng.push(urlRaw);
|
|
|
fileUrl = fileUrl.trim();
|
|
|
if (fileUrl.includes(params.m)) {
|
|
|
- fileUrl = fileUrl.substring(fileUrl.indexOf(params.m) + params.m.length);
|
|
|
+ fileUrl = fileUrl.substring(
|
|
|
+ fileUrl.indexOf(params.m) + params.m.length
|
|
|
+ );
|
|
|
}
|
|
|
fileUrl = new URL(fileUrl, "http://www.a.com").pathname;
|
|
|
fileUrl = (params.realPath || params.m) + fileUrl;
|
|
@@ -134,36 +167,43 @@ 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) => {
|
|
|
- const apiName = `getImageCallback${count++}`;
|
|
|
+ const apiName = `getImageCallback${global.count++}`;
|
|
|
global[apiName] = (base64) => {
|
|
|
- console.error("请求url:" + fileUrl, "返回:" + base64.substring(0, 60));
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
resolve(URL.createObjectURL(base64ToBlob(base64)));
|
|
|
delete global[apiName];
|
|
|
};
|
|
|
global.android.getImage(fileUrl, apiName);
|
|
|
});
|
|
|
} else {
|
|
|
+ getFilesSuccess.push(urlRaw);
|
|
|
return fileUrl;
|
|
|
}
|
|
|
},
|
|
|
uploadImage(file: File) {
|
|
|
return new Promise<string>(async (resolve) => {
|
|
|
- const apiName = `uploadImageCallback${count++}`;
|
|
|
+ const apiName = `uploadImageCallback${global.count++}`;
|
|
|
global[apiName] = (data) => {
|
|
|
resolve(data);
|
|
|
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) {
|
|
|
return new Promise<boolean>(async (resolve) => {
|
|
|
- const apiName = `downloadImageCallback${count++}`;
|
|
|
+ const apiName = `downloadImageCallback${global.count++}`;
|
|
|
global[apiName] = () => {
|
|
|
resolve(true);
|
|
|
delete global[apiName];
|
|
@@ -175,9 +215,13 @@ export const api = !global.android
|
|
|
},
|
|
|
photograph(rotate = true) {
|
|
|
return new Promise<string>((resolve) => {
|
|
|
- const apiName = `photograph${count++}`;
|
|
|
+ const apiName = `photograph${global.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);
|
|
@@ -185,9 +229,13 @@ export const api = !global.android
|
|
|
},
|
|
|
selectPhotoAlbum(rotate = true) {
|
|
|
return new Promise<string>((resolve) => {
|
|
|
- const apiName = `selectPhotoAlbum${count++}`;
|
|
|
+ const apiName = `selectPhotoAlbum${global.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);
|
|
@@ -218,7 +266,7 @@ const loadStore = async () => {
|
|
|
uses.value = data?.uses || defaultUses;
|
|
|
tables.value = data?.tables || {};
|
|
|
drawSetting.value = data?.drawSetting || {};
|
|
|
-
|
|
|
+
|
|
|
syncSceneStore();
|
|
|
};
|
|
|
|
|
@@ -228,8 +276,14 @@ export const uploadImage = (blob: Blob, name = `${getId()}.jpg`) => {
|
|
|
return api.uploadImage(file);
|
|
|
};
|
|
|
|
|
|
-export const downloadImage = async (data: Blob | string, name = `${getId()}.jpg`) => {
|
|
|
- const blob: Blob = typeof data === "string" ? (await axios.get(data, { responseType: "blob" })).data : data;
|
|
|
+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 file = new File([blob], name, { type: "image/jpeg" });
|
|
|
|
|
|
return await api.downloadImage(file);
|