feat: init project with miniprogram, cloud functions and admin console
这个提交包含在:
@@ -0,0 +1,106 @@
|
||||
var ble = require('../../services/ble')
|
||||
var mqtt = require('../../services/mqtt')
|
||||
var http = require('../../utils/request')
|
||||
var app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
connected: false,
|
||||
deviceName: '',
|
||||
battery: 0,
|
||||
subscription: null,
|
||||
subRemaining: 0,
|
||||
modeState: '空闲',
|
||||
bleState: 'disconnected',
|
||||
hasDevice: false,
|
||||
deviceInfo: null
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
this.checkState()
|
||||
ble.on('status', this.onBleStatus.bind(this))
|
||||
},
|
||||
|
||||
onHide: function () {
|
||||
ble.off('status')
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
ble.off('status')
|
||||
},
|
||||
|
||||
checkState: function () {
|
||||
var self = this
|
||||
var token = wx.getStorageSync('token')
|
||||
if (!token) {
|
||||
wx.reLaunch({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
|
||||
self.setData({ connected: ble.isConnected() })
|
||||
|
||||
http.get('/api/v1/device/list').then(function (data) {
|
||||
var devices = data.devices || []
|
||||
self.setData({ hasDevice: devices.length > 0 })
|
||||
if (devices.length > 0) {
|
||||
self.setData({
|
||||
deviceName: devices[0].device_name || '光子美容仪',
|
||||
deviceInfo: devices[0]
|
||||
})
|
||||
}
|
||||
}).catch(function () {})
|
||||
|
||||
http.get('/api/v1/subscription').then(function (sub) {
|
||||
self.setData({
|
||||
subscription: sub,
|
||||
subRemaining: sub.remaining_days || 0
|
||||
})
|
||||
}).catch(function () {})
|
||||
},
|
||||
|
||||
onBleStatus: function (status) {
|
||||
this.setData({
|
||||
battery: status.battery || 0,
|
||||
modeState: ble.getModeStateName(status.mode_state),
|
||||
connected: true,
|
||||
bleState: 'connected'
|
||||
})
|
||||
},
|
||||
|
||||
onConnectBle: function () {
|
||||
var self = this
|
||||
self.setData({ bleState: 'scanning' })
|
||||
|
||||
ble.startScan({
|
||||
onFound: function () {
|
||||
self.setData({ bleState: 'connecting' })
|
||||
},
|
||||
onConnected: function () {
|
||||
self.setData({ connected: true, bleState: 'connected' })
|
||||
ble.queryStatus().catch(function () {})
|
||||
},
|
||||
onError: function (err) {
|
||||
self.setData({ connected: false, bleState: 'error' })
|
||||
wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onAddDevice: function () {
|
||||
wx.navigateTo({ url: '/pages/scan/scan' })
|
||||
},
|
||||
|
||||
onStartTreatment: function () {
|
||||
if (!this.data.subscription || this.data.subscription.status === 0) {
|
||||
wx.navigateTo({ url: '/pages/subscribe-prompt/subscribe-prompt' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: '/pages/wear-check/wear-check' })
|
||||
},
|
||||
|
||||
onViewSubscription: function () {
|
||||
if (!this.data.subscription || this.data.subscription.status === 0) {
|
||||
wx.navigateTo({ url: '/pages/subscribe-plans/subscribe-plans' })
|
||||
}
|
||||
}
|
||||
})
|
||||
在新工单中引用
屏蔽一个用户