hotUpload
xingyy 1 month ago
parent d663d7e7c4
commit 98745b859b

@ -8,44 +8,34 @@ import {onExit } from "@dcloudio/uni-app";
import { Communication } from '../../utils/communication.js'; import { Communication } from '../../utils/communication.js';
const commun=new Communication() const commun=new Communication()
const permissionListener = uni.createRequestPermissionListener(); const permissionListener = uni.createRequestPermissionListener();
permissionListener.onRequest((e)=>{
console.log('APP执行onRequest',e)
commun.sendToH5('permission-application',e);
})
permissionListener.onConfirm((e) => {
});
permissionListener.onComplete((e) => {
console.log('APP执行onComplete',e)
const arr=['android.permission.ACCESS_COARSE_LOCATION','android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_LOCATION_EXTRA_COMMANDS','android.permission.ACCESS_MOCK_LOCATION']
commun.sendToH5('permission-complete',e);
})
onExit(()=>{ onExit(()=>{
permissionListener.stop() permissionListener.stop()
}) })
function initializeWebView() { function initializeWebView() {
const currentWebview = getCurrentPages().pop().$getAppWebview() const currentWebview = getCurrentPages().pop().$getAppWebview()
console.log('当前view',currentWebview)
commun.setWebView(currentWebview.children()[0]) commun.setWebView(currentWebview.children()[0])
} }
commun.registerHandler('load-complete',()=>{ commun.registerHandler('load-complete',()=>{
initializeWebView()
const {statusBarHeight} = uni.getSystemInfoSync()
commun.webViewObj.setStyle({
top: statusBarHeight,
bottom: 0,
})
permissionListener.onRequest((e)=>{
commun.sendToH5('permission-application',e);
})
permissionListener.onConfirm((e) => {
});
permissionListener.onComplete((e) => {
console.log('APP执行onComplete',e)
const arr=['android.permission.ACCESS_COARSE_LOCATION','android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_LOCATION_EXTRA_COMMANDS','android.permission.ACCESS_MOCK_LOCATION']
commun.sendToH5('permission-complete',e);
})
}) })
const webLoad = (e) => { const webLoad = (e) => {
try { const message = e.detail.data?.[0] || '';
const message = e.detail.data?.[0] || ''; commun.handleMessage(message);
if (message.action==='load-complete'){
initializeWebView()
const {statusBarHeight} = uni.getSystemInfoSync()
commun.webViewObj.setStyle({
top: statusBarHeight,
bottom: 0,
})
}else {
commun.handleMessage(message);
}
} catch (error) {
}
}; };
</script> </script>

