|
@@ -51,6 +51,9 @@ export const api = !global.android
|
|
|
window.open(URL.createObjectURL(file));
|
|
|
return true;
|
|
|
},
|
|
|
+ async shareImage(filename: string) {
|
|
|
+ await window.open(await api.getFile(filename));
|
|
|
+ },
|
|
|
async getFile(url) {
|
|
|
if (url.includes(baseURL)) {
|
|
|
url = url.substring(baseURL.length);
|
|
@@ -91,6 +94,17 @@ export const api = !global.android
|
|
|
},
|
|
|
}
|
|
|
: {
|
|
|
+ shareImage(filename: string) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ console.log("shareImage", filename);
|
|
|
+ global.shareImageCallback = (data) => {
|
|
|
+ console.log("shareImage返回", data);
|
|
|
+ delete global.shareImageCallback;
|
|
|
+ resolve(data);
|
|
|
+ };
|
|
|
+ global.android.shareImage(filename, "shareImageCallback");
|
|
|
+ });
|
|
|
+ },
|
|
|
setStore(data) {
|
|
|
return new Promise((resolve) => {
|
|
|
console.log("调用setSceneStore参数", JSON.stringify(data));
|
|
@@ -112,19 +126,14 @@ export const api = !global.android
|
|
|
console.log("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) {
|
|
|
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;
|
|
@@ -142,10 +151,7 @@ export const api = !global.android
|
|
|
return await new Promise<string>((resolve) => {
|
|
|
const apiName = `getImageCallback${count++}`;
|
|
|
global[apiName] = (base64) => {
|
|
|
- console.error(
|
|
|
- "请求url:" + fileUrl,
|
|
|
- "返回:" + base64.substring(0, 60)
|
|
|
- );
|
|
|
+ console.error("请求url:" + fileUrl, "返回:" + base64.substring(0, 60));
|
|
|
resolve(URL.createObjectURL(base64ToBlob(base64)));
|
|
|
delete global[apiName];
|
|
|
};
|
|
@@ -245,15 +251,12 @@ const loadStore = async () => {
|
|
|
};
|
|
|
|
|
|
export const updateSceneStore = debounce(api.setStore, 300);
|
|
|
-export const uploadImage = (blob: Blob) => {
|
|
|
- const file = new File([blob], `${getId()}.jpg`);
|
|
|
+export const uploadImage = (blob: Blob, name = `${getId()}.jpg`) => {
|
|
|
+ const file = new File([blob], name);
|
|
|
return api.uploadImage(file);
|
|
|
};
|
|
|
|
|
|
-export const downloadImage = async (
|
|
|
- data: Blob | string,
|
|
|
- name: string = getId()
|
|
|
-) => {
|
|
|
+export const downloadImage = async (data: Blob | string, name: string = getId()) => {
|
|
|
const blob: Blob =
|
|
|
typeof data === "string"
|
|
|
? (await axios.get(data, { responseType: "blob" })).data
|
|
@@ -282,34 +285,6 @@ const syncSceneStore = () => {
|
|
|
{ deep: true }
|
|
|
);
|
|
|
};
|
|
|
-//
|
|
|
-// // 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) => {
|
|
|
console.error(e);
|