1123
This commit is contained in:
parent
d663d7e7c4
commit
98745b859b
@ -8,8 +8,21 @@ import {onExit } from "@dcloudio/uni-app";
|
||||
import { Communication } from '../../utils/communication.js';
|
||||
const commun=new Communication()
|
||||
const permissionListener = uni.createRequestPermissionListener();
|
||||
onExit(()=>{
|
||||
permissionListener.stop()
|
||||
})
|
||||
function initializeWebView() {
|
||||
const currentWebview = getCurrentPages().pop().$getAppWebview()
|
||||
commun.setWebView(currentWebview.children()[0])
|
||||
}
|
||||
commun.registerHandler('load-complete',()=>{
|
||||
initializeWebView()
|
||||
const {statusBarHeight} = uni.getSystemInfoSync()
|
||||
commun.webViewObj.setStyle({
|
||||
top: statusBarHeight,
|
||||
bottom: 0,
|
||||
})
|
||||
permissionListener.onRequest((e)=>{
|
||||
console.log('APP执行onRequest',e)
|
||||
commun.sendToH5('permission-application',e);
|
||||
})
|
||||
permissionListener.onConfirm((e) => {
|
||||
@ -18,34 +31,11 @@ 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(()=>{
|
||||
permissionListener.stop()
|
||||
})
|
||||
function initializeWebView() {
|
||||
const currentWebview = getCurrentPages().pop().$getAppWebview()
|
||||
console.log('当前view',currentWebview)
|
||||
commun.setWebView(currentWebview.children()[0])
|
||||
}
|
||||
|
||||
commun.registerHandler('load-complete',()=>{
|
||||
})
|
||||
const webLoad = (e) => {
|
||||
try {
|
||||
const message = e.detail.data?.[0] || '';
|
||||
if (message.action==='load-complete'){
|
||||
initializeWebView()
|
||||
const {statusBarHeight} = uni.getSystemInfoSync()
|
||||
commun.webViewObj.setStyle({
|
||||
top: statusBarHeight,
|
||||
bottom: 0,
|
||||
})
|
||||
}else {
|
||||
commun.handleMessage(message);
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
44
unpackage/dist/dev/app-plus/app-service.js
vendored
44
unpackage/dist/dev/app-plus/app-service.js
vendored
@ -87,15 +87,11 @@ if (uni.restoreGlobal) {
|
||||
this.messageHandlers[action] = handler;
|
||||
}
|
||||
handleMessage(message) {
|
||||
try {
|
||||
const { action, data } = JSON.parse(message);
|
||||
const { action, data = {} } = message;
|
||||
if (this.messageHandlers[action]) {
|
||||
this.messageHandlers[action](data);
|
||||
} else {
|
||||
formatAppLog("warn", "at utils/communication.js:31", "Unknown action:", action);
|
||||
}
|
||||
} catch (error2) {
|
||||
formatAppLog("error", "at utils/communication.js:34", "Failed to handle message:", error2);
|
||||
formatAppLog("warn", "at utils/communication.js:30", "Unknown action:", action);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,42 +107,34 @@ if (uni.restoreGlobal) {
|
||||
setup(__props) {
|
||||
const commun = new Communication();
|
||||
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(() => {
|
||||
permissionListener.stop();
|
||||
});
|
||||
function initializeWebView() {
|
||||
const currentWebview = getCurrentPages().pop().$getAppWebview();
|
||||
formatAppLog("log", "at pages/index/index.vue:28", "当前view", currentWebview);
|
||||
commun.setWebView(currentWebview.children()[0]);
|
||||
}
|
||||
commun.registerHandler("load-complete", () => {
|
||||
});
|
||||
const webLoad = (e2) => {
|
||||
var _a;
|
||||
try {
|
||||
const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || "";
|
||||
if (message.action === "load-complete") {
|
||||
initializeWebView();
|
||||
const { statusBarHeight } = uni.getSystemInfoSync();
|
||||
commun.webViewObj.setStyle({
|
||||
top: statusBarHeight,
|
||||
bottom: 0
|
||||
});
|
||||
} else {
|
||||
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) => {
|
||||
var _a;
|
||||
const message = ((_a = e2.detail.data) == null ? void 0 : _a[0]) || "";
|
||||
commun.handleMessage(message);
|
||||
}
|
||||
} catch (error2) {
|
||||
}
|
||||
};
|
||||
return (_ctx, _cache) => {
|
||||
return vue.openBlock(), vue.createElementBlock("web-view", {
|
||||
@ -3206,7 +3194,7 @@ if (uni.restoreGlobal) {
|
||||
function I(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 = "";
|
||||
try {
|
||||
O = "__UNI__4796942";
|
||||
|
@ -23,16 +23,12 @@ export class Communication {
|
||||
this.messageHandlers[action] = handler;
|
||||
}
|
||||
handleMessage(message) {
|
||||
try {
|
||||
const { action, data } = JSON.parse(message);
|
||||
const { action, data = {} } = message
|
||||
if (this.messageHandlers[action]) {
|
||||
this.messageHandlers[action](data);
|
||||
} else {
|
||||
console.warn('Unknown action:', action);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to handle message:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user