文件
jw-beauty/miniprogram/pages/scan/scan.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

82 行
2.0 KiB
JavaScript

var http = require('../../utils/request')
Page({
data: {
statusBarHeight: 44,
scanning: false,
deviceId: '',
error: ''
},
onLoad: function () {
var app = getApp()
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
},
onScan: function () {
var self = this
self.setData({ scanning: true, error: '' })
wx.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
success: function (res) {
var deviceId = self.parseDeviceId(res.result)
if (!deviceId) {
self.setData({ scanning: false, error: '无效的设备二维码' })
return
}
self.bindDevice(deviceId)
},
fail: function () {
self.setData({ scanning: false })
}
})
},
parseDeviceId: function (content) {
if (/^[0-9A-Fa-f]{16}$/.test(content)) return content
try {
var url = new URL(content)
var id = url.searchParams.get('device_id') || url.searchParams.get('id')
return id || null
} catch (e) {
return null
}
},
bindDevice: function (deviceId) {
var self = this
http.post('/api/v1/device/bind', { device_id: deviceId }).then(function (data) {
self.setData({ scanning: false })
wx.navigateTo({
url: '/pages/ble-connect/ble-connect?device_id=' + deviceId + '&bind_token=' + data.bind_token
})
}).catch(function (err) {
self.setData({
scanning: false,
error: err.message || '绑定失败'
})
})
},
onManualInput: function () {
var self = this
wx.showModal({
title: '手动输入设备号',
editable: true,
placeholderText: '请输入16位设备ID',
success: function (res) {
if (res.confirm && res.content) {
var deviceId = res.content.trim()
if (/^[0-9A-Fa-f]{16}$/.test(deviceId)) {
self.bindDevice(deviceId)
} else {
wx.showToast({ title: '设备号格式不正确', icon: 'none' })
}
}
}
})
}
})