@ -87,15 +87,11 @@ if (uni.restoreGlobal) {
this.messageHandlers[action] = handler; this.messageHandlers[action] = handler;
} }
handleMessage(message) { handleMessage(message) {
try { const { action, data = {} } = message;
const { action, data } = JSON.parse(message); if (this.messageHandlers[action]) {
if (this.messageHandlers[action]) { this.messageHandlers[action](data);
this.messageHandlers[action](data); } else {
} else { formatAppLog("warn", "at utils/communication.js:30", "Unknown action:", action);
formatAppLog("warn", "at utils/communication.js:31", "Unknown action:", action);
}
} catch (error2) {
formatAppLog("error", "at utils/communication.js:34", "Failed to handle message:", error2);
} }
} }
} }
@ -111,42 +107,34 @@ if (uni.restoreGlobal) {
setup(__props) { setup(__props) {
const commun = new Communication(); const commun = new Communication();
const permissionListener = uni.createRequestPermissionListener(); const permissionListener = uni.createRequestPermissionListener();
permissionListener.onRequest((e2) => {
formatAppLog("log", "at pages/index/index.vue:12", "APP执行onRequest", e2);
commun.sendToH5("permission-application", e2);
});
permissionListener.onConfirm((e2) => {
});
permissionListener.onComplete((e2) => {
formatAppLog("log", "at pages/index/index.vue:18", "APP执行onComplete", e2);
commun.sendToH5("permission-complete", e2);
});
onExit(() => { onExit(() => {
permissionListener.stop(); permissionListener.stop();
}); });
function initializeWebView() { function initializeWebView() {
const currentWebview = getCurrentPages().pop().$getAppWebview(); const currentWebview = getCurrentPages().pop().$getAppWebview();
formatAppLog("log", "at pages/index/index.vue:28", "当前view", currentWebview);
commun.setWebView(currentWebview.children()[0]); commun.setWebView(currentWebview.children()[0]);
} }
commun.registerHandler("load-complete", () => { commun.registerHandler("load-complete", () => {
initializeWebView();
const { statusBarHeight } = uni.getSystemInfoSync();
commun.webViewObj.setStyle({
top: statusBarHeight,
bottom: 0
});
permissionListener.onRequest((e2) => {
commun.sendToH5("permission-application", e2);
});
permissionListener.onConfirm((e2) => {
});
permissionListener.onComplete((e2) => {
formatAppLog("log", "at pages/index/index.vue:31", "APP执行onComplete", e2);
commun.sendToH5("permission-complete", e2);
});
}); });
const webLoad = (e2) => { const webLoad = (e2) => {
var _a; var _a;
try { const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || "";
const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || ""; commun.handleMessage(message);
if (message.action === "load-complete") {
initializeWebView();
const { statusBarHeight } = uni.getSystemInfoSync();
commun.webViewObj.setStyle({
top: statusBarHeight,
bottom: 0
});
} else {
commun.handleMessage(message);
}
} catch (error2) {
}
}; };
return (_ctx, _cache) => { return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("web-view", { return vue.openBlock(), vue.createElementBlock("web-view", {
@ -3206,7 +3194,7 @@ if (uni.restoreGlobal) {
function I(e2) { function I(e2) {
return e2 && "string" == typeof e2 ? JSON.parse(e2) : e2; return e2 && "string" == typeof e2 ? JSON.parse(e2) : e2;
} }
const S = true, b = "app", A = I(define_process_env_UNI_SECURE_NETWORK_CONFIG_default), C = b, P = I('{\n "address": [\n "127.0.0.1",\n "192.168.56.1",\n "192.168.88.56"\n ],\n "debugPort": 9001,\n "initialLaunchType": "local",\n "servePort": 7001,\n "skipFiles": [\n "<node_internals>/**",\n "C:/Users/37363/Downloads/HBuilderX.4.08.2024040127/HBuilderX/plugins/unicloud/**/*.js"\n ]\n}\n'), T = I('[{"provider":"alipay","spaceName":"oaapp","spaceId":"env-00jxgxphla18","spaceAppId":"2021004145628977","accessKey":"ZALus7EgJXdovISb","secretKey":"7qzvVrPN0mAxfcLr"}]') || []; const S = true, b = "app", A = I(define_process_env_UNI_SECURE_NETWORK_CONFIG_default), C = b, P = I('{\n "address": [\n "127.0.0.1",\n "192.168.56.1",\n "192.168.88.56"\n ],\n "debugPort": 9000,\n "initialLaunchType": "local",\n "servePort": 7000,\n "skipFiles": [\n "<node_internals>/**",\n "C:/Users/37363/Downloads/HBuilderX.4.08.2024040127/HBuilderX/plugins/unicloud/**/*.js"\n ]\n}\n'), T = I('[{"provider":"alipay","spaceName":"oaapp","spaceId":"env-00jxgxphla18","spaceAppId":"2021004145628977","accessKey":"ZALus7EgJXdovISb","secretKey":"7qzvVrPN0mAxfcLr"}]') || [];
let O = ""; let O = "";
try { try {
O = "__UNI__4796942"; O = "__UNI__4796942";

@ -23,15 +23,11 @@ export class Communication {
this.messageHandlers[action] = handler; this.messageHandlers[action] = handler;
} }
handleMessage(message) { handleMessage(message) {
try { const { action, data = {} } = message
const { action, data } = JSON.parse(message); if (this.messageHandlers[action]) {
if (this.messageHandlers[action]) { this.messageHandlers[action](data);
this.messageHandlers[action](data); } else {
} else { console.warn('Unknown action:', action);
console.warn('Unknown action:', action);
}
} catch (error) {
console.error('Failed to handle message:', error);
} }
} }
} }

Loading…
Cancel
Save