feat: init project with miniprogram, cloud functions and admin console
这个提交包含在:
@@ -0,0 +1,96 @@
|
||||
var ble = require('../../services/ble')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
regions: 0,
|
||||
wavelength: 2,
|
||||
duration: 600000,
|
||||
mode: 0,
|
||||
remainingMs: 600000,
|
||||
remainingText: '10:00',
|
||||
battery: 0,
|
||||
temperature: 0,
|
||||
progress: 0,
|
||||
paused: false,
|
||||
completed: false
|
||||
},
|
||||
|
||||
onLoad: function (options) {
|
||||
this.setData({
|
||||
regions: parseInt(options.regions) || 0x7F,
|
||||
wavelength: parseInt(options.wavelength) || 2,
|
||||
duration: parseInt(options.duration) || 600000,
|
||||
mode: parseInt(options.mode) || 0,
|
||||
remainingMs: parseInt(options.duration) || 600000
|
||||
})
|
||||
|
||||
ble.on('status', this.onStatus.bind(this))
|
||||
ble.on('treatment_complete', this.onComplete.bind(this))
|
||||
ble.on('exception', this.onException.bind(this))
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
ble.off('status')
|
||||
ble.off('treatment_complete')
|
||||
ble.off('exception')
|
||||
},
|
||||
|
||||
onStatus: function (status) {
|
||||
var remaining = status.remaining_ms || 0
|
||||
var total = this.data.duration
|
||||
var progress = total > 0 ? Math.round(((total - remaining) / total) * 100) : 0
|
||||
var mins = Math.floor(remaining / 60000)
|
||||
var secs = Math.floor((remaining % 60000) / 1000)
|
||||
var text = ('0' + mins).slice(-2) + ':' + ('0' + secs).slice(-2)
|
||||
|
||||
this.setData({
|
||||
remainingMs: remaining,
|
||||
remainingText: text,
|
||||
progress: progress,
|
||||
battery: status.battery,
|
||||
temperature: status.temperature,
|
||||
paused: status.mode_state === 0x03
|
||||
})
|
||||
},
|
||||
|
||||
onComplete: function (result) {
|
||||
this.setData({ completed: true, progress: 100 })
|
||||
var app = getApp()
|
||||
app.globalData.currentTreatment = result
|
||||
|
||||
setTimeout(function () {
|
||||
wx.redirectTo({
|
||||
url: '/pages/treatment-done/treatment-done?session_id=' + result.session_id +
|
||||
'®ions=' + result.regions +
|
||||
'&duration=' + result.total_duration_ms +
|
||||
'&avg_pd=' + result.avg_pd
|
||||
})
|
||||
}, 1000)
|
||||
},
|
||||
|
||||
onException: function (err) {
|
||||
wx.showModal({
|
||||
title: '设备异常',
|
||||
content: err.error_msg || '护理过程中出现异常',
|
||||
showCancel: false,
|
||||
complete: function () {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onStop: function () {
|
||||
var self = this
|
||||
wx.showModal({
|
||||
title: '结束护理',
|
||||
content: '确定要提前结束本次护理吗?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
ble.stopTreatment().then(function () {
|
||||
wx.navigateBack()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "护理中"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<view class="container treating-page">
|
||||
<view class="card text-center">
|
||||
<view class="progress-circle">
|
||||
<text class="progress-text">{{remainingText}}</text>
|
||||
</view>
|
||||
<view class="progress-bar-wrap mt-20">
|
||||
<progress percent="{{progress}}" stroke-width="8" activeColor="#333333" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
<view class="flex-between mb-20">
|
||||
<text>波长</text>
|
||||
<text class="text-muted">{{wavelength === 1 ? '红外 850nm' : wavelength === 2 ? '红光 630nm' : wavelength === 3 ? '紫光 405nm' : '黄光 590nm'}}</text>
|
||||
</view>
|
||||
<view class="flex-between mb-20">
|
||||
<text>模式</text>
|
||||
<text class="text-muted">{{mode === 1 ? '智能模式' : '普通模式'}}</text>
|
||||
</view>
|
||||
<view class="flex-between mb-20">
|
||||
<text>电量</text>
|
||||
<text class="text-muted">{{battery}}%</text>
|
||||
</view>
|
||||
<view class="flex-between">
|
||||
<text>温度</text>
|
||||
<text class="text-muted">{{temperature}}°C</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="stop-btn-area">
|
||||
<view class="btn-stop" bindtap="onStop">结束护理</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,37 @@
|
||||
.treating-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.progress-circle {
|
||||
width: 240rpx;
|
||||
height: 240rpx;
|
||||
border-radius: 50%;
|
||||
border: 12rpx solid #eeeeee;
|
||||
border-top-color: #333333;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 40rpx auto;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 56rpx;
|
||||
font-weight: 700;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.stop-btn-area {
|
||||
margin-top: auto;
|
||||
padding: 20rpx 0 60rpx;
|
||||
}
|
||||
|
||||
.btn-stop {
|
||||
background-color: #ff4d4f;
|
||||
color: #ffffff;
|
||||
border-radius: 12rpx;
|
||||
padding: 24rpx 40rpx;
|
||||
text-align: center;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户