文件
jw-beauty/miniprogram/pages/ble-connect/ble-connect.js
T
Guoguo 52cb1f72dc fix: resolve header overlap on Dynamic Island iPhones
- app.js 通过 wx.getSystemInfoSync 获取 statusBarHeight 存入 globalData
- 所有12个自定义导航页面的 JS 读取 statusBarHeight
- WXML 通过 style="padding-top: {{statusBarHeight + 24}}px" 动态适配
- 普通手机和灵动岛手机都能正确显示
2026-04-24 22:20:10 +08:00

64 行
1.5 KiB
JavaScript

var ble = require('../../services/ble')
var app = getApp()
Page({
data: {
statusBarHeight: 44,
deviceId: '',
bindToken: '',
state: 'scanning',
error: ''
},
onLoad: function (options) {
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
this.setData({
deviceId: options.device_id || '',
bindToken: options.bind_token || ''
})
this.startBleConnect()
},
startBleConnect: function () {
var self = this
self.setData({ state: 'scanning', error: '' })
ble.startScan({
onFound: function (device) {
self.setData({ state: 'connecting' })
},
onConnected: function (device) {
self.setData({ state: 'binding' })
self.doBind()
},
onError: function (err) {
self.setData({ state: 'error', error: err.msg || '连接失败' })
}
})
},
doBind: function () {
var self = this
var userId = app.globalData.userId || ''
ble.on('bind_result', function (result) {
if (result.success) {
self.setData({ state: 'done' })
wx.redirectTo({
url: '/pages/bind-success/bind-success?device_id=' + self.data.deviceId
})
} else {
self.setData({ state: 'error', error: '设备绑定失败' })
}
})
ble.bindDevice(userId, self.data.bindToken).catch(function (err) {
self.setData({ state: 'error', error: err.error_msg || '绑定命令失败' })
})
},
onRetry: function () {
ble.disconnect()
this.startBleConnect()
}
})