- 3 个并行 agent 各管 5 页,互不重叠命名空间 - 全 App 18 页均 i18n.bind,22 命名空间/400 键中英对齐 - 动态文案(时长/天数/价格/区域)JS 内 i18n.t 计算;区域标签复用 common.regions
80 行
2.0 KiB
JavaScript
80 行
2.0 KiB
JavaScript
var ble = require('../../services/ble')
|
|
var i18n = require('../../i18n/index')
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
battery: 0,
|
|
connected: false,
|
|
reconnecting: false
|
|
},
|
|
|
|
onShow: function () {
|
|
i18n.bind(this)
|
|
},
|
|
|
|
onBack: function () {
|
|
wx.navigateBack({
|
|
fail: function () {
|
|
wx.reLaunch({ url: '/pages/index/index' })
|
|
}
|
|
})
|
|
},
|
|
|
|
onLoad: function () {
|
|
var app = getApp()
|
|
this.setData({
|
|
statusBarHeight: app.globalData.statusBarHeight,
|
|
connected: ble.isConnected()
|
|
})
|
|
var device = app.globalData.currentDevice || {}
|
|
this.setData({ battery: device.battery || 0 })
|
|
},
|
|
|
|
onNext: function () {
|
|
if (!ble.isConnected()) {
|
|
wx.showToast({ title: i18n.t('common.deviceNotConnected'), icon: 'none' })
|
|
return
|
|
}
|
|
wx.redirectTo({
|
|
url: '/pages/treatment-setup/treatment-setup'
|
|
})
|
|
},
|
|
|
|
onRetry: function () {
|
|
var self = this
|
|
if (self.data.reconnecting) return
|
|
if (ble.isConnected()) {
|
|
self.setData({ connected: true })
|
|
return
|
|
}
|
|
self.setData({ connected: false, reconnecting: true })
|
|
ble.disconnect()
|
|
setTimeout(function () {
|
|
ble.startScan({
|
|
onFound: function () {},
|
|
onConnected: function () {
|
|
clearTimeout(self._reconnectTimer)
|
|
self.setData({ connected: true, reconnecting: false })
|
|
wx.showToast({ title: i18n.t('wearCheck.connectSuccess'), icon: 'success' })
|
|
},
|
|
onError: function (err) {
|
|
clearTimeout(self._reconnectTimer)
|
|
self.setData({ reconnecting: false })
|
|
wx.showToast({ title: err.msg || i18n.t('wearCheck.connectFailed'), icon: 'none' })
|
|
}
|
|
})
|
|
self._reconnectTimer = setTimeout(function () {
|
|
ble.stopScan()
|
|
self.setData({ reconnecting: false })
|
|
wx.showToast({ title: i18n.t('wearCheck.searchTimeout'), icon: 'none' })
|
|
}, 5000)
|
|
}, 500)
|
|
},
|
|
|
|
onUnload: function () {
|
|
clearTimeout(this._reconnectTimer)
|
|
ble.stopScan()
|
|
}
|
|
})
|