REFactor => 移除安全区域相关功能,优化web-view组件样式,更新导航组件结构,简化代码逻辑。
This commit is contained in:
274
Appbuild/unpackage/dist/dev/app-plus/app-service.js
vendored
274
Appbuild/unpackage/dist/dev/app-plus/app-service.js
vendored
@@ -126,33 +126,15 @@ if (uni.restoreGlobal) {
|
||||
this.resumeMessageQueue();
|
||||
},
|
||||
onHide() {
|
||||
formatAppLog("log", "at pages/index/index.vue:52", "WebView页面隐藏");
|
||||
formatAppLog("log", "at pages/index/index.vue:51", "WebView页面隐藏");
|
||||
},
|
||||
onUnload() {
|
||||
this.cleanup();
|
||||
},
|
||||
computed: {
|
||||
navBarHeight() {
|
||||
return (this.getSafeAreaHeight().navBarHeight || 44) + "px";
|
||||
},
|
||||
webViewStyle() {
|
||||
const safeArea = this.getSafeAreaHeight();
|
||||
return {
|
||||
position: "absolute",
|
||||
top: safeArea.navBarHeight + "px",
|
||||
left: "0px",
|
||||
right: "0px",
|
||||
bottom: "0px",
|
||||
width: "100%",
|
||||
height: `calc(100vh - ${safeArea.navBarHeight}px)`,
|
||||
zIndex: 1
|
||||
};
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取初始URL
|
||||
getInitialUrl() {
|
||||
formatAppLog("log", "at pages/index/index.vue:79", "获取初始URL,config:", this.config);
|
||||
formatAppLog("log", "at pages/index/index.vue:60", "获取初始URL,config:", this.config);
|
||||
if (this.config && this.config.appConfig && this.config.appConfig.useTestPage) {
|
||||
return this.config.webConfig.testUrl;
|
||||
}
|
||||
@@ -160,12 +142,12 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 初始化应用
|
||||
initApp() {
|
||||
formatAppLog("log", "at pages/index/index.vue:88", "UniApp: 开始初始化应用");
|
||||
formatAppLog("log", "at pages/index/index.vue:69", "UniApp: 开始初始化应用");
|
||||
this.currentUrl = this.getInitialUrl();
|
||||
formatAppLog("log", "at pages/index/index.vue:91", "UniApp: 设置URL:", this.currentUrl);
|
||||
formatAppLog("log", "at pages/index/index.vue:72", "UniApp: 设置URL:", this.currentUrl);
|
||||
this.setupLoadingTimeout();
|
||||
this.initMessageHandler();
|
||||
formatAppLog("log", "at pages/index/index.vue:97", "UniApp: 立即注入桥接代码");
|
||||
formatAppLog("log", "at pages/index/index.vue:78", "UniApp: 立即注入桥接代码");
|
||||
this.injectBridgeCode();
|
||||
},
|
||||
// 设置加载超时
|
||||
@@ -174,14 +156,14 @@ if (uni.restoreGlobal) {
|
||||
clearTimeout(this.loadingTimer);
|
||||
}
|
||||
if (!this.config.appConfig.enableTimeout) {
|
||||
formatAppLog("log", "at pages/index/index.vue:110", "超时检测已禁用");
|
||||
formatAppLog("log", "at pages/index/index.vue:91", "超时检测已禁用");
|
||||
return;
|
||||
}
|
||||
if (this.config.appConfig.loadingTimeout > 0) {
|
||||
formatAppLog("log", "at pages/index/index.vue:115", "设置加载超时:", this.config.appConfig.loadingTimeout + "ms");
|
||||
formatAppLog("log", "at pages/index/index.vue:96", "设置加载超时:", this.config.appConfig.loadingTimeout + "ms");
|
||||
this.loadingTimer = setTimeout(() => {
|
||||
if (this.loading) {
|
||||
formatAppLog("warn", "at pages/index/index.vue:118", "页面加载超时,当前状态:", this.loading);
|
||||
formatAppLog("warn", "at pages/index/index.vue:99", "页面加载超时,当前状态:", this.loading);
|
||||
this.handleTimeout();
|
||||
}
|
||||
}, this.config.appConfig.loadingTimeout);
|
||||
@@ -189,7 +171,7 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理加载超时
|
||||
handleTimeout() {
|
||||
formatAppLog("warn", "at pages/index/index.vue:127", "触发页面加载超时处理");
|
||||
formatAppLog("warn", "at pages/index/index.vue:108", "触发页面加载超时处理");
|
||||
this.error = "页面加载超时,请检查网络连接";
|
||||
this.loading = false;
|
||||
if (this.loadingTimer) {
|
||||
@@ -199,9 +181,9 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 初始化消息处理器
|
||||
initMessageHandler() {
|
||||
formatAppLog("log", "at pages/index/index.vue:139", "UniApp: 初始化消息处理器");
|
||||
formatAppLog("log", "at pages/index/index.vue:120", "UniApp: 初始化消息处理器");
|
||||
window.addEventListener("message", (event) => {
|
||||
formatAppLog("log", "at pages/index/index.vue:142", "UniApp: 收到window.message事件:", event.data);
|
||||
formatAppLog("log", "at pages/index/index.vue:123", "UniApp: 收到window.message事件:", event.data);
|
||||
this.handleIframeMessage(event);
|
||||
});
|
||||
},
|
||||
@@ -211,21 +193,21 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 注入桥接代码
|
||||
injectBridgeCode() {
|
||||
formatAppLog("log", "at pages/index/index.vue:155", "UniApp: 开始注入桥接代码");
|
||||
formatAppLog("log", "at pages/index/index.vue:136", "UniApp: 开始注入桥接代码");
|
||||
const bridgeCode = `
|
||||
// UniApp WebView 桥接代码
|
||||
__f__('log','at pages/index/index.vue:159','开始注入UniApp桥接代码...');
|
||||
__f__('log','at pages/index/index.vue:140','开始注入UniApp桥接代码...');
|
||||
|
||||
// 检查是否已经存在桥接
|
||||
if (window.uniAppBridge) {
|
||||
__f__('log','at pages/index/index.vue:163','UniApp桥接已存在,跳过注入');
|
||||
__f__('log','at pages/index/index.vue:144','UniApp桥接已存在,跳过注入');
|
||||
return;
|
||||
}
|
||||
|
||||
window.uniAppBridge = {
|
||||
// 发送消息到UniApp
|
||||
postMessage: function(type, data) {
|
||||
__f__('log','at pages/index/index.vue:170','UniApp桥接发送消息:', type, data);
|
||||
__f__('log','at pages/index/index.vue:151','UniApp桥接发送消息:', type, data);
|
||||
window.parent.postMessage({
|
||||
type: type,
|
||||
data: data,
|
||||
@@ -235,68 +217,68 @@ if (uni.restoreGlobal) {
|
||||
|
||||
// 获取用户信息
|
||||
getUserInfo: function() {
|
||||
__f__('log','at pages/index/index.vue:180','UniApp桥接: 请求用户信息');
|
||||
__f__('log','at pages/index/index.vue:161','UniApp桥接: 请求用户信息');
|
||||
this.postMessage('getUserInfo', {});
|
||||
},
|
||||
|
||||
// 获取设备信息
|
||||
getDeviceInfo: function() {
|
||||
__f__('log','at pages/index/index.vue:186','UniApp桥接: 请求设备信息');
|
||||
__f__('log','at pages/index/index.vue:167','UniApp桥接: 请求设备信息');
|
||||
this.postMessage('getDeviceInfo', {});
|
||||
},
|
||||
|
||||
// 显示Toast
|
||||
showToast: function(message, duration = 2000) {
|
||||
__f__('log','at pages/index/index.vue:192','UniApp桥接: 显示Toast', message, duration);
|
||||
__f__('log','at pages/index/index.vue:173','UniApp桥接: 显示Toast', message, duration);
|
||||
this.postMessage('toast', { message, duration });
|
||||
},
|
||||
|
||||
// 显示Alert
|
||||
showAlert: function(title, content) {
|
||||
__f__('log','at pages/index/index.vue:198','UniApp桥接: 显示Alert', title, content);
|
||||
__f__('log','at pages/index/index.vue:179','UniApp桥接: 显示Alert', title, content);
|
||||
this.postMessage('alert', { title, content });
|
||||
},
|
||||
|
||||
// 显示Confirm
|
||||
showConfirm: function(title, content) {
|
||||
__f__('log','at pages/index/index.vue:204','UniApp桥接: 显示Confirm', title, content);
|
||||
__f__('log','at pages/index/index.vue:185','UniApp桥接: 显示Confirm', title, content);
|
||||
this.postMessage('confirm', { title, content });
|
||||
},
|
||||
|
||||
// 分享
|
||||
share: function(data) {
|
||||
__f__('log','at pages/index/index.vue:210','UniApp桥接: 分享', data);
|
||||
__f__('log','at pages/index/index.vue:191','UniApp桥接: 分享', data);
|
||||
this.postMessage('share', data);
|
||||
},
|
||||
|
||||
// 支付
|
||||
payment: function(data) {
|
||||
__f__('log','at pages/index/index.vue:216','UniApp桥接: 支付', data);
|
||||
__f__('log','at pages/index/index.vue:197','UniApp桥接: 支付', data);
|
||||
this.postMessage('payment', data);
|
||||
},
|
||||
|
||||
// 页面导航
|
||||
navigate: function(url) {
|
||||
__f__('log','at pages/index/index.vue:222','UniApp桥接: 导航', url);
|
||||
__f__('log','at pages/index/index.vue:203','UniApp桥接: 导航', url);
|
||||
this.postMessage('navigate', { url });
|
||||
},
|
||||
|
||||
// 自定义消息
|
||||
sendCustomMessage: function(type, data) {
|
||||
__f__('log','at pages/index/index.vue:228','UniApp桥接: 自定义消息', type, data);
|
||||
__f__('log','at pages/index/index.vue:209','UniApp桥接: 自定义消息', type, data);
|
||||
this.postMessage(type, data);
|
||||
},
|
||||
|
||||
// 页面准备就绪
|
||||
notifyPageReady: function(data) {
|
||||
__f__('log','at pages/index/index.vue:234','UniApp桥接: 页面准备就绪', data);
|
||||
__f__('log','at pages/index/index.vue:215','UniApp桥接: 页面准备就绪', data);
|
||||
this.postMessage('pageReady', data);
|
||||
}
|
||||
};
|
||||
|
||||
// 监听来自UniApp的消息
|
||||
window.addEventListener('message', function(event) {
|
||||
__f__('log','at pages/index/index.vue:241','UniApp桥接收到消息:', event.data);
|
||||
__f__('log','at pages/index/index.vue:222','UniApp桥接收到消息:', event.data);
|
||||
if (event.data && event.data.type) {
|
||||
// 触发自定义事件
|
||||
const customEvent = new CustomEvent('uniAppMessage', {
|
||||
@@ -306,7 +288,7 @@ if (uni.restoreGlobal) {
|
||||
}
|
||||
});
|
||||
|
||||
__f__('log','at pages/index/index.vue:251','UniApp桥接代码注入成功');
|
||||
__f__('log','at pages/index/index.vue:232','UniApp桥接代码注入成功');
|
||||
|
||||
// 通知UniApp页面已加载完成
|
||||
window.parent.postMessage({
|
||||
@@ -315,47 +297,47 @@ if (uni.restoreGlobal) {
|
||||
timestamp: Date.now()
|
||||
}, '*');
|
||||
`;
|
||||
formatAppLog("log", "at pages/index/index.vue:262", "UniApp: 立即注入桥接代码");
|
||||
formatAppLog("log", "at pages/index/index.vue:243", "UniApp: 立即注入桥接代码");
|
||||
this.evalJS(bridgeCode);
|
||||
setTimeout(() => {
|
||||
formatAppLog("log", "at pages/index/index.vue:267", "UniApp: 延迟500ms后再次注入");
|
||||
formatAppLog("log", "at pages/index/index.vue:248", "UniApp: 延迟500ms后再次注入");
|
||||
this.evalJS(bridgeCode);
|
||||
}, 500);
|
||||
setTimeout(() => {
|
||||
formatAppLog("log", "at pages/index/index.vue:273", "UniApp: 延迟1000ms后备用注入");
|
||||
formatAppLog("log", "at pages/index/index.vue:254", "UniApp: 延迟1000ms后备用注入");
|
||||
this.evalJS(bridgeCode);
|
||||
}, 1e3);
|
||||
},
|
||||
// 执行JavaScript代码
|
||||
evalJS(code) {
|
||||
formatAppLog("log", "at pages/index/index.vue:280", "UniApp: 执行JavaScript代码");
|
||||
formatAppLog("log", "at pages/index/index.vue:281", "UniApp: 当前平台:", uni.getSystemInfoSync().platform);
|
||||
formatAppLog("log", "at pages/index/index.vue:261", "UniApp: 执行JavaScript代码");
|
||||
formatAppLog("log", "at pages/index/index.vue:262", "UniApp: 当前平台:", uni.getSystemInfoSync().platform);
|
||||
const webview = this.$refs.webview;
|
||||
formatAppLog("log", "at pages/index/index.vue:284", "UniApp: webview引用:", webview);
|
||||
formatAppLog("log", "at pages/index/index.vue:265", "UniApp: webview引用:", webview);
|
||||
if (webview && webview.evalJS) {
|
||||
try {
|
||||
webview.evalJS(code);
|
||||
formatAppLog("log", "at pages/index/index.vue:291", "UniApp: JavaScript代码执行成功 (App环境)");
|
||||
formatAppLog("log", "at pages/index/index.vue:272", "UniApp: JavaScript代码执行成功 (App环境)");
|
||||
} catch (error) {
|
||||
formatAppLog("error", "at pages/index/index.vue:293", "UniApp: JavaScript代码执行失败:", error);
|
||||
formatAppLog("error", "at pages/index/index.vue:274", "UniApp: JavaScript代码执行失败:", error);
|
||||
}
|
||||
} else {
|
||||
formatAppLog("warn", "at pages/index/index.vue:296", "UniApp: webview或evalJS方法不存在 (App环境)");
|
||||
formatAppLog("warn", "at pages/index/index.vue:277", "UniApp: webview或evalJS方法不存在 (App环境)");
|
||||
this.tryAlternativeInjection(code);
|
||||
}
|
||||
},
|
||||
// 备用注入方案
|
||||
tryAlternativeInjection(code) {
|
||||
formatAppLog("log", "at pages/index/index.vue:315", "UniApp: 尝试备用注入方案");
|
||||
formatAppLog("log", "at pages/index/index.vue:296", "UniApp: 尝试备用注入方案");
|
||||
try {
|
||||
window.postMessage({
|
||||
type: "injectCode",
|
||||
data: { code },
|
||||
timestamp: Date.now()
|
||||
}, "*");
|
||||
formatAppLog("log", "at pages/index/index.vue:323", "UniApp: 备用方案1执行成功");
|
||||
formatAppLog("log", "at pages/index/index.vue:304", "UniApp: 备用方案1执行成功");
|
||||
} catch (error) {
|
||||
formatAppLog("error", "at pages/index/index.vue:325", "UniApp: 备用方案1失败:", error);
|
||||
formatAppLog("error", "at pages/index/index.vue:306", "UniApp: 备用方案1失败:", error);
|
||||
try {
|
||||
const webview = this.$refs.webview;
|
||||
if (webview && webview.postMessage) {
|
||||
@@ -363,34 +345,34 @@ if (uni.restoreGlobal) {
|
||||
type: "injectCode",
|
||||
data: { code }
|
||||
});
|
||||
formatAppLog("log", "at pages/index/index.vue:335", "UniApp: 备用方案2执行成功");
|
||||
formatAppLog("log", "at pages/index/index.vue:316", "UniApp: 备用方案2执行成功");
|
||||
} else {
|
||||
formatAppLog("error", "at pages/index/index.vue:337", "UniApp: 备用方案2失败 - webview.postMessage不存在");
|
||||
formatAppLog("error", "at pages/index/index.vue:318", "UniApp: 备用方案2失败 - webview.postMessage不存在");
|
||||
}
|
||||
} catch (error2) {
|
||||
formatAppLog("error", "at pages/index/index.vue:340", "UniApp: 备用方案2失败:", error2);
|
||||
formatAppLog("error", "at pages/index/index.vue:321", "UniApp: 备用方案2失败:", error2);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 处理web-view组件的消息
|
||||
handleMessage(event) {
|
||||
formatAppLog("log", "at pages/index/index.vue:347", "收到web-view消息:", event.detail);
|
||||
formatAppLog("log", "at pages/index/index.vue:328", "收到web-view消息:", event.detail);
|
||||
try {
|
||||
const data = event.detail.data;
|
||||
if (data && data.type) {
|
||||
this.processMessage(data);
|
||||
}
|
||||
} catch (error) {
|
||||
formatAppLog("error", "at pages/index/index.vue:354", "处理消息失败:", error);
|
||||
formatAppLog("error", "at pages/index/index.vue:335", "处理消息失败:", error);
|
||||
}
|
||||
},
|
||||
// 处理iframe消息
|
||||
handleIframeMessage(event) {
|
||||
formatAppLog("log", "at pages/index/index.vue:360", "收到iframe消息:", event.data);
|
||||
formatAppLog("log", "at pages/index/index.vue:341", "收到iframe消息:", event.data);
|
||||
try {
|
||||
if (event.data && event.data.type) {
|
||||
if (event.data.type === "pageLoaded") {
|
||||
formatAppLog("log", "at pages/index/index.vue:365", "收到页面加载完成消息:", event.data.data);
|
||||
formatAppLog("log", "at pages/index/index.vue:346", "收到页面加载完成消息:", event.data.data);
|
||||
if (this.loadingTimer) {
|
||||
clearTimeout(this.loadingTimer);
|
||||
this.loadingTimer = null;
|
||||
@@ -402,55 +384,55 @@ if (uni.restoreGlobal) {
|
||||
this.processMessage(event.data);
|
||||
}
|
||||
} catch (error) {
|
||||
formatAppLog("error", "at pages/index/index.vue:380", "处理iframe消息失败:", error);
|
||||
formatAppLog("error", "at pages/index/index.vue:361", "处理iframe消息失败:", error);
|
||||
}
|
||||
},
|
||||
// 处理消息
|
||||
processMessage(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:386", "UniApp处理消息:", data.type, data);
|
||||
formatAppLog("log", "at pages/index/index.vue:367", "UniApp处理消息:", data.type, data);
|
||||
switch (data.type) {
|
||||
case this.config.communication.messageTypes.GET_USER_INFO:
|
||||
formatAppLog("log", "at pages/index/index.vue:390", "UniApp: 处理获取用户信息请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:371", "UniApp: 处理获取用户信息请求");
|
||||
this.sendUserInfo();
|
||||
break;
|
||||
case this.config.communication.messageTypes.GET_DEVICE_INFO:
|
||||
formatAppLog("log", "at pages/index/index.vue:394", "UniApp: 处理获取设备信息请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:375", "UniApp: 处理获取设备信息请求");
|
||||
this.sendDeviceInfo();
|
||||
break;
|
||||
case this.config.communication.messageTypes.NAVIGATE:
|
||||
formatAppLog("log", "at pages/index/index.vue:398", "UniApp: 处理导航请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:379", "UniApp: 处理导航请求");
|
||||
this.handleNavigation(data);
|
||||
break;
|
||||
case this.config.communication.messageTypes.SHARE:
|
||||
formatAppLog("log", "at pages/index/index.vue:402", "UniApp: 处理分享请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:383", "UniApp: 处理分享请求");
|
||||
this.handleShare(data);
|
||||
break;
|
||||
case this.config.communication.messageTypes.PAYMENT:
|
||||
formatAppLog("log", "at pages/index/index.vue:406", "UniApp: 处理支付请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:387", "UniApp: 处理支付请求");
|
||||
this.handlePayment(data);
|
||||
break;
|
||||
case this.config.communication.messageTypes.TOAST:
|
||||
formatAppLog("log", "at pages/index/index.vue:410", "UniApp: 处理Toast请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:391", "UniApp: 处理Toast请求");
|
||||
this.handleToast(data);
|
||||
break;
|
||||
case this.config.communication.messageTypes.ALERT:
|
||||
formatAppLog("log", "at pages/index/index.vue:414", "UniApp: 处理Alert请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:395", "UniApp: 处理Alert请求");
|
||||
this.handleAlert(data);
|
||||
break;
|
||||
case this.config.communication.messageTypes.CONFIRM:
|
||||
formatAppLog("log", "at pages/index/index.vue:418", "UniApp: 处理Confirm请求");
|
||||
formatAppLog("log", "at pages/index/index.vue:399", "UniApp: 处理Confirm请求");
|
||||
this.handleConfirm(data);
|
||||
break;
|
||||
case "pageReady":
|
||||
formatAppLog("log", "at pages/index/index.vue:422", "UniApp: 处理页面准备就绪消息");
|
||||
formatAppLog("log", "at pages/index/index.vue:403", "UniApp: 处理页面准备就绪消息");
|
||||
break;
|
||||
default:
|
||||
formatAppLog("log", "at pages/index/index.vue:426", "UniApp: 未知消息类型:", data.type);
|
||||
formatAppLog("log", "at pages/index/index.vue:407", "UniApp: 未知消息类型:", data.type);
|
||||
}
|
||||
},
|
||||
// 发送用户信息到iframe
|
||||
sendUserInfo() {
|
||||
formatAppLog("log", "at pages/index/index.vue:432", "UniApp: 发送用户信息");
|
||||
formatAppLog("log", "at pages/index/index.vue:413", "UniApp: 发送用户信息");
|
||||
const userInfo = {
|
||||
type: "userInfo",
|
||||
data: this.config.userConfig.defaultUser
|
||||
@@ -459,7 +441,7 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 发送设备信息到iframe
|
||||
sendDeviceInfo() {
|
||||
formatAppLog("log", "at pages/index/index.vue:442", "UniApp: 发送设备信息");
|
||||
formatAppLog("log", "at pages/index/index.vue:423", "UniApp: 发送设备信息");
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const deviceInfo = {
|
||||
type: "deviceInfo",
|
||||
@@ -479,12 +461,12 @@ if (uni.restoreGlobal) {
|
||||
// 处理导航
|
||||
handleNavigation(data) {
|
||||
if (data.url) {
|
||||
formatAppLog("log", "at pages/index/index.vue:463", "导航到:", data.url);
|
||||
formatAppLog("log", "at pages/index/index.vue:444", "导航到:", data.url);
|
||||
}
|
||||
},
|
||||
// 处理分享
|
||||
handleShare(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:470", "UniApp: 处理分享请求", data);
|
||||
formatAppLog("log", "at pages/index/index.vue:451", "UniApp: 处理分享请求", data);
|
||||
uni.share({
|
||||
provider: "weixin",
|
||||
scene: "WXSceneSession",
|
||||
@@ -493,18 +475,18 @@ if (uni.restoreGlobal) {
|
||||
title: data.title || this.config.appConfig.appName,
|
||||
summary: data.summary || "分享内容",
|
||||
success: (res) => {
|
||||
formatAppLog("log", "at pages/index/index.vue:479", "UniApp: 分享成功:", res);
|
||||
formatAppLog("log", "at pages/index/index.vue:460", "UniApp: 分享成功:", res);
|
||||
this.sendToIframe("shareResult", { success: true });
|
||||
},
|
||||
fail: (err) => {
|
||||
formatAppLog("error", "at pages/index/index.vue:483", "UniApp: 分享失败:", err);
|
||||
formatAppLog("error", "at pages/index/index.vue:464", "UniApp: 分享失败:", err);
|
||||
this.sendToIframe("shareResult", { success: false, error: err });
|
||||
}
|
||||
});
|
||||
},
|
||||
// 处理支付
|
||||
handlePayment(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:491", "UniApp: 处理支付请求", data);
|
||||
formatAppLog("log", "at pages/index/index.vue:472", "UniApp: 处理支付请求", data);
|
||||
setTimeout(() => {
|
||||
this.sendToIframe("paymentResult", {
|
||||
success: true,
|
||||
@@ -514,7 +496,7 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理Toast
|
||||
handleToast(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:504", "UniApp: 处理Toast请求", data);
|
||||
formatAppLog("log", "at pages/index/index.vue:485", "UniApp: 处理Toast请求", data);
|
||||
uni.showToast({
|
||||
title: data.message,
|
||||
icon: "none",
|
||||
@@ -523,7 +505,7 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理Alert
|
||||
handleAlert(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:514", "UniApp: 处理Alert请求", data);
|
||||
formatAppLog("log", "at pages/index/index.vue:495", "UniApp: 处理Alert请求", data);
|
||||
uni.showModal({
|
||||
title: data.title || "提示",
|
||||
content: data.content,
|
||||
@@ -532,12 +514,12 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理Confirm
|
||||
handleConfirm(data) {
|
||||
formatAppLog("log", "at pages/index/index.vue:524", "UniApp: 处理Confirm请求", data);
|
||||
formatAppLog("log", "at pages/index/index.vue:505", "UniApp: 处理Confirm请求", data);
|
||||
uni.showModal({
|
||||
title: data.title || "确认",
|
||||
content: data.content,
|
||||
success: (res) => {
|
||||
formatAppLog("log", "at pages/index/index.vue:529", "UniApp: Confirm结果:", res);
|
||||
formatAppLog("log", "at pages/index/index.vue:510", "UniApp: Confirm结果:", res);
|
||||
this.sendToIframe("confirmResult", {
|
||||
confirmed: res.confirm
|
||||
});
|
||||
@@ -551,10 +533,10 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理消息队列
|
||||
processMessageQueue() {
|
||||
formatAppLog("log", "at pages/index/index.vue:545", "UniApp: 处理消息队列, 队列长度:", this.messageQueue.length, "加载状态:", this.loading);
|
||||
formatAppLog("log", "at pages/index/index.vue:526", "UniApp: 处理消息队列, 队列长度:", this.messageQueue.length, "加载状态:", this.loading);
|
||||
if (this.messageQueue.length > 0 && !this.loading) {
|
||||
const message = this.messageQueue.shift();
|
||||
formatAppLog("log", "at pages/index/index.vue:548", "UniApp: 发送消息到iframe:", message);
|
||||
formatAppLog("log", "at pages/index/index.vue:529", "UniApp: 发送消息到iframe:", message);
|
||||
this.evalJS(`
|
||||
window.postMessage(${JSON.stringify(message)}, '*');
|
||||
`);
|
||||
@@ -575,12 +557,12 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 处理加载状态
|
||||
handleLoading(event) {
|
||||
formatAppLog("log", "at pages/index/index.vue:572", "WebView加载状态变化:", event.detail);
|
||||
formatAppLog("log", "at pages/index/index.vue:553", "WebView加载状态变化:", event.detail);
|
||||
const newLoadingState = event.detail.loading;
|
||||
formatAppLog("log", "at pages/index/index.vue:574", "加载状态从", this.loading, "变为", newLoadingState);
|
||||
formatAppLog("log", "at pages/index/index.vue:555", "加载状态从", this.loading, "变为", newLoadingState);
|
||||
this.loading = newLoadingState;
|
||||
if (!this.loading) {
|
||||
formatAppLog("log", "at pages/index/index.vue:580", "页面加载完成,清除超时定时器");
|
||||
formatAppLog("log", "at pages/index/index.vue:561", "页面加载完成,清除超时定时器");
|
||||
if (this.loadingTimer) {
|
||||
clearTimeout(this.loadingTimer);
|
||||
this.loadingTimer = null;
|
||||
@@ -588,13 +570,13 @@ if (uni.restoreGlobal) {
|
||||
this.injectBridgeCode();
|
||||
this.processMessageQueue();
|
||||
} else {
|
||||
formatAppLog("log", "at pages/index/index.vue:592", "页面开始加载,设置超时检测");
|
||||
formatAppLog("log", "at pages/index/index.vue:573", "页面开始加载,设置超时检测");
|
||||
this.setupLoadingTimeout();
|
||||
}
|
||||
},
|
||||
// 处理错误
|
||||
handleError(event) {
|
||||
formatAppLog("error", "at pages/index/index.vue:599", "WebView错误:", event.detail);
|
||||
formatAppLog("error", "at pages/index/index.vue:580", "WebView错误:", event.detail);
|
||||
this.error = "页面加载失败,请检查网络连接";
|
||||
this.loading = false;
|
||||
clearTimeout(this.loadingTimer);
|
||||
@@ -616,99 +598,18 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 清除超时
|
||||
clearTimeout() {
|
||||
formatAppLog("log", "at pages/index/index.vue:625", "手动清除超时");
|
||||
formatAppLog("log", "at pages/index/index.vue:606", "手动清除超时");
|
||||
if (this.loadingTimer) {
|
||||
clearTimeout(this.loadingTimer);
|
||||
this.loadingTimer = null;
|
||||
}
|
||||
this.error = "";
|
||||
this.loading = false;
|
||||
formatAppLog("log", "at pages/index/index.vue:632", "超时已清除");
|
||||
},
|
||||
// 获取安全区域高度
|
||||
getSafeAreaHeight() {
|
||||
try {
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
formatAppLog("log", "at pages/index/index.vue:640", "UniApp: 系统信息:", systemInfo);
|
||||
const safeArea = systemInfo.safeArea || {};
|
||||
const safeAreaInsets = systemInfo.safeAreaInsets || {};
|
||||
formatAppLog("log", "at pages/index/index.vue:646", "UniApp: 安全区域:", safeArea);
|
||||
formatAppLog("log", "at pages/index/index.vue:647", "UniApp: 安全区域边距:", safeAreaInsets);
|
||||
const statusBarHeight = systemInfo.statusBarHeight || 0;
|
||||
formatAppLog("log", "at pages/index/index.vue:651", "UniApp: 状态栏高度:", statusBarHeight);
|
||||
let topSafeAreaHeight = statusBarHeight;
|
||||
if (safeAreaInsets.top !== void 0) {
|
||||
topSafeAreaHeight = safeAreaInsets.top;
|
||||
formatAppLog("log", "at pages/index/index.vue:659", "UniApp: 使用safeAreaInsets.top:", topSafeAreaHeight);
|
||||
} else if (safeArea.top !== void 0) {
|
||||
topSafeAreaHeight = safeArea.top;
|
||||
formatAppLog("log", "at pages/index/index.vue:662", "UniApp: 使用safeArea.top:", topSafeAreaHeight);
|
||||
} else {
|
||||
topSafeAreaHeight = this.calculatePlatformSafeArea(statusBarHeight, systemInfo);
|
||||
}
|
||||
const safeAreaInfo = {
|
||||
top: topSafeAreaHeight,
|
||||
bottom: safeAreaInsets.bottom || safeArea.bottom || 0,
|
||||
left: safeAreaInsets.left || safeArea.left || 0,
|
||||
right: safeAreaInsets.right || safeArea.right || 0,
|
||||
statusBarHeight,
|
||||
navBarHeight: 44,
|
||||
// 导航栏高度通常是44px
|
||||
platform: systemInfo.platform,
|
||||
model: systemInfo.model,
|
||||
system: systemInfo.system,
|
||||
screenWidth: systemInfo.screenWidth,
|
||||
screenHeight: systemInfo.screenHeight
|
||||
};
|
||||
return safeAreaInfo;
|
||||
} catch (error) {
|
||||
formatAppLog("error", "at pages/index/index.vue:686", "UniApp: 获取安全区域信息失败:", error);
|
||||
return {
|
||||
top: 44,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
statusBarHeight: 44,
|
||||
navBarHeight: 44,
|
||||
platform: "unknown",
|
||||
model: "unknown",
|
||||
system: "unknown",
|
||||
screenWidth: 375,
|
||||
screenHeight: 667
|
||||
};
|
||||
}
|
||||
},
|
||||
// 根据平台计算安全区域
|
||||
calculatePlatformSafeArea(statusBarHeight, systemInfo) {
|
||||
const platform = systemInfo.platform.toLowerCase();
|
||||
const model = systemInfo.model || "";
|
||||
const screenHeight = systemInfo.screenHeight;
|
||||
const screenWidth = systemInfo.screenWidth;
|
||||
formatAppLog("log", "at pages/index/index.vue:712", "UniApp: 平台信息:", { platform, model, screenHeight, screenWidth });
|
||||
if (platform === "ios") {
|
||||
if (screenHeight >= 812 || screenWidth >= 812) {
|
||||
formatAppLog("log", "at pages/index/index.vue:718", "UniApp: 检测到iPhone X及以后设备");
|
||||
return 44;
|
||||
} else {
|
||||
formatAppLog("log", "at pages/index/index.vue:723", "UniApp: 检测到传统iPhone设备");
|
||||
return statusBarHeight || 20;
|
||||
}
|
||||
} else if (platform === "android") {
|
||||
if (screenHeight >= 800 || screenWidth >= 800) {
|
||||
formatAppLog("log", "at pages/index/index.vue:731", "UniApp: 检测到高分辨率Android设备");
|
||||
return Math.max(statusBarHeight, 24);
|
||||
} else {
|
||||
formatAppLog("log", "at pages/index/index.vue:736", "UniApp: 检测到传统Android设备");
|
||||
return statusBarHeight || 24;
|
||||
}
|
||||
} else {
|
||||
formatAppLog("log", "at pages/index/index.vue:742", "UniApp: 其他平台设备");
|
||||
return statusBarHeight || 20;
|
||||
}
|
||||
formatAppLog("log", "at pages/index/index.vue:613", "超时已清除");
|
||||
},
|
||||
// 动态设置web-view高度
|
||||
setWebViewHeight(height) {
|
||||
formatAppLog("log", "at pages/index/index.vue:749", "设置web-view高度:", height);
|
||||
formatAppLog("log", "at pages/index/index.vue:618", "设置web-view高度:", height);
|
||||
if (this.$refs.webview) {
|
||||
this.$refs.webview.$el.style.height = height + "px";
|
||||
this.$refs.webview.$el.className = "webview custom-height";
|
||||
@@ -719,17 +620,15 @@ if (uni.restoreGlobal) {
|
||||
},
|
||||
// 设置web-view为全屏
|
||||
setWebViewFullscreen() {
|
||||
this.getSafeAreaHeight();
|
||||
const fullHeight = uni.getSystemInfoSync().windowHeight;
|
||||
formatAppLog("log", "at pages/index/index.vue:768", "设置web-view全屏,高度:", fullHeight);
|
||||
formatAppLog("log", "at pages/index/index.vue:636", "设置web-view全屏,高度:", fullHeight);
|
||||
this.setWebViewHeight(fullHeight);
|
||||
},
|
||||
// 设置web-view为部分高度
|
||||
setWebViewPartialHeight(percentage = 0.8) {
|
||||
this.getSafeAreaHeight();
|
||||
const windowHeight = uni.getSystemInfoSync().windowHeight;
|
||||
const partialHeight = windowHeight * percentage;
|
||||
formatAppLog("log", "at pages/index/index.vue:777", "设置web-view部分高度:", partialHeight, "百分比:", percentage);
|
||||
formatAppLog("log", "at pages/index/index.vue:644", "设置web-view部分高度:", partialHeight, "百分比:", percentage);
|
||||
this.setWebViewHeight(partialHeight);
|
||||
},
|
||||
// 清理资源
|
||||
@@ -745,12 +644,12 @@ if (uni.restoreGlobal) {
|
||||
vue.createCommentVNode(" 全屏web-view容器 "),
|
||||
vue.createElementVNode("web-view", {
|
||||
src: $data.currentUrl,
|
||||
style: vue.normalizeStyle($options.webViewStyle),
|
||||
class: "webview",
|
||||
ref: "webview",
|
||||
onMessage: _cache[0] || (_cache[0] = (...args) => $options.handleMessage && $options.handleMessage(...args)),
|
||||
onError: _cache[1] || (_cache[1] = (...args) => $options.handleError && $options.handleError(...args)),
|
||||
onLoading: _cache[2] || (_cache[2] = (...args) => $options.handleLoading && $options.handleLoading(...args))
|
||||
}, null, 44, ["src"]),
|
||||
}, null, 40, ["src"]),
|
||||
vue.createCommentVNode(" 加载状态 "),
|
||||
$data.loading ? (vue.openBlock(), vue.createElementBlock("view", {
|
||||
key: 0,
|
||||
@@ -802,13 +701,6 @@ if (uni.restoreGlobal) {
|
||||
"加载状态: " + vue.toDisplayString($data.loading ? "加载中" : "已加载"),
|
||||
1
|
||||
/* TEXT */
|
||||
),
|
||||
vue.createElementVNode(
|
||||
"text",
|
||||
null,
|
||||
"navBarHeight: " + vue.toDisplayString($options.navBarHeight),
|
||||
1
|
||||
/* TEXT */
|
||||
)
|
||||
])) : vue.createCommentVNode("v-if", true)
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user