187 lines
4.7 KiB
Plaintext
187 lines
4.7 KiB
Plaintext
===========================================
|
||
调试版本 - 确认问题位置
|
||
===========================================
|
||
|
||
📍 第一步:添加简单的测试方法
|
||
-------------------------------------------
|
||
在 methods: { } 中添加一个简单的测试方法:
|
||
|
||
/**
|
||
* 测试Android Bridge连接
|
||
*/
|
||
testAndroidBridge() {
|
||
console.log('🧪 测试Android Bridge连接')
|
||
|
||
if (typeof window !== 'undefined') {
|
||
console.log('✅ window 对象存在')
|
||
|
||
if (window.Android) {
|
||
console.log('✅ window.Android 存在')
|
||
|
||
if (window.Android.getDeviceConfig) {
|
||
console.log('✅ getDeviceConfig 方法存在')
|
||
|
||
try {
|
||
const configStr = window.Android.getDeviceConfig()
|
||
console.log('📱 原始配置字符串:', configStr)
|
||
|
||
const config = JSON.parse(configStr)
|
||
console.log('📱 解析后的配置:', config)
|
||
|
||
if (config.configured) {
|
||
console.log('✅ 设备已配置:', config.host)
|
||
} else {
|
||
console.log('❌ 设备未配置')
|
||
}
|
||
} catch (error) {
|
||
console.error('❌ 调用getDeviceConfig失败:', error)
|
||
}
|
||
} else {
|
||
console.log('❌ getDeviceConfig 方法不存在')
|
||
}
|
||
} else {
|
||
console.log('❌ window.Android 不存在')
|
||
}
|
||
} else {
|
||
console.log('❌ window 对象不存在')
|
||
}
|
||
},
|
||
|
||
|
||
📍 第二步:修改设备配置按钮,添加测试
|
||
-------------------------------------------
|
||
修改 openDeviceConfig() 方法:
|
||
|
||
/**
|
||
* 打开设备配置页面
|
||
*/
|
||
openDeviceConfig() {
|
||
console.log('🔧 打开设备配置')
|
||
|
||
// 先测试Android Bridge
|
||
this.testAndroidBridge()
|
||
|
||
if (typeof window !== 'undefined' && window.Android && window.Android.openDeviceDiscovery) {
|
||
console.log('🔍 打开Android原生设备发现')
|
||
window.Android.openDeviceDiscovery()
|
||
|
||
// 启动简单的测试定时器
|
||
console.log('⏰ 启动配置检查定时器')
|
||
setTimeout(() => {
|
||
console.log('⏰ 5秒后检查配置')
|
||
this.testAndroidBridge()
|
||
}, 5000)
|
||
|
||
setTimeout(() => {
|
||
console.log('⏰ 10秒后检查配置')
|
||
this.testAndroidBridge()
|
||
}, 10000)
|
||
|
||
} else {
|
||
console.log('⚠️ Android原生设备发现不可用')
|
||
uni.showToast({
|
||
title: '请在Android应用中使用',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
},
|
||
|
||
|
||
📍 第三步:在页面显示时也测试
|
||
-------------------------------------------
|
||
修改 onShow() 方法,在最开头添加:
|
||
|
||
onShow() {
|
||
console.log('📄 页面显示 - onShow 触发')
|
||
this.isPageActive = true
|
||
|
||
// 测试Android Bridge
|
||
this.testAndroidBridge()
|
||
|
||
// 继续原有的逻辑...
|
||
this.loadData()
|
||
this.fetchAlarmHistory(true)
|
||
this.loadKitchenAlarmHistory()
|
||
this.startAlarmTimer()
|
||
},
|
||
|
||
|
||
===========================================
|
||
🧪 测试步骤
|
||
===========================================
|
||
|
||
1. 添加上面的代码
|
||
2. 保存并打包 uni-app
|
||
3. 替换 web 文件夹
|
||
4. 重新 Build Android 应用
|
||
5. 运行应用,观察日志
|
||
|
||
|
||
===========================================
|
||
🔍 预期的调试日志
|
||
===========================================
|
||
|
||
如果一切正常,应该看到:
|
||
|
||
页面加载时:
|
||
📄 页面显示 - onShow 触发
|
||
🧪 测试Android Bridge连接
|
||
✅ window 对象存在
|
||
✅ window.Android 存在
|
||
✅ getDeviceConfig 方法存在
|
||
📱 原始配置字符串: {"configured":false}
|
||
📱 解析后的配置: {configured: false}
|
||
❌ 设备未配置
|
||
|
||
点击配置按钮时:
|
||
🔧 打开设备配置
|
||
🧪 测试Android Bridge连接
|
||
✅ window 对象存在
|
||
✅ window.Android 存在
|
||
✅ getDeviceConfig 方法存在
|
||
📱 原始配置字符串: {"configured":false}
|
||
📱 解析后的配置: {configured: false}
|
||
❌ 设备未配置
|
||
🔍 打开Android原生设备发现
|
||
⏰ 启动配置检查定时器
|
||
|
||
选择设备后(5秒后):
|
||
⏰ 5秒后检查配置
|
||
🧪 测试Android Bridge连接
|
||
✅ window 对象存在
|
||
✅ window.Android 存在
|
||
✅ getDeviceConfig 方法存在
|
||
📱 原始配置字符串: {"configured":true,"host":"192.168.1.100:80",...}
|
||
📱 解析后的配置: {configured: true, host: "192.168.1.100:80", ...}
|
||
✅ 设备已配置: 192.168.1.100:80
|
||
|
||
|
||
===========================================
|
||
🚨 可能的错误情况
|
||
===========================================
|
||
|
||
如果看到这些错误:
|
||
|
||
❌ window 对象不存在
|
||
→ 说明代码运行环境有问题
|
||
|
||
❌ window.Android 不存在
|
||
→ 说明JavaScript Bridge没有正确注入
|
||
|
||
❌ getDeviceConfig 方法不存在
|
||
→ 说明Esp32JsBridge没有正确配置
|
||
|
||
❌ 调用getDeviceConfig失败
|
||
→ 说明方法调用有问题
|
||
|
||
|
||
===========================================
|
||
💡 下一步
|
||
===========================================
|
||
|
||
先运行这个调试版本,把日志发给我,我就能知道问题在哪里了!
|
||
|
||
这样我们就能精确定位问题,然后针对性地解决。
|
||
===========================================
|