|
@@ -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 {blobToBase64, debounce, getId} from "@/utils";
|
|
|
|
|
|
+import {base64ToBlob, 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";
|
|
@@ -40,17 +40,22 @@ export const api =
|
|
return true;
|
|
return true;
|
|
},
|
|
},
|
|
async getFile(url) {
|
|
async getFile(url) {
|
|
- // console.error(url, baseURL)
|
|
|
|
- //
|
|
|
|
- // return url.includes(baseURL) ? url : (baseURL + url.trim());
|
|
|
|
-
|
|
|
|
if (url.includes(baseURL)) {
|
|
if (url.includes(baseURL)) {
|
|
url = url.substring(baseURL.length);
|
|
url = url.substring(baseURL.length);
|
|
}
|
|
}
|
|
url = url.trim();
|
|
url = url.trim();
|
|
- const data = await axios.get(url, { responseType: "blob" });
|
|
|
|
- const base64 = await blobToBase64(data.data);
|
|
|
|
- return base64
|
|
|
|
|
|
+ const paths = url.split("/")
|
|
|
|
+ const notBase64BaseTypes = [
|
|
|
|
+ ".png", ".jpg", ".bin"
|
|
|
|
+ ]
|
|
|
|
+ const notBase64 = notBase64BaseTypes.some(type => paths[paths.length - 1].includes(type))
|
|
|
|
+ if (notBase64) {
|
|
|
|
+ return baseURL + url
|
|
|
|
+ } else {
|
|
|
|
+ const data = await axios.get(url, { responseType: "blob" });
|
|
|
|
+ const base64 = await blobToBase64(data.data);
|
|
|
|
+ return URL.createObjectURL(base64ToBlob(base64))
|
|
|
|
+ }
|
|
},
|
|
},
|
|
async closePage() {
|
|
async closePage() {
|
|
return router.push({ name: writeRouteName.scene });
|
|
return router.push({ name: writeRouteName.scene });
|
|
@@ -88,18 +93,19 @@ export const api =
|
|
}
|
|
}
|
|
fileUrl = new URL(fileUrl, "http://www.a.com").pathname
|
|
fileUrl = new URL(fileUrl, "http://www.a.com").pathname
|
|
fileUrl = (params.realPath || params.m) + fileUrl
|
|
fileUrl = (params.realPath || params.m) + fileUrl
|
|
- console.error("处理后url:" + fileUrl)
|
|
|
|
|
|
|
|
const paths = fileUrl.split("/")
|
|
const paths = fileUrl.split("/")
|
|
- const notBase64 = paths[paths.length - 1].includes(".png") ||
|
|
|
|
- paths[paths.length - 1].includes(".jpg")
|
|
|
|
|
|
+ const notBase64BaseTypes = [
|
|
|
|
+ ".png", ".jpg", ".bin"
|
|
|
|
+ ]
|
|
|
|
+ const notBase64 = notBase64BaseTypes.some(type => paths[paths.length - 1].includes(type))
|
|
|
|
|
|
- if (import.meta.env.DEV || !notBase64) {
|
|
|
|
|
|
+ if (!notBase64) {
|
|
return await new Promise<string>((resolve) => {
|
|
return await new Promise<string>((resolve) => {
|
|
const apiName = `getImageCallback${count++}`
|
|
const apiName = `getImageCallback${count++}`
|
|
global[apiName] = (base64) => {
|
|
global[apiName] = (base64) => {
|
|
console.error("请求url:" + fileUrl, "返回:" + base64.substring(0, 60))
|
|
console.error("请求url:" + fileUrl, "返回:" + base64.substring(0, 60))
|
|
- resolve(base64);
|
|
|
|
|
|
+ resolve(URL.createObjectURL(base64ToBlob(base64)));
|
|
delete global[apiName]
|
|
delete global[apiName]
|
|
};
|
|
};
|
|
global.android.getImage(fileUrl, apiName);
|
|
global.android.getImage(fileUrl, apiName);
|
|
@@ -166,7 +172,7 @@ const loadStore = async () => {
|
|
console.log("开始同步syncSceneStore")
|
|
console.log("开始同步syncSceneStore")
|
|
};
|
|
};
|
|
|
|
|
|
-export const updateSceneStore = debounce(api.setStore, 1000);
|
|
|
|
|
|
+export const updateSceneStore = debounce(api.setStore, 300);
|
|
export const uploadImage = (blob: Blob) => {
|
|
export const uploadImage = (blob: Blob) => {
|
|
const file = new File([blob], `${getId()}.jpg`);
|
|
const file = new File([blob], `${getId()}.jpg`);
|
|
return api.uploadImage(file);
|
|
return api.uploadImage(file);
|
|
@@ -204,19 +210,34 @@ const syncSceneStore = () => {
|
|
{ deep: true }
|
|
{ deep: true }
|
|
);
|
|
);
|
|
};
|
|
};
|
|
-
|
|
|
|
-if (global.android) {
|
|
|
|
- document.documentElement.addEventListener('focusin', ev => {
|
|
|
|
- console.log("获得焦点")
|
|
|
|
- console.log(ev.target)
|
|
|
|
- global.android.inputMethodManager(true);
|
|
|
|
- })
|
|
|
|
- document.documentElement.addEventListener('focusout', ev => {
|
|
|
|
- console.log("失去焦点")
|
|
|
|
- console.log(ev.target)
|
|
|
|
- global.android.inputMethodManager(false);
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+//
|
|
|
|
+// // if (global.android) {
|
|
|
|
+// const isEditInput = (dom: HTMLElement) => {
|
|
|
|
+// const tagName = dom.tagName.toUpperCase();
|
|
|
|
+// const isInput = tagName === "INPUT"
|
|
|
|
+// const isTextarea = tagName === "TEXTAREA"
|
|
|
|
+// console.log(isInput && dom.getAttribute("type") === "text")
|
|
|
|
+// if (!(isInput && dom.getAttribute("type") === "text") && !isTextarea) {
|
|
|
|
+// return false;
|
|
|
|
+// }
|
|
|
|
+// console.log("???")
|
|
|
|
+// return !dom.hasAttribute("readonly")
|
|
|
|
+// }
|
|
|
|
+// document.documentElement.addEventListener('focusin', ev => {
|
|
|
|
+// console.log("获得焦点")
|
|
|
|
+// console.log(ev.target)
|
|
|
|
+// if (isEditInput(ev.target as HTMLElement)) {
|
|
|
|
+// global.android.inputMethodManager(true);
|
|
|
|
+// }
|
|
|
|
+// })
|
|
|
|
+// document.documentElement.addEventListener('focusout', ev => {
|
|
|
|
+// console.log("失去焦点")
|
|
|
|
+// console.log(ev.target)
|
|
|
|
+// if (isEditInput(ev.target as HTMLElement)) {
|
|
|
|
+// global.android.inputMethodManager(false);
|
|
|
|
+// }
|
|
|
|
+// })
|
|
|
|
+// // }
|
|
|
|
|
|
loadStore().catch((e) => {
|
|
loadStore().catch((e) => {
|
|
console.error(e);
|
|
console.error(e);
|